Sha256: 0517630db8c60071944f0e5d13521d622d892ce53a2024d0d40fac64de71ef31

Contents?: true

Size: 1011 Bytes

Versions: 12

Compression:

Stored size: 1011 Bytes

Contents

module Faye
  
  class << self
    attr_accessor :logger
  end
  
  module Logging
    
    DEFAULT_LOG_LEVEL = :error
    
    LOG_LEVELS = {
      :error  => 3,
      :warn   => 2,
      :info   => 1,
      :debug  => 0
    }
    
    class << self
      attr_writer :log_level
      
      def log_level
        @log_level || DEFAULT_LOG_LEVEL
      end
    end
    
    attr_writer :log_level
    
    def log_level
      @log_level || Logging.log_level
    end
    
    def log(message_args, level)
      return unless Faye.logger
      return if LOG_LEVELS[log_level] > LOG_LEVELS[level]
      
      message = message_args.shift.gsub(/\?/) do
        Faye.to_json(message_args.shift)
      end
      
      timestamp = Time.now.strftime('%Y-%m-%d %H:%M:%S')
      banner = " [#{ level.to_s.upcase }] [#{ self.class.name }] "
      
      puts(timestamp + banner + message)
    end
    
    LOG_LEVELS.each do |level, value|
      define_method(level) { |*args| log(args, level) }
    end
    
  end
end

Version data entries

12 entries across 12 versions & 1 rubygems

Version Path
faye-0.6.3 lib/faye/mixins/logging.rb
faye-0.6.2 lib/faye/mixins/logging.rb
faye-0.6.1 lib/faye/mixins/logging.rb
faye-0.6.0 lib/faye/mixins/logging.rb
faye-0.5.5 lib/faye/mixins/logging.rb
faye-0.5.4 lib/faye/mixins/logging.rb
faye-0.5.3 lib/faye/mixins/logging.rb
faye-0.5.2 lib/faye/mixins/logging.rb
faye-0.5.1 lib/faye/mixins/logging.rb
faye-0.5.0 lib/faye/mixins/logging.rb
faye-0.3.4 lib/faye/logging.rb
faye-0.3.3 lib/faye/logging.rb