How can I configure Rails 3 to output colored logging to the terminal, but non-colored to log files?
There's a rails configuration option of config.colorize_logging
开发者_如何学C that you can set to turn it on/off across the board. It's not clear to me where to configure (or write a logger subclass) that can keep colorized logging to my terminal without inserting all the goofy control characters into log files
Rails.logger
is a ActiveSupport::BufferedLogger
:
#<ActiveSupport::BufferedLogger:0x0000010524ae18 @level=0, @buffer={},
@auto_flushing=1, @guard=#<Mutex:0x0000010524ab70>,
@log=#<File:/Users/ian/coding/some_poject/log/development.log>>
Though it also seems to be splitting the output to $stdout
at some point, and it's not clear to me where hooks are to configure the loggers.
You can add this to your configuration:
console do
config.colorize_logging = true
Rails.logger = Logger.new(STDOUT)
end
The console do
should only execute if you're, well, using a console.
The Rails.logger = Logger.new(STDOUT)
is something I add to make the logging use STDOUT automatically.
Hope this helps.
精彩评论