#56 The Logger (revised)
The log file will show what is going on behind the scenes of a Rails request. Learn how to log messages, add tags, override formatting, and more.
- source codeProject Files in Zip (88.2 KB)
- mp4Full Size H.264 Video (16.9 MB)
- m4vSmaller H.264 Video (8.94 MB)
- webmFull Size VP8 Video (9.22 MB)
- ogvFull Size Theora Video (24.9 MB)
Sweet! Getting rid of assets requests is a priority for me. Short and sweet; thanks.
Nice and concise - thank you Ryan!
I've built a more colorful formatter. This code might be not optimized yet, since I didn't investigate the type of
severity(nor did I for
Maybe you'll find it useful, too ;-)
would be useful to have the Gemfile in the user notes as well
nice episode, but the problem that the last second or something gets cut off from the video is still there (all videos so far)
I wanted a more compact log file, with additional information (timestamp and log level, for instance), and more control over colorization. Since none of the existing logging plugins did quite what I wanted, I wrote one. It's here:
It works with the existing
ActiveSupport::BufferedLogger, instead of replacing it, so it should still work with new features like tagged logging.
Comments and criticisms are welcome. And, of course, feel free to adapt, hack, or otherwise steal.
Nice one! Thanks Ryan.
I just wrote a blog post on how you can include "running time" in your logs: http://zogash.tumblr.com/post/21138929607/running-time-in-rails-logs
I got the same issue as Dignifiedquire on website watching, not iTunes podcast, last seconds are cuts off. Thanks Ryan for your excellent work.
I can confirm the issue with last seconds too.
Here is another bug (on Chrome at least). If you navigate away from this comments page (by entering url) and then press browser "Back" button, you'll see raw HTML.
Thanks Ryan, have wanted to tune my logs a little more. Good jump off point.
@Milovan: I've had this (raw HTML) issue too. I thought it was being caused by Glimmer Blocker, but having removed Glimmer, the problem persists (on Safari, for me).
I wrote a colorful logger class.
It uses term-ansicolor gem and intends to be used in multi-process environment where pid is colored to make it easier to distinguish processes.
You can put that file in
lib/and use colorful logger directly like:
or just pick some code and patch SimpleLogger.
Every time I think I really know what I'm doing in rails you humble me. This is so simple and useful, and I didn't know it. Thanks so much!
Is it possible to add session variables as log tags to the log file or maybe some other way to add that info against each request?
I am migrating an app over from Rails 2.0 and only thing I can't get to work is adding session[:user_id] to the log output for each request.
Earlier it was done using monkey-patching ActionController's "log_processing" method.
This doesn't seem to work if you are already redefining the logger.
I use the following in the configuration file in order to cycle log files...
Either of the following two lines will cause errors, the first on webrick startup the second on the first call to the logger
Seems the 'log_tags' method isn't defined
This is absolutely great. Thanks.
This was a great episode ! Thanks, but any tips on how to have more colors in the rails log (and console ?)
Things seem to have moved around for Rails 4. I had to change the class/module as follows:
George, thanks. I just ran into that problem.