central_logger icon indicating copy to clipboard operation
central_logger copied to clipboard

Make compatible with Heroku by adding logs to both Mongo and STDOUT

Open reedlaw opened this issue 14 years ago • 13 comments

Heroku logs require messages to be sent to STDOUT. This patch makes central_logger store logs both in mongodb and output to STDOUT.

reedlaw avatar May 03 '11 17:05 reedlaw

Thanks, this was helpful. I'm a little surprised there's not more noise about this, I would guess logging is broken for anyone using central logger and heroku without these patches.

stcorbett avatar May 18 '11 21:05 stcorbett

Took a while to get around to this, but thanks for the pull request.

I don't believe writing to STDOUT is necessary to see your logs. Wouldn't it be desirable to use the existing channels to see your app log? Let me know if I'm missing something here.

Somewhere in app logger.info "All your base are belong to us."

Will show your log statement heroku logs --source app

http://devcenter.heroku.com/articles/logging

astupka avatar Jul 21 '11 04:07 astupka

The requirement to write to STDOUT is written in the link you provided...

http://devcenter.heroku.com/articles/logging#writing_to_your_log

betelgeuse avatar Jul 21 '11 06:07 betelgeuse

I needed this back when I was on Heroku. Now I no longer need it, but a number of people have found it useful.

reedlaw avatar Jul 21 '11 12:07 reedlaw

@reedlaw Were you using rails? The mongo logger still logs to the app log, which should be viewable using

heroku logs --source app

@betelgeuse Logging to STDOUT is not required to see your app logs. The central logger extends BufferedLogger, which still writes to the production log file. That is viewable using the above command. Is there some other use case I should be supporting?

astupka avatar Jul 21 '11 14:07 astupka

Yes, I patched central_logger because Heroku support told me that in order for their advanced logging to work the app must output all logs to STDOUT.

reedlaw avatar Jul 21 '11 14:07 reedlaw

@astupka I think Heroku with the new logging system does not use the production log file any more. I haven't tested verbatim central_logger on Heroku recently but I think I subscribed here because I needed the patches to get it working.

betelgeuse avatar Jul 21 '11 15:07 betelgeuse

Yes.... still critical to do the following for Heroku as pointed out in redlaw's 808e05f patch :

mkdir vendor/plugins/rails_log_stdout touch vendor/plugins/rails_log_stdout/.gitkeep

had been working on this issue for a few hours until I tried this... worked right away.

thanks you reedlaw!

slim2000 avatar Aug 01 '11 06:08 slim2000

Central Logger stopped working for me on Heroku about a month ago. I was tearing my hair out until finding this patch from @reedlaw. @astupka, what do you need to merge this pull request? I can make a fresh commit and request if you want.

In the meantime, here's a fork with some of the recent pull requests: https://github.com/turadg/central_logger/commits/master

turadg avatar Sep 08 '11 20:09 turadg

Update: the vendor/plugins trick was working for me then stopped yesterday. I wrote Heroku support to ask how to stop the injection of their rails_log_stdout and they replied:

There is no way to avoid injection of this plugin on Cedar; however, you can bypass this by re-setting the logger after plugins are loaded, or explicitly declaring the list of plugins (config.plugins = ...) you wish to install to not include this plugin. Note that this may break any other plugins we automatically inject in the future (e.g. our rails 3.1 runtime asset compilation plugin) so you should be aware of this going forward.

Can a feature be added to Central Logger to detect when the logger is borked and reset it accordingly?

turadg avatar Sep 10 '11 15:09 turadg

Update: what I thought was central_logger no longer working (due to the error messages) was just confined to rake assets:precompile. As describe in Rails 3.1 on Heroku Cedar, the env config vars aren't available in this process. I'm getting messages like PGError: could not connect to server. I believe this is triggered by Central Logger being unable to connect:

       CentralLogger Initializer Error: Unable to access log file. Please ensure that /tmp/build_10dle9td5yslt/log/production.log exists and is chmod 0666. The log level has been raised to WARN and the output directed to STDERR until the problem is fixed.

…because I keep my Central Logger password in a config var for security (rather than in source). I don't really need central_logger activated during assets:precompile. Can CL be silenced when in a rake task?

I hope these comments are relevant to other people trying to get Heroku and Central Logger working together. Btw, @jamescallmebrent has a commit to make these @reelaw's STDOUT logging happen only if ENV['HEROKU_RACK'].

turadg avatar Sep 10 '11 19:09 turadg

Late reply. Sorry. I am in the process of adding rails 3.1 support. I will release a new version of the gem in the next few weeks.

I need to add tests to this pull request to make sure it doesn't mess with non-heroku deploys.

Alex

astupka avatar Dec 08 '11 06:12 astupka

@astupka how's this one coming? :)

turadg avatar Nov 19 '12 17:11 turadg