Using rails-enabled logging, how can I log message level logs?

In my logls logger configuration, the current time and UUID are written, for example:

config.logger = ActiveSupport::TaggedLogging.new(Logger.new("#{Rails.root}/log/#{ENV['RAILS_ENV']}.log", 'daily')) config.log_tags = [Proc.new {Time.now.strftime('%Y-%m-%d %H:%M:%S.%L')}, :uuid] 

Is there a way to log the current level of the message log?

ie, if I call logger.debug, the [DEBUG] tag is added to the message.

+8
ruby-on-rails logging ruby-on-rails-3
source share
2 answers

Railscasts shows how to override the logger to display the severity of a log message by overriding the method of calling SimpleFormatter #:

 class Logger::SimpleFormatter def call(severity, time, progname, msg) "[#{severity}] #{msg}\n" end end 

See http://railscasts.com/episodes/56-the-logger-revised for more details.

+8
source share

I added MyApp :: Application.config.log_level to the log tags and this worked for me.

 config.log_tags = [Proc.new {Time.now.strftime('%Y-%m-%d %H:%M:%S.%L')}, :uuid, Proc.new {MyApp::Application.config.log_level}] 
-4
source share

All Articles