Sha256: e65f2d123d526ec9e175e75e42782d73e85305ac0022502b009f54962edd01a5

Contents?: true

Size: 700 Bytes

Versions: 3

Compression:

Stored size: 700 Bytes

Contents

module Faye
  module Logging

    LOG_LEVELS = {
      :fatal  => 4,
      :error  => 3,
      :warn   => 2,
      :info   => 1,
      :debug  => 0
    }

    LOG_LEVELS.each do |level, value|
      define_method(level) { |*args| write_log(args, level) }
    end

  private

    def write_log(message_args, level)
      return unless Faye.logger

      message = message_args.shift.gsub(/\?/) do
        Faye.to_json(message_args.shift)
      end

      banner = "[#{ self.class.name }] "

      if Faye.logger.respond_to?(level)
        Faye.logger.__send__(level, banner + message)
      elsif Faye.logger.respond_to?(:call)
        Faye.logger.call(banner + message)
      end
    end

  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
faye-1.0.4 lib/faye/mixins/logging.rb
faye-1.0.3 lib/faye/mixins/logging.rb
faye-1.0.1 lib/faye/mixins/logging.rb