Sha256: 0fcf51ede6664ee81a948caa1e52169e6ebf495760d25489469788d0aa9322bc

Contents?: true

Size: 969 Bytes

Versions: 11

Compression:

Stored size: 969 Bytes

Contents

module Faye
  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 }] "
      
      Faye.logger.call(timestamp + banner + message)
    end
    
    LOG_LEVELS.each do |level, value|
      define_method(level) { |*args| log(args, level) }
    end
    
  end
end

Version data entries

11 entries across 11 versions & 3 rubygems

Version Path
faye-0.8.8 lib/faye/mixins/logging.rb
faye-0.8.6 lib/faye/mixins/logging.rb
faye-0.8.5 lib/faye/mixins/logging.rb
faye-0.8.4 lib/faye/mixins/logging.rb
faye-0.8.3 lib/faye/mixins/logging.rb
faye-0.8.2 lib/faye/mixins/logging.rb
_bushido-faye-0.8.2 lib/faye/mixins/logging.rb
_bushido-faye-0.8.1 lib/faye/mixins/logging.rb
bushido-faye-0.8.1 lib/faye/mixins/logging.rb
faye-0.8.1 lib/faye/mixins/logging.rb
faye-0.8.0 lib/faye/mixins/logging.rb