之前在测试支持HTTP3的nginx服务器时遇到了一些问题,希望能够通过nginx的error.log日志进行排查(error.log有debug级别的日志),但是配置后并没有生效,从官网查找了下关于debug日志的资料,翻译如下。
想要开启debug日志,需要在构建的时候将nginx配置为支持debug:
./configure --with-debug ...
接着可以将error日志的日志级别设置为debug
error_log /path/to/log debug;
预构建的Linux包提供了开箱即用的nginx-debug二进制文件(1.9.8)的调试日志支持,它可以通过如下命令运行,接着设置日志级别为debug级别就行。
service nginx stop
service nginx-debug start
Windows 下的 nginx 的二进制版本在构建的时候都已经支持 debug 日志,因此只需设置日志为 debug 级别即可。
如果你在多个地方指定了日志级别,若在最近指定日志级别时没有设置为 debug 级别,debug 日志将会被禁用 。在下述例子中,在 server 层重新指定了日志级别,将会导致该server的debug日志被禁用 :
error_log /path/to/log debug;
http {
server {
error_log /path/to/log;
...
为了避免上述情形,可以注释掉重新定义日志的那行配置,也可以在那行配置上也加上 debug的日志级别:
error_log /path/to/log debug;
http {
server {
error_log /path/to/log debug;
...
指定客户端的debug日志
debug级别的日志会打印大量信息,有可能把磁盘写满,如果既想避免这种情形又希望能看到debug日志,可以只为指定的客户端地址发来的请求开启 debug 日志:
error_log /path/to/log;
events {
debug_connection 192.168.1.1;
debug_connection 192.168.10.0/24;
}
使用循环内存缓存区域记录日志
上述debug日志可以写入到一个循环使用的内存缓冲区
error_log memory:32m debug;
即使在高负载的情形下,把debug级别的日志写入到内存缓冲区也不会对nginx性能产生显著影响。
在这种情形下,可以使用如下gdb脚本提取日志:
set $log = ngx_cycle->log
while $log->writer != ngx_log_memory_writer
set $log = $log->next
end
原文链接:
A debugging log