Skip to content
This repository has been archived by the owner on Jan 15, 2024. It is now read-only.

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

Open
wants to merge 4 commits into
base: master
Choose a base branch
from

Conversation

reedlaw
Copy link

@reedlaw reedlaw commented May 3, 2011

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

@stcorbett
Copy link

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.

@astupka
Copy link
Member

astupka commented Jul 21, 2011

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

@betelgeuse
Copy link

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

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

@reedlaw
Copy link
Author

reedlaw commented Jul 21, 2011

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

@astupka
Copy link
Member

astupka commented Jul 21, 2011

@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?

@reedlaw
Copy link
Author

reedlaw commented Jul 21, 2011

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.

@betelgeuse
Copy link

@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.

@slim2000
Copy link

slim2000 commented Aug 1, 2011

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!

@turadg
Copy link

turadg commented Sep 8, 2011

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

turadg commented Sep 10, 2011

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

turadg commented Sep 10, 2011

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'].

@astupka
Copy link
Member

astupka commented Dec 8, 2011

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

@turadg
Copy link

turadg commented Nov 19, 2012

@astupka how's this one coming? :)

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

Successfully merging this pull request may close these issues.

6 participants