OSC / ood_appkit

https://osc.github.io/Open-OnDemand/
MIT License
1 stars 2 forks source link

Log formatting and lograge enabling #8

Closed ericfranz closed 8 years ago

ericfranz commented 8 years ago

Fixes #https://github.com/AweSim-OSC/osc-ondemand/issues/85

If OodAppkit.use_ood_log_formatting is set to true in an initializer, then we do these things:

  1. set the log formatter of the Rails.logger to OodAppkit::LogFormatter.new
  2. set the progname of the Rails.logger to the app token (if it exists)
  3. enable lograge if the config option is available

By default this is enabled in production. The log formatter prepends logs with timestamp, app token, and log level. For example, here is a single request:

[2016-06-17 18:12:17 -0400 efranz/dashboard]  INFO method=GET path=/pun/dev/dashboard/ format=html controller=dashboard action=index status=200 duration=289.55 view=278.56

This addresses https://github.com/AweSim-OSC/osc-ondemand/issues/85

NOTE: I wanted to use the Rails config option log_formatter but that was not working when I set it from the engine. I tried multiple things, including ::Rails.configuration.log_formatter = OodAppkit::LogFormatter.new in the before_initialize section and config.log_formatter. I end up with something like this:

irb(main):005:0> Rails.configuration.log_formatter
=> #<OodAppkit::LogFormatter:0x00000002b4f788>
irb(main):006:0> Rails.logger.formatter
=> #<ActiveSupport::Logger::SimpleFormatter:0x00000003ee2110 @datetime_format=nil>

Using the log_formatter option in the future would be preferable to the Rails.logger.formatter.extend line in the future.

ericfranz commented 8 years ago

@nickjer please review

ericfranz commented 8 years ago

I should probably make lograge a dependency since I'm doing this: app.config.lograge.enabled = true Also, this is temporary. Probably should make this a separate ood_rails_logging gem.