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 Logger::Severity::DEBUG and friends).
Maybe you'll find it useful, too ;-)
log_formatter.rb
classLogger::SimpleFormatter# from activesupport/lib/active_support/core_ext/logger.rbdefcall(severity, time, progname, msg)
"#{severity_color severity}#{String === msg ? msg : msg.inspect}\n"end
private
defseverity_color(severity)
case severity
when"DEBUG""\033[0;34;40m[DEBUG]\033[0m"# bluewhen"INFO""\033[1;37;40m[INFO]\033[0m"# bold whitewhen"WARN""\033[1;33;40m[WARNING]\033[0m"# bold yellowwhen"ERROR""\033[1;31;40m[ERROR]\033[0m"# bold redwhen"FATAL""\033[7;31;40m[FATAL]\033[0m"# bold black, red bgelse"[#{severity}]"# noneendendend
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:
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).
Hi Ryan,
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.
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 forLogger::Severity::DEBUG
and friends).Maybe you'll find it useful, too ;-)
would be useful to have the Gemfile in the user notes as well
nice!
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:
https://github.com/bmc/grizzled-rails-logger
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.
Sweet!
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!
Hi Ryan,
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.