Skip to content

Commit

Permalink
Merge pull request #57 from saidie/fix/level_logger_severity_format
Browse files Browse the repository at this point in the history
Implement standard compatible severity formatting to LevelFluentLogger
  • Loading branch information
repeatedly authored Jan 16, 2017
2 parents d278e03 + 1750fcd commit 22ba8e0
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 4 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ require 'fluent-logger'
f = Fluent::Logger::LevelFluentLogger.new('fluent')

f.formatter = proc do |severity, datetime, progname, message|
map = { level: severity.class == Fixnum ? %w(DEBUG INFO WARN ERROR FATAL ANY)[severity] : severity }
map = { level: severity }
map[:message] = message if message
map[:progname] = progname if progname
map[:stage] = ENV['RAILS_ENV']
Expand Down
4 changes: 2 additions & 2 deletions lib/fluent/logger/level_fluent_logger.rb
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ class LevelFluentLogger < ::Logger
def initialize(tag_prefix = nil, *args)
@level = ::Logger::DEBUG
@default_formatter = proc do |severity, datetime, progname, message|
map = { level: format_severity(severity) }
map = { level: severity }
map[:message] = message if message
map[:progname] = progname if progname
map
Expand All @@ -50,7 +50,7 @@ def add(severity, message = nil, progname = nil, &block)
progname = @progname
end
end
map = format_message(severity, Time.now, progname, message)
map = format_message(format_severity(severity), Time.now, progname, message)
@fluent_logger.post(format_severity(severity).downcase, map)
true
end
Expand Down
2 changes: 1 addition & 1 deletion spec/level_fluent_logger_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@
it ('define formatter') {
level_logger.level = ::Logger::DEBUG
level_logger.formatter = proc do |severity, datetime, progname, message|
map = { level: severity.class == Fixnum ? %w(DEBUG INFO WARN ERROR FATAL ANY)[severity] : severity }
map = { level: severity }
map[:message] = message if message
map[:progname] = progname if progname
map[:stage] = "development"
Expand Down

0 comments on commit 22ba8e0

Please sign in to comment.