Better Log Formatter

A formatter allowing you to add dynamic tags to your logs with sidekiq tags support

Usage

logger = Logger.new(STDOUT)
formatter = BetterLogFormatter.new("my_app")
formatter.custom_tag(:foo) { 'Bar' }
formatter.custom_tag(:request_id) { Request.id }
logger.formatter = formatter
logger.info "Hello world!" # 2018-09-16T12:42:27.843291 my_app[1337][Bar][a776fea1-e24c-4976-b8c4-df790b1aefcb] -- INFO: Hello world!

Also, timestamp can be hidden or removed:

formatter.datetime_format = "%m/%d/%y - %H:%M:%S "
logger.info "Hello world!" # 09/16/2018T12:42:27 my_app[1337][Bar][a776fea1-e24c-4976-b8c4-df790b1aefcb] -- INFO: Hello world!
formatter.datetime_display = false
logger.info "Hello world!" # my_app[1337][Bar][a776fea1-e24c-4976-b8c4-df790b1aefcb] -- INFO: Hello world!

Contributing

Bug reports and pull requests are welcome on GitHub at https://github.com/spuyet/better_log_formatter.

License

The gem is available as open source under the terms of the MIT License.