开发者

How can I configure Rails 3 to output colored logging to the terminal, but non-colored to log files?

开发者 https://www.devze.com 2023-03-18 07:41 出处:网络
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)

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.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号