rudionrails / yell

Yell - Your Extensible Logging Library
MIT License
311 stars 21 forks source link

formatting Hash as comma separated key=value #25

Closed filmhubhq closed 10 years ago

filmhubhq commented 11 years ago

Currently Hashes are formatted in the log message like this:

2013-09-19T10:35:25-07:00 [ INFO] 8980 :  simple_string: simple, string_with_spaces: two and three

Many log analyzers prefer key=value pairs though. Here is a humble pull request to change the Hash formatting to this more parseable format. For example,

    logger = Yell.new STDOUT
    logger.info simple_string: "simple", string_with_spaces: "two and three", number_var: 234

would result in

2013-09-19T10:35:25-07:00 [ INFO] 8980 : simple_string=simple, string_with_spaces="two and three", number_var=234

If this is a too radical general change - in case you consider this at all helpful - I could imagine a new 'message' formatter variable instead.

coveralls commented 11 years ago

Coverage Status

Coverage remained the same when pulling 2d34fa4ff5b91b83baa525427a465af3cc7429b2 on kinonation:master into 1d68bbaaade7fb076c0913372af47697ab49b1e9 on rudionrails:master.

coveralls commented 11 years ago

Coverage Status

Coverage remained the same when pulling e2daaad054d2fb4bb0c10f7e0156739616b61f37 on kinonation:master into 1d68bbaaade7fb076c0913372af47697ab49b1e9 on rudionrails:master.

rudionrails commented 11 years ago

Hi,

sorry for the delay. Just got time to look at the request and I came up with something more configurable. I would rather not change the default behaviour as some people might expect hashes to being printed out the way it works right now. However, I've added a machanism to change it as you like:

format = Yell::Formatter.new  do |f|
  f.modify(Hash) { |m| m.map { |k,v| "#{k}=#{v}" }.join( ", " ) }
end

logger = Yell.new :stdout, format: format
logger.info :hash => "message"
# => 2013-09-25T17:45:46+02:00 [ INFO] 21046 : hash=message
filmhubhq commented 11 years ago

Your solution is awesome and much better than mine ;-). Thanks for your attention to this.