Skip to content

Commit

Permalink
Cleanup for #122
Browse files Browse the repository at this point in the history
  • Loading branch information
jodosha committed May 27, 2016
1 parent 76b289d commit 1163c17
Showing 1 changed file with 15 additions and 12 deletions.
27 changes: 15 additions & 12 deletions lib/hanami/logger.rb
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,10 @@ class Logger < ::Logger
#
# @see http://www.ruby-doc.org/stdlib/libdoc/logger/rdoc/Logger/Formatter.html
class Formatter < ::Logger::Formatter
# @since x.x.x
# @api private
SEPARATOR = ' '.freeze

# @since 0.5.0
# @api private
attr_writer :application_name
Expand All @@ -107,13 +111,12 @@ class Formatter < ::Logger::Formatter
#
# @see http://www.ruby-doc.org/stdlib/libdoc/logger/rdoc/Logger/Formatter.html#method-i-call
def call(severity, time, progname, msg)
hash = {
app: @application_name,
_format({
app: @application_name,
severity: severity,
time: time.utc,
}.merge!(_message_hash(msg))

_format(hash)
time: time.utc
}.merge(
_message_hash(msg)))
end

private
Expand All @@ -125,20 +128,20 @@ def _message_hash(message)
when Hash
message
when Exception
{
message: message.message,
Hash[
message: message.message,
backtrace: message.backtrace || [],
error: message.class
}
error: message.class
]
else
{ message: message }
Hash[message: message]
end
end

# @since x.x.x
# @api private
def _format(hash)
hash.map { |k,v| "#{ k }=#{ v }" }.join(' ')
hash.map { |k, v| "#{k}=#{v}" }.join(SEPARATOR)
end
end

Expand Down

0 comments on commit 1163c17

Please sign in to comment.