Reputation: 26212
There is so little information about managing log levels out there, that I decided to ask this question to get your opinion on this.
The motivation behind this question is to find out the optimal way of setting the log levels in production without restarting the app server.
First thing that I can think about is putting a method in an application_controller
which will check for certain url parameter existence i.e log_level=debug
and turn that logging level if it exists for the life of the request.
This has one drawback, which is that your user or you have to modify the url to turn on the logging. Another one might be that any underlying calls you make i.e via javascript call to you api also needs to be aware of this change and pass this log_level
url param.
Another thing I can think is putting a file to your Rails root directory called debug_log_level
or something similar, then on each request start check if that file exists. When it does, checking is the filename actually containing the valid logging level, and when it does turning that logging level on.
Drawback of this one is that you might have several instances on different boxes, so you would need to go on each box to make this change.
Another one could be to make a call to a database and same the same flow like for file.
Alternatively you could set an environment variable for log level, and use that to set the log level, but that would require the app server restart.
How are you managing this in your production environment? There has to be a smarter way to do this by now, is there?
Upvotes: 1
Views: 1483
Reputation: 399
According to the documentation, you can set the log level in an environment initializer (e.g. in config/environments/production.rb
) with the following:
config.log_level = :warn
where instead of :warn
you specify your desired log level.
The available log levels are: :debug, :info, :warn, :error, :fatal, and :unknown, corresponding to the log level numbers from 0 up to 5 respectively.
If you need to specify the log level at run time, you can use
Rails.logger.level = 0
Upvotes: 1