Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Problems on Heroku #13

Open
DannyBen opened this issue Feb 28, 2016 · 3 comments
Open

Problems on Heroku #13

DannyBen opened this issue Feb 28, 2016 · 3 comments

Comments

@DannyBen
Copy link

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.

@DannyBen DannyBen changed the title Problems with delayed job not recognizing the logs Problems with delayed job / heroku not recognizing the logs Feb 28, 2016
@DannyBen DannyBen changed the title Problems with delayed job / heroku not recognizing the logs Problems on Heroku Feb 28, 2016
@lulalala
Copy link
Owner

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
Copy link
Author

I can try

@DannyBen
Copy link
Author

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants