Markus
2013-Jun-11 03:35 UTC
Changing log level at runtime in a multithread server like unicorn
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. Any thoughts on this method or if there is a better one? -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-talk/19577d60-5f4b-4e2a-8b6d-ac139c44cd8e%40googlegroups.com?hl=en-US. For more options, visit https://groups.google.com/groups/opt_out.
Frederick Cheung
2013-Jun-11 11:04 UTC
Re: Changing log level at runtime in a multithread server like unicorn
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 -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-talk/61833756-549b-4c2b-ac3c-138af81f1de0%40googlegroups.com?hl=en-US. For more options, visit https://groups.google.com/groups/opt_out.