A ruby logger formatter to output log in LTSV format
MIT License
A ruby logger formatter to output log in LTSV format
Add this line to your application's Gemfile:
gem 'ltsv_log_formatter'
And then execute:
$ bundle
require 'logger'
require 'ltsv_log_formatter'
logger = Logger.new(STDOUT)
logger.formatter = LtsvLogFormatter.new
Configure at config/application.rb
config.logger.formatter = LtsvLogFormatter.new
Passing a hash parameter:
irb> logger.info({foo: "foo", bar: "bar"})
time:20150423T00:00:00+09:00\tlevel:INFO\tfoo:foo\tbar:bar
Passing a string parameter: message
key is used as default
irb> logger.info("foo")
time:20150423T00:00:00+09:00\tlevel:INFO\tmessage:foo
NOTE1: Notice that the line feed character \n
is converted into \\n
because LTSV format does not allow to break lines
irb> logger.info("foo\nbar")
time:20150423T00:00:00+09:00\tlevel:INFO\tmessage:foo\\nbar
NOTE2: Notice that the tab character \t
is converted into \\t
because message might have a string as "\t:"
irb> logger.info("foo\tbar:baz")
time:20150423T00:00:00+09:00\tlevel:INFO\tmessage:foo\\tbar:baz
nil
to remove. Default: timenil
to remove. Default: levelExample)
logger.formatter = LtsvLogFormatter.new(time_key: "log_time", level_key: nil)
See CHANGELOG.md for details.
git checkout -b my-new-feature
)git commit -am 'Add some feature'
)git push origin my-new-feature
)See LICENSE.txt for details.