Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
nginx
GitHub Repository: nginx/nginx.org
Path: blob/main/xml/en/docs/debugging_log.xml
1 views
1
<!--
2
Copyright (C) Igor Sysoev
3
Copyright (C) Nginx, Inc.
4
-->
5
6
<!DOCTYPE article SYSTEM "../../../dtd/article.dtd">
7
8
<article name="A debugging log"
9
link="/en/docs/debugging_log.html"
10
lang="en"
11
rev="6">
12
13
14
<section>
15
16
<para>
17
To enable a debugging log, nginx needs to be configured to support
18
debugging during the build:
19
20
<programlisting>
21
./configure --with-debug ...
22
</programlisting>
23
24
Then the <literal>debug</literal> level should be set with the
25
<link doc="ngx_core_module.xml" id="error_log"/> directive:
26
27
<programlisting>
28
error_log /path/to/log debug;
29
</programlisting>
30
31
To verify that nginx is configured to support debugging,
32
run the <command>nginx -V</command> command:
33
34
<programlisting>
35
configure arguments: --with-debug ...
36
</programlisting>
37
38
Pre-built <link doc="../linux_packages.xml">Linux</link> packages
39
provide out-of-the-box support for debugging log with
40
the <literal>nginx-debug</literal> binary (1.9.8)
41
which can be run using commands
42
43
<programlisting>
44
service nginx stop
45
service nginx-debug start
46
</programlisting>
47
48
and then set the <literal>debug</literal> level.
49
The nginx binary version for Windows is always built with the debugging log
50
support, so only setting the <literal>debug</literal> level will suffice.
51
</para>
52
53
<para>
54
Note that redefining the log without also specifying the
55
<literal>debug</literal>
56
level will disable the debugging log.
57
In the example below, redefining the log on the
58
<link doc="http/ngx_http_core_module.xml" id="server"/>
59
level disables the debugging log for this server:
60
<programlisting>
61
error_log /path/to/log debug;
62
63
http {
64
server {
65
error_log /path/to/log;
66
...
67
</programlisting>
68
To avoid this, either the line redefining the log should be
69
commented out, or the <literal>debug</literal> level specification should
70
also be added:
71
<programlisting>
72
error_log /path/to/log debug;
73
74
http {
75
server {
76
error_log /path/to/log debug;
77
...
78
</programlisting>
79
</para>
80
81
</section>
82
83
84
<section id="clients" name="Debugging log for selected clients">
85
86
<para>
87
It is also possible to enable the debugging log for
88
<link doc="ngx_core_module.xml" id="debug_connection">selected
89
client addresses</link> only:
90
91
<programlisting>
92
error_log /path/to/log;
93
94
events {
95
debug_connection 192.168.1.1;
96
debug_connection 192.168.10.0/24;
97
}
98
</programlisting>
99
</para>
100
101
</section>
102
103
104
<section id="memory" name="Logging to a cyclic memory buffer">
105
106
<para>
107
The debugging log can be written to a cyclic memory buffer:
108
<programlisting>
109
error_log memory:32m debug;
110
</programlisting>
111
Logging to the memory buffer on the <literal>debug</literal> level
112
does not have significant impact on performance even under high load.
113
In this case, the log can be extracted using
114
a <command>gdb</command> script like the following one:
115
<example>
116
set $log = ngx_cycle->log
117
118
while $log->writer != ngx_log_memory_writer
119
set $log = $log->next
120
end
121
122
set $buf = (ngx_log_memory_buf_t *) $log->wdata
123
dump binary memory debug_log.txt $buf->start $buf->end
124
</example>
125
Or using an <command>lldb</command> script as follows:
126
<example>
127
expr ngx_log_t *$log = ngx_cycle->log
128
expr while ($log->writer != ngx_log_memory_writer) { $log = $log->next; }
129
expr ngx_log_memory_buf_t *$buf = (ngx_log_memory_buf_t *) $log->wdata
130
memory read --force --outfile debug_log.txt --binary $buf->start $buf->end
131
</example>
132
</para>
133
134
</section>
135
136
</article>
137
138