Sha256: abc4314dfaff8709c3a4ac2dcd2786d4eaff46e723a32edfc60e630054b8d5d3

Contents?: true

Size: 845 Bytes

Versions: 20

Compression:

Stored size: 845 Bytes

Contents

module Bluepill
  class Logger
    LOG_METHODS = [:emerg, :alert, :crit, :err, :warning, :notice, :info, :debug]
    
    def initialize(options = {})
      @logger = options[:logger] || Syslog.open(options[:identity] || 'bluepilld', Syslog::LOG_PID, Syslog::LOG_LOCAL6)
      @prefix = options[:prefix]
      @prefixes = {}
    end
    
    LOG_METHODS.each do |method|
      eval <<-END
        def #{method}(msg, prefix = [])
          if @logger.is_a?(self.class)
            @logger.#{method}(msg, [@prefix] + prefix)
          else
            prefix = prefix.size > 0 ? "[\#{prefix.compact.join(':')}] " : ""
            @logger.#{method}("\#{prefix}\#{msg}")
          end
        end
      END
    end
    
    def prefix_with(prefix)
      @prefixes[prefix] ||= self.class.new(:logger => self, :prefix => prefix)
    end
    
  end
end

Version data entries

20 entries across 20 versions & 1 rubygems

Version Path
bluepill-0.0.21 lib/bluepill/logger.rb
bluepill-0.0.20 lib/bluepill/logger.rb
bluepill-0.0.19 lib/bluepill/logger.rb
bluepill-0.0.18 lib/bluepill/logger.rb
bluepill-0.0.17 lib/bluepill/logger.rb
bluepill-0.0.16 lib/bluepill/logger.rb
bluepill-0.0.15 lib/bluepill/logger.rb
bluepill-0.0.14 lib/bluepill/logger.rb
bluepill-0.0.13 lib/bluepill/logger.rb
bluepill-0.0.12 lib/bluepill/logger.rb
bluepill-0.0.11 lib/bluepill/logger.rb
bluepill-0.0.10 lib/bluepill/logger.rb
bluepill-0.0.9 lib/bluepill/logger.rb
bluepill-0.0.8 lib/bluepill/logger.rb
bluepill-0.0.7 lib/bluepill/logger.rb
bluepill-0.0.6 lib/bluepill/logger.rb
bluepill-0.0.5 lib/bluepill/logger.rb
bluepill-0.0.4 lib/bluepill/logger.rb
bluepill-0.0.3 lib/bluepill/logger.rb
bluepill-0.0.2 lib/bluepill/logger.rb