Re: Changing log level at runtime in a multithread server like unicorn

32 views
Skip to first unread message

Frederick Cheung

unread,
Jun 11, 2013, 7:04:15 AM6/11/13
to rubyonra...@googlegroups.com


On Tuesday, June 11, 2013 4:35:28 AM UTC+1, Markus wrote:
How can I change the log-level at runtime without restarting or creating new forks?

I was thinking of having a controller that - with proper authentication- allows a user to set the log level of a specific server, i.e. the server the controller resides on.
Because we are in a threaded environment changing the log level of one thread would not affect the others (correct me if I am wrong) so I was thinking I write the new log level to a file.
To not waste time reading the file on each log request I was thinking about setting a "global" persistent-across-requests variable that has the time of the last check and if more than 10s elapsed it reads the file again and sets the log level to the value in the file, if this is a valid one.

The usecase is that let's say 20 servers are running and an API call may return corrupted data or has a huge performance spike. So now I want to turn on a logging level that shows me i.e. the queries that were executed, and if that does not help, show even more data that is saved on "debug" level.  When there are no problems I want to restrict the logging to "error" so no unnecessary logging takes place and wastes cpu/space.


Changing it per server seems fiddly - how do you ensure that the request is handled by the server you expect it to ? I think the log level is a per process thing, but you have multiple processes so the problem remains. A file you can touch seems reasonable - Passenger etc. do something similar for monitoring changes to the tmp/restart.txt so it's probably a viable mechanism.

Fred 
Reply all
Reply to author
Forward
0 new messages