My rails logger configuration currently logs the current time and UUID, like this:
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 also log the current message's log level?
i.e., if I call logger.debug, the tag [DEBUG] is added to the message.
In a Rails app, logs are stored under the /log folder. In development mode, the development. log file is used & you see log output on the terminal you're running rails server on.
To write in the current log use the logger. (debug|info|warn|error|fatal|unknown) method from within a controller, model, or mailer: logger. debug "Person attributes hash: #{@person.
Rails uses six different log levels: debug, info, warn, error, fatal, and unknown. Each level defines how much information your application will log: Debug: diagnostic information for developers and system administrators, including database calls or inspecting object attributes.
Railscasts shows how to override the logger to output the severity of the log message by overriding the SimpleFormatter#call method:
class Logger::SimpleFormatter
def call(severity, time, progname, msg)
"[#{severity}] #{msg}\n"
end
end
See http://railscasts.com/episodes/56-the-logger-revised for the details.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With