Is it possible to dynamically change the log level?

132 views
Skip to first unread message

hl...@vendasta.com

unread,
Nov 9, 2018, 11:29:44 AM11/9/18
to openresty-en
Hi, in our nginx.conf we have `error_log <path/to/save/the/log> warn;` , just wondering whether it's possible or not to dynamically change the log level so that our backend monitoring system can automatically change it. 

Thibault Charbonnier

unread,
Nov 9, 2018, 6:19:27 PM11/9/18
to openre...@googlegroups.com
Hi,

No, it is not possible to dynamically change the log level of 'error_log'.

However, you may care to have a look at the ngx.errlog[1] module, which,
assuming some tweaks in your monitoring infrastructure, can dynamically
change its filtering value of log levels, and let you achieve your end goal.

Best,
Thibault

[1]:
https://github.com/openresty/lua-resty-core/blob/master/lib/ngx/errlog.md

Jim Robinson

unread,
Nov 13, 2018, 8:59:09 AM11/13/18
to openresty-en

One thing that could be done if you want to normally log at a higher level but sometimes drop to a lower level for debugging is to send the higher level log to a memory buffer, e.g.,

error_log /var/log/opscache/error.log warn;
error_log memory:32m debug;

the documentation is:

hl...@vendasta.com

unread,
Nov 13, 2018, 10:38:55 AM11/13/18
to openresty-en
Hi Thibault, 

Thanks for the answer! 

Yes, I checked that module and it said it's still experimental, so I didn't dare to use it in our production environment. Plus I didn't find anywhere in its documentation stating whether the filter will affect the content of the log file as well. Do you know if the log memory chunk is independent from the log file?

Regards,
House

hl...@vendasta.com

unread,
Nov 13, 2018, 11:02:25 AM11/13/18
to openresty-en
Hi Jim!

Thanks for the reply. 

That's a really interesting solution, never knew this. Will attaching nginx to gdb impact its performance?

Thanks & Best Regards,
House

Jim Robinson

unread,
Nov 20, 2018, 10:42:06 AM11/20/18
to openresty-en
Apologies for the late response.  I haven't used it extensively but I haven't noticed any impact when I grab the memory.  My impression has been that it doesn't need to perform any locking that impacts the logic paths that handle serving requests in order to grab and dump the region of memory holding the buffer.
Reply all
Reply to author
Forward
0 new messages