Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Set logging levels in Ruby on Rails

I'm using following code to configure logging in my Ruby on Rails application:

environment.rb:

Rails.logger = Logger.new(STDOUT)  class Logger   def format_message(severity, timestamp, progname, msg)     "#{timestamp.to_formatted_s(:db)} #{severity} #{msg}\n"   end end 

I'm trying to set the logging level to warn now using

config.log_level = :warn 

in my production.rb, but it doens't seem to work. Am I missing something here?

If I put Rails.logger.level = 4 in my environment.rb, it does seem to work. But I would like to configure things in my environment initializers.

like image 613
Lieven Cardoen Avatar asked Aug 29 '12 14:08

Lieven Cardoen


People also ask

How do you change the log level?

To change log levels as a root user, perform the following: To enable debug logging, run the following command: /subsystem=logging/root-logger=ROOT:change-root-log-level(level=DEBUG) To disable debug logging, run the following command: /subsystem=logging/root-logger=ROOT:change-root-log-level(level=INFO)

How do you define logging level?

What is a logging level? A logging level is a way of classifying the entries in your log file in terms of urgency. Classifying helps filter your log files during search and helps control the amount of information in your logs. Sometimes, categorizing may require you to balance storage use.


1 Answers

According to the official documentation, you should be using:

config.log_level = :warn # In any environment initializer, or Rails.logger.level = 0 # at any time 

If neither of those work for you, try:

config.log_level = Logger::WARN 

And if that doesn't work, try:

config.logger.level = Logger::WARN 

Note: The final method appears to be conflating the two official strategies, but works in some situations

like image 132
Brad Werth Avatar answered Sep 17 '22 21:09

Brad Werth