lulalala / multi_logger

Create multiple loggers in Rails
MIT License
59 stars 21 forks source link

Problems on Heroku #13

Open DannyBen opened 8 years ago

DannyBen commented 8 years ago

Hello,

I am working with multi logger for quite some time in development, and in production, and it works nicely and I cant live without it... :)

I am experiencing a weird problem in production, that seems to be related to a Heroku's way of handling logging.

When translated to English, the suspected error says: RailsStdoutLogging does not know any of the multi-logger logs

I have a log named notifier defined with

# config/initializers/multi_logger.rb
MultiLogger.add_logger 'notifier', formatter: full_formatter

And the error log says:

Feb 28 21:00:35:  [ActiveJob] Enqueued MailJob (Job ID: c9a...f97) to DelayedJob(default) with arguments: ...
Feb 28 21:00:35:  Completed 500 Internal Server Error in 90ms (ActiveRecord: 52.1ms) ...
Feb 28 21:00:35:  NoMethodError (undefined method `notifier' for #<RailsStdoutLogging::StdoutLogger:0x007f91461c3890>): 

I found this SO post that may be related. It seems (not verified) that Heroku forces stdout logging, so my guess is that all my multi logger calls will fail unless there is support or at least graceful handling of this case. Thoughts? Am I doomed and need to abandon my multi logging?...

I also opened a ticket on Heroku, and will post back here with any results.

lulalala commented 8 years ago

I am guessing this is like #8 I guess the way to do it is to detect the usage of https://github.com/heroku/rails_stdout_logging, and then add the accessor methods on it, and point it to stdout. Would you mind tackling it? Because I don't use Heroku myself :P

DannyBen commented 8 years ago

I can try

DannyBen commented 8 years ago

Update: So far I was unable to figure out an elegant way to do what I want.

My thoughts are these:

A. If making any addition or update to multi_logger, it should be a more generic patch rather than a fix for Heroku. Based on this, I was considering having a setting in multi_logger to say "use tagged mode" - and then, people can do something like:

# config/initializers/multi_logger.rb
MultiLogger.tagged_mode = Rails.env.production?   # or whatever logic suits them

B. Then, in "tagged mode", any call to Rails.logger.notifier.info "hello" would simply log to the standard, untouched logger, and only prefix it with the name - like "[:notifier] hello"

I spent some time on this, but was unable to come up with anything nice. For now, I am doing this ugly thing:

if Rails.env.production?
  Rails.logger.info "[:notifier] #{msg}"
else
  Rails.logger.notifier.info msg
end

I may try again, or stay with this workaround, or look for another approach. I am open to any nudge in the right direction so that either me or someone else can implement it.