lib/faye/mixins/logging.rb in faye-0.8.11 vs lib/faye/mixins/logging.rb in faye-1.0.0
- old
+ new
@@ -1,46 +1,35 @@
module Faye
module Logging
- DEFAULT_LOG_LEVEL = :error
-
LOG_LEVELS = {
+ :fatal => 4,
:error => 3,
:warn => 2,
:info => 1,
:debug => 0
}
- class << self
- attr_writer :log_level
+ private
- def log_level
- @log_level || DEFAULT_LOG_LEVEL
- end
+ LOG_LEVELS.each do |level, value|
+ define_method(level) { |*args| write_log(args, level) }
end
- attr_writer :log_level
-
- def log_level
- @log_level || Logging.log_level
- end
-
- def log(message_args, level)
+ def write_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 }] "
+ banner = "[#{ self.class.name }] "
- Faye.logger.call(timestamp + banner + message)
- end
-
- LOG_LEVELS.each do |level, value|
- define_method(level) { |*args| log(args, level) }
+ 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