Mercurial > hg > nginx-quic
annotate src/stream/ngx_stream_log_module.c @ 6930:97c99bb43737
Introduced worker_shutdown_timeout.
The directive configures a timeout to be used when gracefully shutting down
worker processes. When the timer expires, nginx will try to close all
the connections currently open to facilitate shutdown.
author | Maxim Dounin <mdounin@mdounin.ru> |
---|---|
date | Tue, 07 Mar 2017 18:51:16 +0300 |
parents | c36d160cd4e0 |
children | 3fb9b5eb75c0 |
rev | line source |
---|---|
441
da8c5707af39
nginx-0.1.0-2004-09-28-12:34:51 import; set copyright and remove unused files
Igor Sysoev <igor@sysoev.ru>
parents:
427
diff
changeset
|
1 |
da8c5707af39
nginx-0.1.0-2004-09-28-12:34:51 import; set copyright and remove unused files
Igor Sysoev <igor@sysoev.ru>
parents:
427
diff
changeset
|
2 /* |
444
42d11f017717
nginx-0.1.0-2004-09-29-20:00:49 import; remove years from copyright
Igor Sysoev <igor@sysoev.ru>
parents:
441
diff
changeset
|
3 * Copyright (C) Igor Sysoev |
4412 | 4 * Copyright (C) Nginx, Inc. |
441
da8c5707af39
nginx-0.1.0-2004-09-28-12:34:51 import; set copyright and remove unused files
Igor Sysoev <igor@sysoev.ru>
parents:
427
diff
changeset
|
5 */ |
da8c5707af39
nginx-0.1.0-2004-09-28-12:34:51 import; set copyright and remove unused files
Igor Sysoev <igor@sysoev.ru>
parents:
427
diff
changeset
|
6 |
26
53cb81681040
nginx-0.0.1-2002-12-15-09:25:09 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
7 |
53cb81681040
nginx-0.0.1-2002-12-15-09:25:09 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
8 #include <ngx_config.h> |
53cb81681040
nginx-0.0.1-2002-12-15-09:25:09 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
9 #include <ngx_core.h> |
6678 | 10 #include <ngx_stream.h> |
26
53cb81681040
nginx-0.0.1-2002-12-15-09:25:09 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
11 |
4988
3849bb380605
Access log: the "gzip" parameter of the "access_log" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4986
diff
changeset
|
12 #if (NGX_ZLIB) |
3849bb380605
Access log: the "gzip" parameter of the "access_log" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4986
diff
changeset
|
13 #include <zlib.h> |
3849bb380605
Access log: the "gzip" parameter of the "access_log" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4986
diff
changeset
|
14 #endif |
3849bb380605
Access log: the "gzip" parameter of the "access_log" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4986
diff
changeset
|
15 |
26
53cb81681040
nginx-0.0.1-2002-12-15-09:25:09 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
16 |
6678 | 17 typedef struct ngx_stream_log_op_s ngx_stream_log_op_t; |
880 | 18 |
6678 | 19 typedef u_char *(*ngx_stream_log_op_run_pt) (ngx_stream_session_t *s, |
20 u_char *buf, ngx_stream_log_op_t *op); | |
880 | 21 |
6678 | 22 typedef size_t (*ngx_stream_log_op_getlen_pt) (ngx_stream_session_t *s, |
880 | 23 uintptr_t data); |
24 | |
25 | |
6678 | 26 struct ngx_stream_log_op_s { |
27 size_t len; | |
28 ngx_stream_log_op_getlen_pt getlen; | |
29 ngx_stream_log_op_run_pt run; | |
30 uintptr_t data; | |
880 | 31 }; |
32 | |
573 | 33 |
34 typedef struct { | |
6678 | 35 ngx_str_t name; |
36 ngx_array_t *flushes; | |
37 ngx_array_t *ops; /* array of ngx_stream_log_op_t */ | |
38 } ngx_stream_log_fmt_t; | |
573 | 39 |
657 | 40 |
573 | 41 typedef struct { |
6678 | 42 ngx_array_t formats; /* array of ngx_stream_log_fmt_t */ |
43 } ngx_stream_log_main_conf_t; | |
573 | 44 |
657 | 45 |
573 | 46 typedef struct { |
6678 | 47 u_char *start; |
48 u_char *pos; | |
49 u_char *last; | |
4986
3efc49b156d9
Access log: the "flush" parameter of the "access_log" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4985
diff
changeset
|
50 |
6678 | 51 ngx_event_t *event; |
52 ngx_msec_t flush; | |
53 ngx_int_t gzip; | |
54 } ngx_stream_log_buf_t; | |
4985
a0599b56e748
Reopening log files code moved to a separate function.
Valentin Bartenev <vbart@nginx.com>
parents:
4984
diff
changeset
|
55 |
a0599b56e748
Reopening log files code moved to a separate function.
Valentin Bartenev <vbart@nginx.com>
parents:
4984
diff
changeset
|
56 |
a0599b56e748
Reopening log files code moved to a separate function.
Valentin Bartenev <vbart@nginx.com>
parents:
4984
diff
changeset
|
57 typedef struct { |
6678 | 58 ngx_array_t *lengths; |
59 ngx_array_t *values; | |
60 } ngx_stream_log_script_t; | |
2072 | 61 |
62 | |
63 typedef struct { | |
6678 | 64 ngx_open_file_t *file; |
65 ngx_stream_log_script_t *script; | |
66 time_t disk_full_time; | |
67 time_t error_log_time; | |
68 ngx_syslog_peer_t *syslog_peer; | |
69 ngx_stream_log_fmt_t *format; | |
70 ngx_stream_complex_value_t *filter; | |
71 } ngx_stream_log_t; | |
573 | 72 |
657 | 73 |
573 | 74 typedef struct { |
6678 | 75 ngx_array_t *logs; /* array of ngx_stream_log_t */ |
2072 | 76 |
6678 | 77 ngx_open_file_cache_t *open_file_cache; |
78 time_t open_file_cache_valid; | |
79 ngx_uint_t open_file_cache_min_uses; | |
2072 | 80 |
6678 | 81 ngx_uint_t off; /* unsigned off:1 */ |
82 } ngx_stream_log_srv_conf_t; | |
573 | 83 |
84 | |
85 typedef struct { | |
6678 | 86 ngx_str_t name; |
87 size_t len; | |
88 ngx_stream_log_op_run_pt run; | |
89 } ngx_stream_log_var_t; | |
573 | 90 |
91 | |
6678 | 92 static void ngx_stream_log_write(ngx_stream_session_t *s, ngx_stream_log_t *log, |
1071
bd4202f92581
log a failure of the writing to access_log once per minute
Igor Sysoev <igor@sysoev.ru>
parents:
905
diff
changeset
|
93 u_char *buf, size_t len); |
6678 | 94 static ssize_t ngx_stream_log_script_write(ngx_stream_session_t *s, |
95 ngx_stream_log_script_t *script, u_char **name, u_char *buf, size_t len); | |
1071
bd4202f92581
log a failure of the writing to access_log once per minute
Igor Sysoev <igor@sysoev.ru>
parents:
905
diff
changeset
|
96 |
4988
3849bb380605
Access log: the "gzip" parameter of the "access_log" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4986
diff
changeset
|
97 #if (NGX_ZLIB) |
6678 | 98 static ssize_t ngx_stream_log_gzip(ngx_fd_t fd, u_char *buf, size_t len, |
4988
3849bb380605
Access log: the "gzip" parameter of the "access_log" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4986
diff
changeset
|
99 ngx_int_t level, ngx_log_t *log); |
3849bb380605
Access log: the "gzip" parameter of the "access_log" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4986
diff
changeset
|
100 |
6678 | 101 static void *ngx_stream_log_gzip_alloc(void *opaque, u_int items, u_int size); |
102 static void ngx_stream_log_gzip_free(void *opaque, void *address); | |
4988
3849bb380605
Access log: the "gzip" parameter of the "access_log" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4986
diff
changeset
|
103 #endif |
3849bb380605
Access log: the "gzip" parameter of the "access_log" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4986
diff
changeset
|
104 |
6678 | 105 static void ngx_stream_log_flush(ngx_open_file_t *file, ngx_log_t *log); |
106 static void ngx_stream_log_flush_handler(ngx_event_t *ev); | |
4985
a0599b56e748
Reopening log files code moved to a separate function.
Valentin Bartenev <vbart@nginx.com>
parents:
4984
diff
changeset
|
107 |
6678 | 108 static ngx_int_t ngx_stream_log_variable_compile(ngx_conf_t *cf, |
6840
0cf4e82e7c48
Access log: support for json escaping.
Valentin Bartenev <vbart@nginx.com>
parents:
6693
diff
changeset
|
109 ngx_stream_log_op_t *op, ngx_str_t *value, ngx_uint_t json); |
6678 | 110 static size_t ngx_stream_log_variable_getlen(ngx_stream_session_t *s, |
501 | 111 uintptr_t data); |
6678 | 112 static u_char *ngx_stream_log_variable(ngx_stream_session_t *s, u_char *buf, |
113 ngx_stream_log_op_t *op); | |
114 static uintptr_t ngx_stream_log_escape(u_char *dst, u_char *src, size_t size); | |
6840
0cf4e82e7c48
Access log: support for json escaping.
Valentin Bartenev <vbart@nginx.com>
parents:
6693
diff
changeset
|
115 static size_t ngx_stream_log_json_variable_getlen(ngx_stream_session_t *s, |
0cf4e82e7c48
Access log: support for json escaping.
Valentin Bartenev <vbart@nginx.com>
parents:
6693
diff
changeset
|
116 uintptr_t data); |
0cf4e82e7c48
Access log: support for json escaping.
Valentin Bartenev <vbart@nginx.com>
parents:
6693
diff
changeset
|
117 static u_char *ngx_stream_log_json_variable(ngx_stream_session_t *s, |
0cf4e82e7c48
Access log: support for json escaping.
Valentin Bartenev <vbart@nginx.com>
parents:
6693
diff
changeset
|
118 u_char *buf, ngx_stream_log_op_t *op); |
501 | 119 |
120 | |
6678 | 121 static void *ngx_stream_log_create_main_conf(ngx_conf_t *cf); |
122 static void *ngx_stream_log_create_srv_conf(ngx_conf_t *cf); | |
123 static char *ngx_stream_log_merge_srv_conf(ngx_conf_t *cf, void *parent, | |
497 | 124 void *child); |
6678 | 125 static char *ngx_stream_log_set_log(ngx_conf_t *cf, ngx_command_t *cmd, |
497 | 126 void *conf); |
6678 | 127 static char *ngx_stream_log_set_format(ngx_conf_t *cf, ngx_command_t *cmd, |
497 | 128 void *conf); |
6678 | 129 static char *ngx_stream_log_compile_format(ngx_conf_t *cf, |
2261 | 130 ngx_array_t *flushes, ngx_array_t *ops, ngx_array_t *args, ngx_uint_t s); |
6678 | 131 static char *ngx_stream_log_open_file_cache(ngx_conf_t *cf, ngx_command_t *cmd, |
2072 | 132 void *conf); |
6678 | 133 static ngx_int_t ngx_stream_log_init(ngx_conf_t *cf); |
99
a059e1aa65d4
nginx-0.0.1-2003-06-02-19:24:30 import
Igor Sysoev <igor@sysoev.ru>
parents:
69
diff
changeset
|
134 |
176
c0552e5ab567
nginx-0.0.1-2003-11-09-23:03:38 import; separate building
Igor Sysoev <igor@sysoev.ru>
parents:
119
diff
changeset
|
135 |
6678 | 136 static ngx_command_t ngx_stream_log_commands[] = { |
176
c0552e5ab567
nginx-0.0.1-2003-11-09-23:03:38 import; separate building
Igor Sysoev <igor@sysoev.ru>
parents:
119
diff
changeset
|
137 |
497 | 138 { ngx_string("log_format"), |
6678 | 139 NGX_STREAM_MAIN_CONF|NGX_CONF_2MORE, |
140 ngx_stream_log_set_format, | |
141 NGX_STREAM_MAIN_CONF_OFFSET, | |
497 | 142 0, |
143 NULL }, | |
99
a059e1aa65d4
nginx-0.0.1-2003-06-02-19:24:30 import
Igor Sysoev <igor@sysoev.ru>
parents:
69
diff
changeset
|
144 |
497 | 145 { ngx_string("access_log"), |
6678 | 146 NGX_STREAM_MAIN_CONF|NGX_STREAM_SRV_CONF|NGX_CONF_1MORE, |
147 ngx_stream_log_set_log, | |
148 NGX_STREAM_SRV_CONF_OFFSET, | |
497 | 149 0, |
150 NULL }, | |
99
a059e1aa65d4
nginx-0.0.1-2003-06-02-19:24:30 import
Igor Sysoev <igor@sysoev.ru>
parents:
69
diff
changeset
|
151 |
2072 | 152 { ngx_string("open_log_file_cache"), |
6678 | 153 NGX_STREAM_MAIN_CONF|NGX_STREAM_SRV_CONF|NGX_CONF_TAKE1234, |
154 ngx_stream_log_open_file_cache, | |
155 NGX_STREAM_SRV_CONF_OFFSET, | |
2072 | 156 0, |
157 NULL }, | |
158 | |
497 | 159 ngx_null_command |
99
a059e1aa65d4
nginx-0.0.1-2003-06-02-19:24:30 import
Igor Sysoev <igor@sysoev.ru>
parents:
69
diff
changeset
|
160 }; |
a059e1aa65d4
nginx-0.0.1-2003-06-02-19:24:30 import
Igor Sysoev <igor@sysoev.ru>
parents:
69
diff
changeset
|
161 |
a059e1aa65d4
nginx-0.0.1-2003-06-02-19:24:30 import
Igor Sysoev <igor@sysoev.ru>
parents:
69
diff
changeset
|
162 |
6678 | 163 static ngx_stream_module_t ngx_stream_log_module_ctx = { |
880 | 164 NULL, /* preconfiguration */ |
6678 | 165 ngx_stream_log_init, /* postconfiguration */ |
177
4db54fdbcbe7
nginx-0.0.1-2003-11-10-20:17:31 import
Igor Sysoev <igor@sysoev.ru>
parents:
176
diff
changeset
|
166 |
6678 | 167 ngx_stream_log_create_main_conf, /* create main configuration */ |
99
a059e1aa65d4
nginx-0.0.1-2003-06-02-19:24:30 import
Igor Sysoev <igor@sysoev.ru>
parents:
69
diff
changeset
|
168 NULL, /* init main configuration */ |
a059e1aa65d4
nginx-0.0.1-2003-06-02-19:24:30 import
Igor Sysoev <igor@sysoev.ru>
parents:
69
diff
changeset
|
169 |
6678 | 170 ngx_stream_log_create_srv_conf, /* create server configuration */ |
171 ngx_stream_log_merge_srv_conf /* merge server configuration */ | |
99
a059e1aa65d4
nginx-0.0.1-2003-06-02-19:24:30 import
Igor Sysoev <igor@sysoev.ru>
parents:
69
diff
changeset
|
172 }; |
a059e1aa65d4
nginx-0.0.1-2003-06-02-19:24:30 import
Igor Sysoev <igor@sysoev.ru>
parents:
69
diff
changeset
|
173 |
a059e1aa65d4
nginx-0.0.1-2003-06-02-19:24:30 import
Igor Sysoev <igor@sysoev.ru>
parents:
69
diff
changeset
|
174 |
6678 | 175 ngx_module_t ngx_stream_log_module = { |
509 | 176 NGX_MODULE_V1, |
6678 | 177 &ngx_stream_log_module_ctx, /* module context */ |
178 ngx_stream_log_commands, /* module directives */ | |
179 NGX_STREAM_MODULE, /* module type */ | |
541 | 180 NULL, /* init master */ |
573 | 181 NULL, /* init module */ |
541 | 182 NULL, /* init process */ |
183 NULL, /* init thread */ | |
184 NULL, /* exit thread */ | |
185 NULL, /* exit process */ | |
186 NULL, /* exit master */ | |
187 NGX_MODULE_V1_PADDING | |
99
a059e1aa65d4
nginx-0.0.1-2003-06-02-19:24:30 import
Igor Sysoev <igor@sysoev.ru>
parents:
69
diff
changeset
|
188 }; |
a059e1aa65d4
nginx-0.0.1-2003-06-02-19:24:30 import
Igor Sysoev <igor@sysoev.ru>
parents:
69
diff
changeset
|
189 |
26
53cb81681040
nginx-0.0.1-2002-12-15-09:25:09 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
190 |
6678 | 191 static ngx_int_t |
192 ngx_stream_log_handler(ngx_stream_session_t *s) | |
193 { | |
194 u_char *line, *p; | |
195 size_t len, size; | |
196 ssize_t n; | |
197 ngx_str_t val; | |
198 ngx_uint_t i, l; | |
199 ngx_stream_log_t *log; | |
200 ngx_stream_log_op_t *op; | |
201 ngx_stream_log_buf_t *buffer; | |
202 ngx_stream_log_srv_conf_t *lscf; | |
26
53cb81681040
nginx-0.0.1-2002-12-15-09:25:09 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
203 |
6678 | 204 ngx_log_debug0(NGX_LOG_DEBUG_STREAM, s->connection->log, 0, |
205 "stream log handler"); | |
176
c0552e5ab567
nginx-0.0.1-2003-11-09-23:03:38 import; separate building
Igor Sysoev <igor@sysoev.ru>
parents:
119
diff
changeset
|
206 |
6678 | 207 lscf = ngx_stream_get_module_srv_conf(s, ngx_stream_log_module); |
26
53cb81681040
nginx-0.0.1-2002-12-15-09:25:09 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
208 |
6678 | 209 if (lscf->off || lscf->logs == NULL) { |
427
0d08eabe5c7b
nginx-0.0.10-2004-09-15-20:00:43 import
Igor Sysoev <igor@sysoev.ru>
parents:
415
diff
changeset
|
210 return NGX_OK; |
0d08eabe5c7b
nginx-0.0.10-2004-09-15-20:00:43 import
Igor Sysoev <igor@sysoev.ru>
parents:
415
diff
changeset
|
211 } |
0d08eabe5c7b
nginx-0.0.10-2004-09-15-20:00:43 import
Igor Sysoev <igor@sysoev.ru>
parents:
415
diff
changeset
|
212 |
6678 | 213 log = lscf->logs->elts; |
214 for (l = 0; l < lscf->logs->nelts; l++) { | |
176
c0552e5ab567
nginx-0.0.1-2003-11-09-23:03:38 import; separate building
Igor Sysoev <igor@sysoev.ru>
parents:
119
diff
changeset
|
215 |
5653
cb308813b453
Access log: the "if" parameter of the "access_log" directive.
Sergey Kandaurov <pluknet@nginx.com>
parents:
5361
diff
changeset
|
216 if (log[l].filter) { |
6678 | 217 if (ngx_stream_complex_value(s, log[l].filter, &val) != NGX_OK) { |
5653
cb308813b453
Access log: the "if" parameter of the "access_log" directive.
Sergey Kandaurov <pluknet@nginx.com>
parents:
5361
diff
changeset
|
218 return NGX_ERROR; |
cb308813b453
Access log: the "if" parameter of the "access_log" directive.
Sergey Kandaurov <pluknet@nginx.com>
parents:
5361
diff
changeset
|
219 } |
cb308813b453
Access log: the "if" parameter of the "access_log" directive.
Sergey Kandaurov <pluknet@nginx.com>
parents:
5361
diff
changeset
|
220 |
cb308813b453
Access log: the "if" parameter of the "access_log" directive.
Sergey Kandaurov <pluknet@nginx.com>
parents:
5361
diff
changeset
|
221 if (val.len == 0 || (val.len == 1 && val.data[0] == '0')) { |
cb308813b453
Access log: the "if" parameter of the "access_log" directive.
Sergey Kandaurov <pluknet@nginx.com>
parents:
5361
diff
changeset
|
222 continue; |
cb308813b453
Access log: the "if" parameter of the "access_log" directive.
Sergey Kandaurov <pluknet@nginx.com>
parents:
5361
diff
changeset
|
223 } |
cb308813b453
Access log: the "if" parameter of the "access_log" directive.
Sergey Kandaurov <pluknet@nginx.com>
parents:
5361
diff
changeset
|
224 } |
cb308813b453
Access log: the "if" parameter of the "access_log" directive.
Sergey Kandaurov <pluknet@nginx.com>
parents:
5361
diff
changeset
|
225 |
633 | 226 if (ngx_time() == log[l].disk_full_time) { |
227 | |
228 /* | |
1071
bd4202f92581
log a failure of the writing to access_log once per minute
Igor Sysoev <igor@sysoev.ru>
parents:
905
diff
changeset
|
229 * on FreeBSD writing to a full filesystem with enabled softupdates |
633 | 230 * may block process for much longer time than writing to non-full |
1071
bd4202f92581
log a failure of the writing to access_log once per minute
Igor Sysoev <igor@sysoev.ru>
parents:
905
diff
changeset
|
231 * filesystem, so we skip writing to a log for one second |
633 | 232 */ |
233 | |
234 continue; | |
235 } | |
236 | |
6678 | 237 ngx_stream_script_flush_no_cacheable_variables(s, |
238 log[l].format->flushes); | |
2261 | 239 |
176
c0552e5ab567
nginx-0.0.1-2003-11-09-23:03:38 import; separate building
Igor Sysoev <igor@sysoev.ru>
parents:
119
diff
changeset
|
240 len = 0; |
2261 | 241 op = log[l].format->ops->elts; |
242 for (i = 0; i < log[l].format->ops->nelts; i++) { | |
176
c0552e5ab567
nginx-0.0.1-2003-11-09-23:03:38 import; separate building
Igor Sysoev <igor@sysoev.ru>
parents:
119
diff
changeset
|
243 if (op[i].len == 0) { |
6678 | 244 len += op[i].getlen(s, op[i].data); |
176
c0552e5ab567
nginx-0.0.1-2003-11-09-23:03:38 import; separate building
Igor Sysoev <igor@sysoev.ru>
parents:
119
diff
changeset
|
245 |
c0552e5ab567
nginx-0.0.1-2003-11-09-23:03:38 import; separate building
Igor Sysoev <igor@sysoev.ru>
parents:
119
diff
changeset
|
246 } else { |
c0552e5ab567
nginx-0.0.1-2003-11-09-23:03:38 import; separate building
Igor Sysoev <igor@sysoev.ru>
parents:
119
diff
changeset
|
247 len += op[i].len; |
c0552e5ab567
nginx-0.0.1-2003-11-09-23:03:38 import; separate building
Igor Sysoev <igor@sysoev.ru>
parents:
119
diff
changeset
|
248 } |
c0552e5ab567
nginx-0.0.1-2003-11-09-23:03:38 import; separate building
Igor Sysoev <igor@sysoev.ru>
parents:
119
diff
changeset
|
249 } |
c0552e5ab567
nginx-0.0.1-2003-11-09-23:03:38 import; separate building
Igor Sysoev <igor@sysoev.ru>
parents:
119
diff
changeset
|
250 |
5702
777202558122
Added syslog support for error_log and access_log directives.
Vladimir Homutov <vl@nginx.com>
parents:
5653
diff
changeset
|
251 if (log[l].syslog_peer) { |
777202558122
Added syslog support for error_log and access_log directives.
Vladimir Homutov <vl@nginx.com>
parents:
5653
diff
changeset
|
252 |
777202558122
Added syslog support for error_log and access_log directives.
Vladimir Homutov <vl@nginx.com>
parents:
5653
diff
changeset
|
253 /* length of syslog's PRI and HEADER message parts */ |
777202558122
Added syslog support for error_log and access_log directives.
Vladimir Homutov <vl@nginx.com>
parents:
5653
diff
changeset
|
254 len += sizeof("<255>Jan 01 00:00:00 ") - 1 |
777202558122
Added syslog support for error_log and access_log directives.
Vladimir Homutov <vl@nginx.com>
parents:
5653
diff
changeset
|
255 + ngx_cycle->hostname.len + 1 |
777202558122
Added syslog support for error_log and access_log directives.
Vladimir Homutov <vl@nginx.com>
parents:
5653
diff
changeset
|
256 + log[l].syslog_peer->tag.len + 2; |
777202558122
Added syslog support for error_log and access_log directives.
Vladimir Homutov <vl@nginx.com>
parents:
5653
diff
changeset
|
257 |
777202558122
Added syslog support for error_log and access_log directives.
Vladimir Homutov <vl@nginx.com>
parents:
5653
diff
changeset
|
258 goto alloc_line; |
777202558122
Added syslog support for error_log and access_log directives.
Vladimir Homutov <vl@nginx.com>
parents:
5653
diff
changeset
|
259 } |
777202558122
Added syslog support for error_log and access_log directives.
Vladimir Homutov <vl@nginx.com>
parents:
5653
diff
changeset
|
260 |
571 | 261 len += NGX_LINEFEED_SIZE; |
262 | |
4985
a0599b56e748
Reopening log files code moved to a separate function.
Valentin Bartenev <vbart@nginx.com>
parents:
4984
diff
changeset
|
263 buffer = log[l].file ? log[l].file->data : NULL; |
571 | 264 |
4985
a0599b56e748
Reopening log files code moved to a separate function.
Valentin Bartenev <vbart@nginx.com>
parents:
4984
diff
changeset
|
265 if (buffer) { |
571 | 266 |
4985
a0599b56e748
Reopening log files code moved to a separate function.
Valentin Bartenev <vbart@nginx.com>
parents:
4984
diff
changeset
|
267 if (len > (size_t) (buffer->last - buffer->pos)) { |
571 | 268 |
6678 | 269 ngx_stream_log_write(s, &log[l], buffer->start, |
270 buffer->pos - buffer->start); | |
571 | 271 |
4985
a0599b56e748
Reopening log files code moved to a separate function.
Valentin Bartenev <vbart@nginx.com>
parents:
4984
diff
changeset
|
272 buffer->pos = buffer->start; |
571 | 273 } |
274 | |
4985
a0599b56e748
Reopening log files code moved to a separate function.
Valentin Bartenev <vbart@nginx.com>
parents:
4984
diff
changeset
|
275 if (len <= (size_t) (buffer->last - buffer->pos)) { |
571 | 276 |
4985
a0599b56e748
Reopening log files code moved to a separate function.
Valentin Bartenev <vbart@nginx.com>
parents:
4984
diff
changeset
|
277 p = buffer->pos; |
571 | 278 |
4986
3efc49b156d9
Access log: the "flush" parameter of the "access_log" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4985
diff
changeset
|
279 if (buffer->event && p == buffer->start) { |
3efc49b156d9
Access log: the "flush" parameter of the "access_log" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4985
diff
changeset
|
280 ngx_add_timer(buffer->event, buffer->flush); |
3efc49b156d9
Access log: the "flush" parameter of the "access_log" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4985
diff
changeset
|
281 } |
3efc49b156d9
Access log: the "flush" parameter of the "access_log" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4985
diff
changeset
|
282 |
2261 | 283 for (i = 0; i < log[l].format->ops->nelts; i++) { |
6678 | 284 p = op[i].run(s, p, &op[i]); |
571 | 285 } |
286 | |
287 ngx_linefeed(p); | |
288 | |
4985
a0599b56e748
Reopening log files code moved to a separate function.
Valentin Bartenev <vbart@nginx.com>
parents:
4984
diff
changeset
|
289 buffer->pos = p; |
571 | 290 |
291 continue; | |
292 } | |
4986
3efc49b156d9
Access log: the "flush" parameter of the "access_log" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4985
diff
changeset
|
293 |
3efc49b156d9
Access log: the "flush" parameter of the "access_log" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4985
diff
changeset
|
294 if (buffer->event && buffer->event->timer_set) { |
3efc49b156d9
Access log: the "flush" parameter of the "access_log" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4985
diff
changeset
|
295 ngx_del_timer(buffer->event); |
3efc49b156d9
Access log: the "flush" parameter of the "access_log" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4985
diff
changeset
|
296 } |
571 | 297 } |
26
53cb81681040
nginx-0.0.1-2002-12-15-09:25:09 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
298 |
5702
777202558122
Added syslog support for error_log and access_log directives.
Vladimir Homutov <vl@nginx.com>
parents:
5653
diff
changeset
|
299 alloc_line: |
777202558122
Added syslog support for error_log and access_log directives.
Vladimir Homutov <vl@nginx.com>
parents:
5653
diff
changeset
|
300 |
6678 | 301 line = ngx_pnalloc(s->connection->pool, len); |
501 | 302 if (line == NULL) { |
473 | 303 return NGX_ERROR; |
304 } | |
305 | |
176
c0552e5ab567
nginx-0.0.1-2003-11-09-23:03:38 import; separate building
Igor Sysoev <igor@sysoev.ru>
parents:
119
diff
changeset
|
306 p = line; |
26
53cb81681040
nginx-0.0.1-2002-12-15-09:25:09 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
307 |
5702
777202558122
Added syslog support for error_log and access_log directives.
Vladimir Homutov <vl@nginx.com>
parents:
5653
diff
changeset
|
308 if (log[l].syslog_peer) { |
777202558122
Added syslog support for error_log and access_log directives.
Vladimir Homutov <vl@nginx.com>
parents:
5653
diff
changeset
|
309 p = ngx_syslog_add_header(log[l].syslog_peer, line); |
777202558122
Added syslog support for error_log and access_log directives.
Vladimir Homutov <vl@nginx.com>
parents:
5653
diff
changeset
|
310 } |
777202558122
Added syslog support for error_log and access_log directives.
Vladimir Homutov <vl@nginx.com>
parents:
5653
diff
changeset
|
311 |
2261 | 312 for (i = 0; i < log[l].format->ops->nelts; i++) { |
6678 | 313 p = op[i].run(s, p, &op[i]); |
176
c0552e5ab567
nginx-0.0.1-2003-11-09-23:03:38 import; separate building
Igor Sysoev <igor@sysoev.ru>
parents:
119
diff
changeset
|
314 } |
99
a059e1aa65d4
nginx-0.0.1-2003-06-02-19:24:30 import
Igor Sysoev <igor@sysoev.ru>
parents:
69
diff
changeset
|
315 |
5702
777202558122
Added syslog support for error_log and access_log directives.
Vladimir Homutov <vl@nginx.com>
parents:
5653
diff
changeset
|
316 if (log[l].syslog_peer) { |
777202558122
Added syslog support for error_log and access_log directives.
Vladimir Homutov <vl@nginx.com>
parents:
5653
diff
changeset
|
317 |
777202558122
Added syslog support for error_log and access_log directives.
Vladimir Homutov <vl@nginx.com>
parents:
5653
diff
changeset
|
318 size = p - line; |
777202558122
Added syslog support for error_log and access_log directives.
Vladimir Homutov <vl@nginx.com>
parents:
5653
diff
changeset
|
319 |
777202558122
Added syslog support for error_log and access_log directives.
Vladimir Homutov <vl@nginx.com>
parents:
5653
diff
changeset
|
320 n = ngx_syslog_send(log[l].syslog_peer, line, size); |
777202558122
Added syslog support for error_log and access_log directives.
Vladimir Homutov <vl@nginx.com>
parents:
5653
diff
changeset
|
321 |
777202558122
Added syslog support for error_log and access_log directives.
Vladimir Homutov <vl@nginx.com>
parents:
5653
diff
changeset
|
322 if (n < 0) { |
6678 | 323 ngx_log_error(NGX_LOG_WARN, s->connection->log, 0, |
5702
777202558122
Added syslog support for error_log and access_log directives.
Vladimir Homutov <vl@nginx.com>
parents:
5653
diff
changeset
|
324 "send() to syslog failed"); |
777202558122
Added syslog support for error_log and access_log directives.
Vladimir Homutov <vl@nginx.com>
parents:
5653
diff
changeset
|
325 |
777202558122
Added syslog support for error_log and access_log directives.
Vladimir Homutov <vl@nginx.com>
parents:
5653
diff
changeset
|
326 } else if ((size_t) n != size) { |
6678 | 327 ngx_log_error(NGX_LOG_WARN, s->connection->log, 0, |
5702
777202558122
Added syslog support for error_log and access_log directives.
Vladimir Homutov <vl@nginx.com>
parents:
5653
diff
changeset
|
328 "send() to syslog has written only %z of %uz", |
777202558122
Added syslog support for error_log and access_log directives.
Vladimir Homutov <vl@nginx.com>
parents:
5653
diff
changeset
|
329 n, size); |
777202558122
Added syslog support for error_log and access_log directives.
Vladimir Homutov <vl@nginx.com>
parents:
5653
diff
changeset
|
330 } |
777202558122
Added syslog support for error_log and access_log directives.
Vladimir Homutov <vl@nginx.com>
parents:
5653
diff
changeset
|
331 |
777202558122
Added syslog support for error_log and access_log directives.
Vladimir Homutov <vl@nginx.com>
parents:
5653
diff
changeset
|
332 continue; |
777202558122
Added syslog support for error_log and access_log directives.
Vladimir Homutov <vl@nginx.com>
parents:
5653
diff
changeset
|
333 } |
777202558122
Added syslog support for error_log and access_log directives.
Vladimir Homutov <vl@nginx.com>
parents:
5653
diff
changeset
|
334 |
571 | 335 ngx_linefeed(p); |
336 | |
6678 | 337 ngx_stream_log_write(s, &log[l], line, p - line); |
176
c0552e5ab567
nginx-0.0.1-2003-11-09-23:03:38 import; separate building
Igor Sysoev <igor@sysoev.ru>
parents:
119
diff
changeset
|
338 } |
26
53cb81681040
nginx-0.0.1-2002-12-15-09:25:09 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
339 |
53cb81681040
nginx-0.0.1-2002-12-15-09:25:09 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
340 return NGX_OK; |
53cb81681040
nginx-0.0.1-2002-12-15-09:25:09 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
341 } |
99
a059e1aa65d4
nginx-0.0.1-2003-06-02-19:24:30 import
Igor Sysoev <igor@sysoev.ru>
parents:
69
diff
changeset
|
342 |
a059e1aa65d4
nginx-0.0.1-2003-06-02-19:24:30 import
Igor Sysoev <igor@sysoev.ru>
parents:
69
diff
changeset
|
343 |
1071
bd4202f92581
log a failure of the writing to access_log once per minute
Igor Sysoev <igor@sysoev.ru>
parents:
905
diff
changeset
|
344 static void |
6678 | 345 ngx_stream_log_write(ngx_stream_session_t *s, ngx_stream_log_t *log, |
346 u_char *buf, size_t len) | |
1071
bd4202f92581
log a failure of the writing to access_log once per minute
Igor Sysoev <igor@sysoev.ru>
parents:
905
diff
changeset
|
347 { |
6678 | 348 u_char *name; |
349 time_t now; | |
350 ssize_t n; | |
351 ngx_err_t err; | |
4988
3849bb380605
Access log: the "gzip" parameter of the "access_log" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4986
diff
changeset
|
352 #if (NGX_ZLIB) |
6678 | 353 ngx_stream_log_buf_t *buffer; |
4988
3849bb380605
Access log: the "gzip" parameter of the "access_log" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4986
diff
changeset
|
354 #endif |
1071
bd4202f92581
log a failure of the writing to access_log once per minute
Igor Sysoev <igor@sysoev.ru>
parents:
905
diff
changeset
|
355 |
2072 | 356 if (log->script == NULL) { |
357 name = log->file->name.data; | |
4988
3849bb380605
Access log: the "gzip" parameter of the "access_log" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4986
diff
changeset
|
358 |
3849bb380605
Access log: the "gzip" parameter of the "access_log" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4986
diff
changeset
|
359 #if (NGX_ZLIB) |
3849bb380605
Access log: the "gzip" parameter of the "access_log" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4986
diff
changeset
|
360 buffer = log->file->data; |
3849bb380605
Access log: the "gzip" parameter of the "access_log" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4986
diff
changeset
|
361 |
3849bb380605
Access log: the "gzip" parameter of the "access_log" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4986
diff
changeset
|
362 if (buffer && buffer->gzip) { |
6678 | 363 n = ngx_stream_log_gzip(log->file->fd, buf, len, buffer->gzip, |
364 s->connection->log); | |
4988
3849bb380605
Access log: the "gzip" parameter of the "access_log" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4986
diff
changeset
|
365 } else { |
3849bb380605
Access log: the "gzip" parameter of the "access_log" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4986
diff
changeset
|
366 n = ngx_write_fd(log->file->fd, buf, len); |
3849bb380605
Access log: the "gzip" parameter of the "access_log" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4986
diff
changeset
|
367 } |
3849bb380605
Access log: the "gzip" parameter of the "access_log" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4986
diff
changeset
|
368 #else |
2072 | 369 n = ngx_write_fd(log->file->fd, buf, len); |
4988
3849bb380605
Access log: the "gzip" parameter of the "access_log" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4986
diff
changeset
|
370 #endif |
2072 | 371 |
372 } else { | |
373 name = NULL; | |
6678 | 374 n = ngx_stream_log_script_write(s, log->script, &name, buf, len); |
2072 | 375 } |
1071
bd4202f92581
log a failure of the writing to access_log once per minute
Igor Sysoev <igor@sysoev.ru>
parents:
905
diff
changeset
|
376 |
bd4202f92581
log a failure of the writing to access_log once per minute
Igor Sysoev <igor@sysoev.ru>
parents:
905
diff
changeset
|
377 if (n == (ssize_t) len) { |
bd4202f92581
log a failure of the writing to access_log once per minute
Igor Sysoev <igor@sysoev.ru>
parents:
905
diff
changeset
|
378 return; |
bd4202f92581
log a failure of the writing to access_log once per minute
Igor Sysoev <igor@sysoev.ru>
parents:
905
diff
changeset
|
379 } |
bd4202f92581
log a failure of the writing to access_log once per minute
Igor Sysoev <igor@sysoev.ru>
parents:
905
diff
changeset
|
380 |
bd4202f92581
log a failure of the writing to access_log once per minute
Igor Sysoev <igor@sysoev.ru>
parents:
905
diff
changeset
|
381 now = ngx_time(); |
bd4202f92581
log a failure of the writing to access_log once per minute
Igor Sysoev <igor@sysoev.ru>
parents:
905
diff
changeset
|
382 |
bd4202f92581
log a failure of the writing to access_log once per minute
Igor Sysoev <igor@sysoev.ru>
parents:
905
diff
changeset
|
383 if (n == -1) { |
bd4202f92581
log a failure of the writing to access_log once per minute
Igor Sysoev <igor@sysoev.ru>
parents:
905
diff
changeset
|
384 err = ngx_errno; |
bd4202f92581
log a failure of the writing to access_log once per minute
Igor Sysoev <igor@sysoev.ru>
parents:
905
diff
changeset
|
385 |
bd4202f92581
log a failure of the writing to access_log once per minute
Igor Sysoev <igor@sysoev.ru>
parents:
905
diff
changeset
|
386 if (err == NGX_ENOSPC) { |
bd4202f92581
log a failure of the writing to access_log once per minute
Igor Sysoev <igor@sysoev.ru>
parents:
905
diff
changeset
|
387 log->disk_full_time = now; |
bd4202f92581
log a failure of the writing to access_log once per minute
Igor Sysoev <igor@sysoev.ru>
parents:
905
diff
changeset
|
388 } |
bd4202f92581
log a failure of the writing to access_log once per minute
Igor Sysoev <igor@sysoev.ru>
parents:
905
diff
changeset
|
389 |
1161
6002e0253221
use 60 seconds interval but not 61 seconds
Igor Sysoev <igor@sysoev.ru>
parents:
1074
diff
changeset
|
390 if (now - log->error_log_time > 59) { |
6678 | 391 ngx_log_error(NGX_LOG_ALERT, s->connection->log, err, |
2072 | 392 ngx_write_fd_n " to \"%s\" failed", name); |
1071
bd4202f92581
log a failure of the writing to access_log once per minute
Igor Sysoev <igor@sysoev.ru>
parents:
905
diff
changeset
|
393 |
bd4202f92581
log a failure of the writing to access_log once per minute
Igor Sysoev <igor@sysoev.ru>
parents:
905
diff
changeset
|
394 log->error_log_time = now; |
bd4202f92581
log a failure of the writing to access_log once per minute
Igor Sysoev <igor@sysoev.ru>
parents:
905
diff
changeset
|
395 } |
bd4202f92581
log a failure of the writing to access_log once per minute
Igor Sysoev <igor@sysoev.ru>
parents:
905
diff
changeset
|
396 |
bd4202f92581
log a failure of the writing to access_log once per minute
Igor Sysoev <igor@sysoev.ru>
parents:
905
diff
changeset
|
397 return; |
bd4202f92581
log a failure of the writing to access_log once per minute
Igor Sysoev <igor@sysoev.ru>
parents:
905
diff
changeset
|
398 } |
bd4202f92581
log a failure of the writing to access_log once per minute
Igor Sysoev <igor@sysoev.ru>
parents:
905
diff
changeset
|
399 |
1161
6002e0253221
use 60 seconds interval but not 61 seconds
Igor Sysoev <igor@sysoev.ru>
parents:
1074
diff
changeset
|
400 if (now - log->error_log_time > 59) { |
6678 | 401 ngx_log_error(NGX_LOG_ALERT, s->connection->log, 0, |
2072 | 402 ngx_write_fd_n " to \"%s\" was incomplete: %z of %uz", |
403 name, n, len); | |
1071
bd4202f92581
log a failure of the writing to access_log once per minute
Igor Sysoev <igor@sysoev.ru>
parents:
905
diff
changeset
|
404 |
bd4202f92581
log a failure of the writing to access_log once per minute
Igor Sysoev <igor@sysoev.ru>
parents:
905
diff
changeset
|
405 log->error_log_time = now; |
bd4202f92581
log a failure of the writing to access_log once per minute
Igor Sysoev <igor@sysoev.ru>
parents:
905
diff
changeset
|
406 } |
bd4202f92581
log a failure of the writing to access_log once per minute
Igor Sysoev <igor@sysoev.ru>
parents:
905
diff
changeset
|
407 } |
bd4202f92581
log a failure of the writing to access_log once per minute
Igor Sysoev <igor@sysoev.ru>
parents:
905
diff
changeset
|
408 |
bd4202f92581
log a failure of the writing to access_log once per minute
Igor Sysoev <igor@sysoev.ru>
parents:
905
diff
changeset
|
409 |
2072 | 410 static ssize_t |
6678 | 411 ngx_stream_log_script_write(ngx_stream_session_t *s, |
412 ngx_stream_log_script_t *script, u_char **name, u_char *buf, size_t len) | |
2072 | 413 { |
6678 | 414 ssize_t n; |
415 ngx_str_t log; | |
416 ngx_open_file_info_t of; | |
417 ngx_stream_log_srv_conf_t *lscf; | |
4494
13e09cf11d4e
Disable symlinks: initialization of the "disable_symlinks" field in
Valentin Bartenev <vbart@nginx.com>
parents:
4478
diff
changeset
|
418 |
6678 | 419 if (ngx_stream_script_run(s, &log, script->lengths->elts, 1, |
420 script->values->elts) | |
2072 | 421 == NULL) |
422 { | |
4499
778ef9c3fd2d
Fixed spelling in single-line comments.
Ruslan Ermilov <ru@nginx.com>
parents:
4494
diff
changeset
|
423 /* simulate successful logging */ |
2072 | 424 return len; |
425 } | |
426 | |
427 log.data[log.len - 1] = '\0'; | |
428 *name = log.data; | |
429 | |
6678 | 430 ngx_log_debug1(NGX_LOG_DEBUG_STREAM, s->connection->log, 0, |
431 "stream log \"%s\"", log.data); | |
2072 | 432 |
6678 | 433 lscf = ngx_stream_get_module_srv_conf(s, ngx_stream_log_module); |
2072 | 434 |
435 ngx_memzero(&of, sizeof(ngx_open_file_info_t)); | |
436 | |
437 of.log = 1; | |
6678 | 438 of.valid = lscf->open_file_cache_valid; |
439 of.min_uses = lscf->open_file_cache_min_uses; | |
2277 | 440 of.directio = NGX_OPEN_FILE_DIRECTIO_OFF; |
4494
13e09cf11d4e
Disable symlinks: initialization of the "disable_symlinks" field in
Valentin Bartenev <vbart@nginx.com>
parents:
4478
diff
changeset
|
441 |
6678 | 442 if (ngx_open_cached_file(lscf->open_file_cache, &log, &of, |
443 s->connection->pool) | |
2072 | 444 != NGX_OK) |
445 { | |
6678 | 446 ngx_log_error(NGX_LOG_CRIT, s->connection->log, ngx_errno, |
2756
09cab3f8d92e
*) of.test_only to not open file if only stat() is enough
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
447 "%s \"%s\" failed", of.failed, log.data); |
4499
778ef9c3fd2d
Fixed spelling in single-line comments.
Ruslan Ermilov <ru@nginx.com>
parents:
4494
diff
changeset
|
448 /* simulate successful logging */ |
2077 | 449 return len; |
2072 | 450 } |
451 | |
6678 | 452 ngx_log_debug1(NGX_LOG_DEBUG_STREAM, s->connection->log, 0, |
453 "stream log #%d", of.fd); | |
2072 | 454 |
455 n = ngx_write_fd(of.fd, buf, len); | |
456 | |
457 return n; | |
458 } | |
459 | |
460 | |
4988
3849bb380605
Access log: the "gzip" parameter of the "access_log" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4986
diff
changeset
|
461 #if (NGX_ZLIB) |
3849bb380605
Access log: the "gzip" parameter of the "access_log" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4986
diff
changeset
|
462 |
3849bb380605
Access log: the "gzip" parameter of the "access_log" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4986
diff
changeset
|
463 static ssize_t |
6678 | 464 ngx_stream_log_gzip(ngx_fd_t fd, u_char *buf, size_t len, ngx_int_t level, |
4988
3849bb380605
Access log: the "gzip" parameter of the "access_log" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4986
diff
changeset
|
465 ngx_log_t *log) |
3849bb380605
Access log: the "gzip" parameter of the "access_log" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4986
diff
changeset
|
466 { |
3849bb380605
Access log: the "gzip" parameter of the "access_log" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4986
diff
changeset
|
467 int rc, wbits, memlevel; |
3849bb380605
Access log: the "gzip" parameter of the "access_log" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4986
diff
changeset
|
468 u_char *out; |
3849bb380605
Access log: the "gzip" parameter of the "access_log" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4986
diff
changeset
|
469 size_t size; |
3849bb380605
Access log: the "gzip" parameter of the "access_log" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4986
diff
changeset
|
470 ssize_t n; |
3849bb380605
Access log: the "gzip" parameter of the "access_log" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4986
diff
changeset
|
471 z_stream zstream; |
3849bb380605
Access log: the "gzip" parameter of the "access_log" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4986
diff
changeset
|
472 ngx_err_t err; |
3849bb380605
Access log: the "gzip" parameter of the "access_log" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4986
diff
changeset
|
473 ngx_pool_t *pool; |
3849bb380605
Access log: the "gzip" parameter of the "access_log" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4986
diff
changeset
|
474 |
3849bb380605
Access log: the "gzip" parameter of the "access_log" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4986
diff
changeset
|
475 wbits = MAX_WBITS; |
3849bb380605
Access log: the "gzip" parameter of the "access_log" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4986
diff
changeset
|
476 memlevel = MAX_MEM_LEVEL - 1; |
3849bb380605
Access log: the "gzip" parameter of the "access_log" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4986
diff
changeset
|
477 |
3849bb380605
Access log: the "gzip" parameter of the "access_log" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4986
diff
changeset
|
478 while ((ssize_t) len < ((1 << (wbits - 1)) - 262)) { |
3849bb380605
Access log: the "gzip" parameter of the "access_log" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4986
diff
changeset
|
479 wbits--; |
3849bb380605
Access log: the "gzip" parameter of the "access_log" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4986
diff
changeset
|
480 memlevel--; |
3849bb380605
Access log: the "gzip" parameter of the "access_log" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4986
diff
changeset
|
481 } |
3849bb380605
Access log: the "gzip" parameter of the "access_log" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4986
diff
changeset
|
482 |
3849bb380605
Access log: the "gzip" parameter of the "access_log" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4986
diff
changeset
|
483 /* |
3849bb380605
Access log: the "gzip" parameter of the "access_log" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4986
diff
changeset
|
484 * This is a formula from deflateBound() for conservative upper bound of |
3849bb380605
Access log: the "gzip" parameter of the "access_log" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4986
diff
changeset
|
485 * compressed data plus 18 bytes of gzip wrapper. |
3849bb380605
Access log: the "gzip" parameter of the "access_log" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4986
diff
changeset
|
486 */ |
3849bb380605
Access log: the "gzip" parameter of the "access_log" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4986
diff
changeset
|
487 |
3849bb380605
Access log: the "gzip" parameter of the "access_log" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4986
diff
changeset
|
488 size = len + ((len + 7) >> 3) + ((len + 63) >> 6) + 5 + 18; |
3849bb380605
Access log: the "gzip" parameter of the "access_log" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4986
diff
changeset
|
489 |
3849bb380605
Access log: the "gzip" parameter of the "access_log" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4986
diff
changeset
|
490 ngx_memzero(&zstream, sizeof(z_stream)); |
3849bb380605
Access log: the "gzip" parameter of the "access_log" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4986
diff
changeset
|
491 |
3849bb380605
Access log: the "gzip" parameter of the "access_log" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4986
diff
changeset
|
492 pool = ngx_create_pool(256, log); |
3849bb380605
Access log: the "gzip" parameter of the "access_log" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4986
diff
changeset
|
493 if (pool == NULL) { |
3849bb380605
Access log: the "gzip" parameter of the "access_log" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4986
diff
changeset
|
494 /* simulate successful logging */ |
3849bb380605
Access log: the "gzip" parameter of the "access_log" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4986
diff
changeset
|
495 return len; |
3849bb380605
Access log: the "gzip" parameter of the "access_log" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4986
diff
changeset
|
496 } |
3849bb380605
Access log: the "gzip" parameter of the "access_log" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4986
diff
changeset
|
497 |
3849bb380605
Access log: the "gzip" parameter of the "access_log" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4986
diff
changeset
|
498 pool->log = log; |
3849bb380605
Access log: the "gzip" parameter of the "access_log" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4986
diff
changeset
|
499 |
6678 | 500 zstream.zalloc = ngx_stream_log_gzip_alloc; |
501 zstream.zfree = ngx_stream_log_gzip_free; | |
4988
3849bb380605
Access log: the "gzip" parameter of the "access_log" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4986
diff
changeset
|
502 zstream.opaque = pool; |
3849bb380605
Access log: the "gzip" parameter of the "access_log" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4986
diff
changeset
|
503 |
3849bb380605
Access log: the "gzip" parameter of the "access_log" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4986
diff
changeset
|
504 out = ngx_pnalloc(pool, size); |
3849bb380605
Access log: the "gzip" parameter of the "access_log" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4986
diff
changeset
|
505 if (out == NULL) { |
3849bb380605
Access log: the "gzip" parameter of the "access_log" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4986
diff
changeset
|
506 goto done; |
3849bb380605
Access log: the "gzip" parameter of the "access_log" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4986
diff
changeset
|
507 } |
3849bb380605
Access log: the "gzip" parameter of the "access_log" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4986
diff
changeset
|
508 |
3849bb380605
Access log: the "gzip" parameter of the "access_log" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4986
diff
changeset
|
509 zstream.next_in = buf; |
3849bb380605
Access log: the "gzip" parameter of the "access_log" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4986
diff
changeset
|
510 zstream.avail_in = len; |
3849bb380605
Access log: the "gzip" parameter of the "access_log" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4986
diff
changeset
|
511 zstream.next_out = out; |
3849bb380605
Access log: the "gzip" parameter of the "access_log" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4986
diff
changeset
|
512 zstream.avail_out = size; |
3849bb380605
Access log: the "gzip" parameter of the "access_log" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4986
diff
changeset
|
513 |
3849bb380605
Access log: the "gzip" parameter of the "access_log" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4986
diff
changeset
|
514 rc = deflateInit2(&zstream, (int) level, Z_DEFLATED, wbits + 16, memlevel, |
3849bb380605
Access log: the "gzip" parameter of the "access_log" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4986
diff
changeset
|
515 Z_DEFAULT_STRATEGY); |
3849bb380605
Access log: the "gzip" parameter of the "access_log" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4986
diff
changeset
|
516 |
3849bb380605
Access log: the "gzip" parameter of the "access_log" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4986
diff
changeset
|
517 if (rc != Z_OK) { |
3849bb380605
Access log: the "gzip" parameter of the "access_log" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4986
diff
changeset
|
518 ngx_log_error(NGX_LOG_ALERT, log, 0, "deflateInit2() failed: %d", rc); |
3849bb380605
Access log: the "gzip" parameter of the "access_log" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4986
diff
changeset
|
519 goto done; |
3849bb380605
Access log: the "gzip" parameter of the "access_log" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4986
diff
changeset
|
520 } |
3849bb380605
Access log: the "gzip" parameter of the "access_log" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4986
diff
changeset
|
521 |
6678 | 522 ngx_log_debug4(NGX_LOG_DEBUG_STREAM, log, 0, |
4988
3849bb380605
Access log: the "gzip" parameter of the "access_log" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4986
diff
changeset
|
523 "deflate in: ni:%p no:%p ai:%ud ao:%ud", |
3849bb380605
Access log: the "gzip" parameter of the "access_log" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4986
diff
changeset
|
524 zstream.next_in, zstream.next_out, |
3849bb380605
Access log: the "gzip" parameter of the "access_log" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4986
diff
changeset
|
525 zstream.avail_in, zstream.avail_out); |
3849bb380605
Access log: the "gzip" parameter of the "access_log" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4986
diff
changeset
|
526 |
3849bb380605
Access log: the "gzip" parameter of the "access_log" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4986
diff
changeset
|
527 rc = deflate(&zstream, Z_FINISH); |
3849bb380605
Access log: the "gzip" parameter of the "access_log" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4986
diff
changeset
|
528 |
3849bb380605
Access log: the "gzip" parameter of the "access_log" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4986
diff
changeset
|
529 if (rc != Z_STREAM_END) { |
3849bb380605
Access log: the "gzip" parameter of the "access_log" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4986
diff
changeset
|
530 ngx_log_error(NGX_LOG_ALERT, log, 0, |
3849bb380605
Access log: the "gzip" parameter of the "access_log" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4986
diff
changeset
|
531 "deflate(Z_FINISH) failed: %d", rc); |
3849bb380605
Access log: the "gzip" parameter of the "access_log" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4986
diff
changeset
|
532 goto done; |
3849bb380605
Access log: the "gzip" parameter of the "access_log" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4986
diff
changeset
|
533 } |
3849bb380605
Access log: the "gzip" parameter of the "access_log" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4986
diff
changeset
|
534 |
6678 | 535 ngx_log_debug5(NGX_LOG_DEBUG_STREAM, log, 0, |
4988
3849bb380605
Access log: the "gzip" parameter of the "access_log" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4986
diff
changeset
|
536 "deflate out: ni:%p no:%p ai:%ud ao:%ud rc:%d", |
3849bb380605
Access log: the "gzip" parameter of the "access_log" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4986
diff
changeset
|
537 zstream.next_in, zstream.next_out, |
3849bb380605
Access log: the "gzip" parameter of the "access_log" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4986
diff
changeset
|
538 zstream.avail_in, zstream.avail_out, |
3849bb380605
Access log: the "gzip" parameter of the "access_log" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4986
diff
changeset
|
539 rc); |
3849bb380605
Access log: the "gzip" parameter of the "access_log" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4986
diff
changeset
|
540 |
3849bb380605
Access log: the "gzip" parameter of the "access_log" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4986
diff
changeset
|
541 size -= zstream.avail_out; |
3849bb380605
Access log: the "gzip" parameter of the "access_log" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4986
diff
changeset
|
542 |
3849bb380605
Access log: the "gzip" parameter of the "access_log" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4986
diff
changeset
|
543 rc = deflateEnd(&zstream); |
3849bb380605
Access log: the "gzip" parameter of the "access_log" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4986
diff
changeset
|
544 |
3849bb380605
Access log: the "gzip" parameter of the "access_log" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4986
diff
changeset
|
545 if (rc != Z_OK) { |
3849bb380605
Access log: the "gzip" parameter of the "access_log" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4986
diff
changeset
|
546 ngx_log_error(NGX_LOG_ALERT, log, 0, "deflateEnd() failed: %d", rc); |
3849bb380605
Access log: the "gzip" parameter of the "access_log" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4986
diff
changeset
|
547 goto done; |
3849bb380605
Access log: the "gzip" parameter of the "access_log" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4986
diff
changeset
|
548 } |
3849bb380605
Access log: the "gzip" parameter of the "access_log" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4986
diff
changeset
|
549 |
3849bb380605
Access log: the "gzip" parameter of the "access_log" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4986
diff
changeset
|
550 n = ngx_write_fd(fd, out, size); |
3849bb380605
Access log: the "gzip" parameter of the "access_log" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4986
diff
changeset
|
551 |
3849bb380605
Access log: the "gzip" parameter of the "access_log" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4986
diff
changeset
|
552 if (n != (ssize_t) size) { |
3849bb380605
Access log: the "gzip" parameter of the "access_log" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4986
diff
changeset
|
553 err = (n == -1) ? ngx_errno : 0; |
3849bb380605
Access log: the "gzip" parameter of the "access_log" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4986
diff
changeset
|
554 |
3849bb380605
Access log: the "gzip" parameter of the "access_log" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4986
diff
changeset
|
555 ngx_destroy_pool(pool); |
3849bb380605
Access log: the "gzip" parameter of the "access_log" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4986
diff
changeset
|
556 |
3849bb380605
Access log: the "gzip" parameter of the "access_log" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4986
diff
changeset
|
557 ngx_set_errno(err); |
3849bb380605
Access log: the "gzip" parameter of the "access_log" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4986
diff
changeset
|
558 return -1; |
3849bb380605
Access log: the "gzip" parameter of the "access_log" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4986
diff
changeset
|
559 } |
3849bb380605
Access log: the "gzip" parameter of the "access_log" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4986
diff
changeset
|
560 |
3849bb380605
Access log: the "gzip" parameter of the "access_log" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4986
diff
changeset
|
561 done: |
3849bb380605
Access log: the "gzip" parameter of the "access_log" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4986
diff
changeset
|
562 |
3849bb380605
Access log: the "gzip" parameter of the "access_log" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4986
diff
changeset
|
563 ngx_destroy_pool(pool); |
3849bb380605
Access log: the "gzip" parameter of the "access_log" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4986
diff
changeset
|
564 |
3849bb380605
Access log: the "gzip" parameter of the "access_log" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4986
diff
changeset
|
565 /* simulate successful logging */ |
3849bb380605
Access log: the "gzip" parameter of the "access_log" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4986
diff
changeset
|
566 return len; |
3849bb380605
Access log: the "gzip" parameter of the "access_log" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4986
diff
changeset
|
567 } |
3849bb380605
Access log: the "gzip" parameter of the "access_log" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4986
diff
changeset
|
568 |
3849bb380605
Access log: the "gzip" parameter of the "access_log" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4986
diff
changeset
|
569 |
3849bb380605
Access log: the "gzip" parameter of the "access_log" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4986
diff
changeset
|
570 static void * |
6678 | 571 ngx_stream_log_gzip_alloc(void *opaque, u_int items, u_int size) |
4988
3849bb380605
Access log: the "gzip" parameter of the "access_log" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4986
diff
changeset
|
572 { |
3849bb380605
Access log: the "gzip" parameter of the "access_log" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4986
diff
changeset
|
573 ngx_pool_t *pool = opaque; |
3849bb380605
Access log: the "gzip" parameter of the "access_log" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4986
diff
changeset
|
574 |
6678 | 575 ngx_log_debug2(NGX_LOG_DEBUG_STREAM, pool->log, 0, |
4988
3849bb380605
Access log: the "gzip" parameter of the "access_log" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4986
diff
changeset
|
576 "gzip alloc: n:%ud s:%ud", items, size); |
3849bb380605
Access log: the "gzip" parameter of the "access_log" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4986
diff
changeset
|
577 |
3849bb380605
Access log: the "gzip" parameter of the "access_log" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4986
diff
changeset
|
578 return ngx_palloc(pool, items * size); |
3849bb380605
Access log: the "gzip" parameter of the "access_log" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4986
diff
changeset
|
579 } |
3849bb380605
Access log: the "gzip" parameter of the "access_log" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4986
diff
changeset
|
580 |
3849bb380605
Access log: the "gzip" parameter of the "access_log" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4986
diff
changeset
|
581 |
3849bb380605
Access log: the "gzip" parameter of the "access_log" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4986
diff
changeset
|
582 static void |
6678 | 583 ngx_stream_log_gzip_free(void *opaque, void *address) |
4988
3849bb380605
Access log: the "gzip" parameter of the "access_log" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4986
diff
changeset
|
584 { |
3849bb380605
Access log: the "gzip" parameter of the "access_log" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4986
diff
changeset
|
585 #if 0 |
3849bb380605
Access log: the "gzip" parameter of the "access_log" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4986
diff
changeset
|
586 ngx_pool_t *pool = opaque; |
3849bb380605
Access log: the "gzip" parameter of the "access_log" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4986
diff
changeset
|
587 |
6678 | 588 ngx_log_debug1(NGX_LOG_DEBUG_STREAM, pool->log, 0, |
589 "gzip free: %p", address); | |
4988
3849bb380605
Access log: the "gzip" parameter of the "access_log" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4986
diff
changeset
|
590 #endif |
3849bb380605
Access log: the "gzip" parameter of the "access_log" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4986
diff
changeset
|
591 } |
3849bb380605
Access log: the "gzip" parameter of the "access_log" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4986
diff
changeset
|
592 |
3849bb380605
Access log: the "gzip" parameter of the "access_log" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4986
diff
changeset
|
593 #endif |
3849bb380605
Access log: the "gzip" parameter of the "access_log" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4986
diff
changeset
|
594 |
3849bb380605
Access log: the "gzip" parameter of the "access_log" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4986
diff
changeset
|
595 |
4985
a0599b56e748
Reopening log files code moved to a separate function.
Valentin Bartenev <vbart@nginx.com>
parents:
4984
diff
changeset
|
596 static void |
6678 | 597 ngx_stream_log_flush(ngx_open_file_t *file, ngx_log_t *log) |
4985
a0599b56e748
Reopening log files code moved to a separate function.
Valentin Bartenev <vbart@nginx.com>
parents:
4984
diff
changeset
|
598 { |
6678 | 599 size_t len; |
600 ssize_t n; | |
601 ngx_stream_log_buf_t *buffer; | |
4985
a0599b56e748
Reopening log files code moved to a separate function.
Valentin Bartenev <vbart@nginx.com>
parents:
4984
diff
changeset
|
602 |
a0599b56e748
Reopening log files code moved to a separate function.
Valentin Bartenev <vbart@nginx.com>
parents:
4984
diff
changeset
|
603 buffer = file->data; |
a0599b56e748
Reopening log files code moved to a separate function.
Valentin Bartenev <vbart@nginx.com>
parents:
4984
diff
changeset
|
604 |
a0599b56e748
Reopening log files code moved to a separate function.
Valentin Bartenev <vbart@nginx.com>
parents:
4984
diff
changeset
|
605 len = buffer->pos - buffer->start; |
a0599b56e748
Reopening log files code moved to a separate function.
Valentin Bartenev <vbart@nginx.com>
parents:
4984
diff
changeset
|
606 |
a0599b56e748
Reopening log files code moved to a separate function.
Valentin Bartenev <vbart@nginx.com>
parents:
4984
diff
changeset
|
607 if (len == 0) { |
a0599b56e748
Reopening log files code moved to a separate function.
Valentin Bartenev <vbart@nginx.com>
parents:
4984
diff
changeset
|
608 return; |
a0599b56e748
Reopening log files code moved to a separate function.
Valentin Bartenev <vbart@nginx.com>
parents:
4984
diff
changeset
|
609 } |
a0599b56e748
Reopening log files code moved to a separate function.
Valentin Bartenev <vbart@nginx.com>
parents:
4984
diff
changeset
|
610 |
4988
3849bb380605
Access log: the "gzip" parameter of the "access_log" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4986
diff
changeset
|
611 #if (NGX_ZLIB) |
3849bb380605
Access log: the "gzip" parameter of the "access_log" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4986
diff
changeset
|
612 if (buffer->gzip) { |
6678 | 613 n = ngx_stream_log_gzip(file->fd, buffer->start, len, buffer->gzip, |
614 log); | |
4988
3849bb380605
Access log: the "gzip" parameter of the "access_log" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4986
diff
changeset
|
615 } else { |
3849bb380605
Access log: the "gzip" parameter of the "access_log" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4986
diff
changeset
|
616 n = ngx_write_fd(file->fd, buffer->start, len); |
3849bb380605
Access log: the "gzip" parameter of the "access_log" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4986
diff
changeset
|
617 } |
3849bb380605
Access log: the "gzip" parameter of the "access_log" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4986
diff
changeset
|
618 #else |
4985
a0599b56e748
Reopening log files code moved to a separate function.
Valentin Bartenev <vbart@nginx.com>
parents:
4984
diff
changeset
|
619 n = ngx_write_fd(file->fd, buffer->start, len); |
4988
3849bb380605
Access log: the "gzip" parameter of the "access_log" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4986
diff
changeset
|
620 #endif |
4985
a0599b56e748
Reopening log files code moved to a separate function.
Valentin Bartenev <vbart@nginx.com>
parents:
4984
diff
changeset
|
621 |
a0599b56e748
Reopening log files code moved to a separate function.
Valentin Bartenev <vbart@nginx.com>
parents:
4984
diff
changeset
|
622 if (n == -1) { |
a0599b56e748
Reopening log files code moved to a separate function.
Valentin Bartenev <vbart@nginx.com>
parents:
4984
diff
changeset
|
623 ngx_log_error(NGX_LOG_ALERT, log, ngx_errno, |
a0599b56e748
Reopening log files code moved to a separate function.
Valentin Bartenev <vbart@nginx.com>
parents:
4984
diff
changeset
|
624 ngx_write_fd_n " to \"%s\" failed", |
a0599b56e748
Reopening log files code moved to a separate function.
Valentin Bartenev <vbart@nginx.com>
parents:
4984
diff
changeset
|
625 file->name.data); |
a0599b56e748
Reopening log files code moved to a separate function.
Valentin Bartenev <vbart@nginx.com>
parents:
4984
diff
changeset
|
626 |
a0599b56e748
Reopening log files code moved to a separate function.
Valentin Bartenev <vbart@nginx.com>
parents:
4984
diff
changeset
|
627 } else if ((size_t) n != len) { |
a0599b56e748
Reopening log files code moved to a separate function.
Valentin Bartenev <vbart@nginx.com>
parents:
4984
diff
changeset
|
628 ngx_log_error(NGX_LOG_ALERT, log, 0, |
a0599b56e748
Reopening log files code moved to a separate function.
Valentin Bartenev <vbart@nginx.com>
parents:
4984
diff
changeset
|
629 ngx_write_fd_n " to \"%s\" was incomplete: %z of %uz", |
a0599b56e748
Reopening log files code moved to a separate function.
Valentin Bartenev <vbart@nginx.com>
parents:
4984
diff
changeset
|
630 file->name.data, n, len); |
a0599b56e748
Reopening log files code moved to a separate function.
Valentin Bartenev <vbart@nginx.com>
parents:
4984
diff
changeset
|
631 } |
a0599b56e748
Reopening log files code moved to a separate function.
Valentin Bartenev <vbart@nginx.com>
parents:
4984
diff
changeset
|
632 |
a0599b56e748
Reopening log files code moved to a separate function.
Valentin Bartenev <vbart@nginx.com>
parents:
4984
diff
changeset
|
633 buffer->pos = buffer->start; |
4986
3efc49b156d9
Access log: the "flush" parameter of the "access_log" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4985
diff
changeset
|
634 |
3efc49b156d9
Access log: the "flush" parameter of the "access_log" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4985
diff
changeset
|
635 if (buffer->event && buffer->event->timer_set) { |
3efc49b156d9
Access log: the "flush" parameter of the "access_log" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4985
diff
changeset
|
636 ngx_del_timer(buffer->event); |
3efc49b156d9
Access log: the "flush" parameter of the "access_log" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4985
diff
changeset
|
637 } |
3efc49b156d9
Access log: the "flush" parameter of the "access_log" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4985
diff
changeset
|
638 } |
3efc49b156d9
Access log: the "flush" parameter of the "access_log" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4985
diff
changeset
|
639 |
3efc49b156d9
Access log: the "flush" parameter of the "access_log" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4985
diff
changeset
|
640 |
3efc49b156d9
Access log: the "flush" parameter of the "access_log" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4985
diff
changeset
|
641 static void |
6678 | 642 ngx_stream_log_flush_handler(ngx_event_t *ev) |
4986
3efc49b156d9
Access log: the "flush" parameter of the "access_log" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4985
diff
changeset
|
643 { |
3efc49b156d9
Access log: the "flush" parameter of the "access_log" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4985
diff
changeset
|
644 ngx_log_debug0(NGX_LOG_DEBUG_EVENT, ev->log, 0, |
6678 | 645 "stream log buffer flush handler"); |
4986
3efc49b156d9
Access log: the "flush" parameter of the "access_log" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4985
diff
changeset
|
646 |
6927
c36d160cd4e0
Access log: removed dead ev->timedout check in flush timer handler.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6840
diff
changeset
|
647 ngx_stream_log_flush(ev->data, ev->log); |
4985
a0599b56e748
Reopening log files code moved to a separate function.
Valentin Bartenev <vbart@nginx.com>
parents:
4984
diff
changeset
|
648 } |
a0599b56e748
Reopening log files code moved to a separate function.
Valentin Bartenev <vbart@nginx.com>
parents:
4984
diff
changeset
|
649 |
a0599b56e748
Reopening log files code moved to a separate function.
Valentin Bartenev <vbart@nginx.com>
parents:
4984
diff
changeset
|
650 |
497 | 651 static u_char * |
6678 | 652 ngx_stream_log_copy_short(ngx_stream_session_t *s, u_char *buf, |
653 ngx_stream_log_op_t *op) | |
479 | 654 { |
655 size_t len; | |
656 uintptr_t data; | |
657 | |
658 len = op->len; | |
659 data = op->data; | |
660 | |
661 while (len--) { | |
662 *buf++ = (u_char) (data & 0xff); | |
663 data >>= 8; | |
664 } | |
665 | |
666 return buf; | |
667 } | |
668 | |
669 | |
497 | 670 static u_char * |
6678 | 671 ngx_stream_log_copy_long(ngx_stream_session_t *s, u_char *buf, |
672 ngx_stream_log_op_t *op) | |
479 | 673 { |
674 return ngx_cpymem(buf, (u_char *) op->data, op->len); | |
675 } | |
676 | |
677 | |
497 | 678 static ngx_int_t |
6678 | 679 ngx_stream_log_variable_compile(ngx_conf_t *cf, ngx_stream_log_op_t *op, |
6840
0cf4e82e7c48
Access log: support for json escaping.
Valentin Bartenev <vbart@nginx.com>
parents:
6693
diff
changeset
|
680 ngx_str_t *value, ngx_uint_t json) |
501 | 681 { |
509 | 682 ngx_int_t index; |
501 | 683 |
6678 | 684 index = ngx_stream_get_variable_index(cf, value); |
509 | 685 if (index == NGX_ERROR) { |
501 | 686 return NGX_ERROR; |
687 } | |
688 | |
689 op->len = 0; | |
6840
0cf4e82e7c48
Access log: support for json escaping.
Valentin Bartenev <vbart@nginx.com>
parents:
6693
diff
changeset
|
690 |
0cf4e82e7c48
Access log: support for json escaping.
Valentin Bartenev <vbart@nginx.com>
parents:
6693
diff
changeset
|
691 if (json) { |
0cf4e82e7c48
Access log: support for json escaping.
Valentin Bartenev <vbart@nginx.com>
parents:
6693
diff
changeset
|
692 op->getlen = ngx_stream_log_json_variable_getlen; |
0cf4e82e7c48
Access log: support for json escaping.
Valentin Bartenev <vbart@nginx.com>
parents:
6693
diff
changeset
|
693 op->run = ngx_stream_log_json_variable; |
0cf4e82e7c48
Access log: support for json escaping.
Valentin Bartenev <vbart@nginx.com>
parents:
6693
diff
changeset
|
694 |
0cf4e82e7c48
Access log: support for json escaping.
Valentin Bartenev <vbart@nginx.com>
parents:
6693
diff
changeset
|
695 } else { |
0cf4e82e7c48
Access log: support for json escaping.
Valentin Bartenev <vbart@nginx.com>
parents:
6693
diff
changeset
|
696 op->getlen = ngx_stream_log_variable_getlen; |
0cf4e82e7c48
Access log: support for json escaping.
Valentin Bartenev <vbart@nginx.com>
parents:
6693
diff
changeset
|
697 op->run = ngx_stream_log_variable; |
0cf4e82e7c48
Access log: support for json escaping.
Valentin Bartenev <vbart@nginx.com>
parents:
6693
diff
changeset
|
698 } |
0cf4e82e7c48
Access log: support for json escaping.
Valentin Bartenev <vbart@nginx.com>
parents:
6693
diff
changeset
|
699 |
509 | 700 op->data = index; |
501 | 701 |
702 return NGX_OK; | |
703 } | |
704 | |
705 | |
706 static size_t | |
6678 | 707 ngx_stream_log_variable_getlen(ngx_stream_session_t *s, uintptr_t data) |
501 | 708 { |
6678 | 709 uintptr_t len; |
710 ngx_stream_variable_value_t *value; | |
501 | 711 |
6678 | 712 value = ngx_stream_get_indexed_variable(s, data); |
501 | 713 |
573 | 714 if (value == NULL || value->not_found) { |
501 | 715 return 1; |
716 } | |
717 | |
6678 | 718 len = ngx_stream_log_escape(NULL, value->data, value->len); |
2008
66dc85397a90
escape 0x00-0x1f, ", and \ in access log variables
Igor Sysoev <igor@sysoev.ru>
parents:
1640
diff
changeset
|
719 |
66dc85397a90
escape 0x00-0x1f, ", and \ in access log variables
Igor Sysoev <igor@sysoev.ru>
parents:
1640
diff
changeset
|
720 value->escape = len ? 1 : 0; |
66dc85397a90
escape 0x00-0x1f, ", and \ in access log variables
Igor Sysoev <igor@sysoev.ru>
parents:
1640
diff
changeset
|
721 |
66dc85397a90
escape 0x00-0x1f, ", and \ in access log variables
Igor Sysoev <igor@sysoev.ru>
parents:
1640
diff
changeset
|
722 return value->len + len * 3; |
501 | 723 } |
724 | |
725 | |
726 static u_char * | |
6678 | 727 ngx_stream_log_variable(ngx_stream_session_t *s, u_char *buf, |
728 ngx_stream_log_op_t *op) | |
501 | 729 { |
6678 | 730 ngx_stream_variable_value_t *value; |
501 | 731 |
6678 | 732 value = ngx_stream_get_indexed_variable(s, op->data); |
501 | 733 |
573 | 734 if (value == NULL || value->not_found) { |
501 | 735 *buf = '-'; |
736 return buf + 1; | |
737 } | |
738 | |
2008
66dc85397a90
escape 0x00-0x1f, ", and \ in access log variables
Igor Sysoev <igor@sysoev.ru>
parents:
1640
diff
changeset
|
739 if (value->escape == 0) { |
66dc85397a90
escape 0x00-0x1f, ", and \ in access log variables
Igor Sysoev <igor@sysoev.ru>
parents:
1640
diff
changeset
|
740 return ngx_cpymem(buf, value->data, value->len); |
66dc85397a90
escape 0x00-0x1f, ", and \ in access log variables
Igor Sysoev <igor@sysoev.ru>
parents:
1640
diff
changeset
|
741 |
66dc85397a90
escape 0x00-0x1f, ", and \ in access log variables
Igor Sysoev <igor@sysoev.ru>
parents:
1640
diff
changeset
|
742 } else { |
6678 | 743 return (u_char *) ngx_stream_log_escape(buf, value->data, value->len); |
2008
66dc85397a90
escape 0x00-0x1f, ", and \ in access log variables
Igor Sysoev <igor@sysoev.ru>
parents:
1640
diff
changeset
|
744 } |
66dc85397a90
escape 0x00-0x1f, ", and \ in access log variables
Igor Sysoev <igor@sysoev.ru>
parents:
1640
diff
changeset
|
745 } |
66dc85397a90
escape 0x00-0x1f, ", and \ in access log variables
Igor Sysoev <igor@sysoev.ru>
parents:
1640
diff
changeset
|
746 |
66dc85397a90
escape 0x00-0x1f, ", and \ in access log variables
Igor Sysoev <igor@sysoev.ru>
parents:
1640
diff
changeset
|
747 |
66dc85397a90
escape 0x00-0x1f, ", and \ in access log variables
Igor Sysoev <igor@sysoev.ru>
parents:
1640
diff
changeset
|
748 static uintptr_t |
6678 | 749 ngx_stream_log_escape(u_char *dst, u_char *src, size_t size) |
2008
66dc85397a90
escape 0x00-0x1f, ", and \ in access log variables
Igor Sysoev <igor@sysoev.ru>
parents:
1640
diff
changeset
|
750 { |
3275 | 751 ngx_uint_t n; |
2008
66dc85397a90
escape 0x00-0x1f, ", and \ in access log variables
Igor Sysoev <igor@sysoev.ru>
parents:
1640
diff
changeset
|
752 static u_char hex[] = "0123456789ABCDEF"; |
66dc85397a90
escape 0x00-0x1f, ", and \ in access log variables
Igor Sysoev <igor@sysoev.ru>
parents:
1640
diff
changeset
|
753 |
66dc85397a90
escape 0x00-0x1f, ", and \ in access log variables
Igor Sysoev <igor@sysoev.ru>
parents:
1640
diff
changeset
|
754 static uint32_t escape[] = { |
66dc85397a90
escape 0x00-0x1f, ", and \ in access log variables
Igor Sysoev <igor@sysoev.ru>
parents:
1640
diff
changeset
|
755 0xffffffff, /* 1111 1111 1111 1111 1111 1111 1111 1111 */ |
66dc85397a90
escape 0x00-0x1f, ", and \ in access log variables
Igor Sysoev <igor@sysoev.ru>
parents:
1640
diff
changeset
|
756 |
66dc85397a90
escape 0x00-0x1f, ", and \ in access log variables
Igor Sysoev <igor@sysoev.ru>
parents:
1640
diff
changeset
|
757 /* ?>=< ;:98 7654 3210 /.-, +*)( '&%$ #"! */ |
66dc85397a90
escape 0x00-0x1f, ", and \ in access log variables
Igor Sysoev <igor@sysoev.ru>
parents:
1640
diff
changeset
|
758 0x00000004, /* 0000 0000 0000 0000 0000 0000 0000 0100 */ |
66dc85397a90
escape 0x00-0x1f, ", and \ in access log variables
Igor Sysoev <igor@sysoev.ru>
parents:
1640
diff
changeset
|
759 |
66dc85397a90
escape 0x00-0x1f, ", and \ in access log variables
Igor Sysoev <igor@sysoev.ru>
parents:
1640
diff
changeset
|
760 /* _^]\ [ZYX WVUT SRQP ONML KJIH GFED CBA@ */ |
66dc85397a90
escape 0x00-0x1f, ", and \ in access log variables
Igor Sysoev <igor@sysoev.ru>
parents:
1640
diff
changeset
|
761 0x10000000, /* 0001 0000 0000 0000 0000 0000 0000 0000 */ |
66dc85397a90
escape 0x00-0x1f, ", and \ in access log variables
Igor Sysoev <igor@sysoev.ru>
parents:
1640
diff
changeset
|
762 |
66dc85397a90
escape 0x00-0x1f, ", and \ in access log variables
Igor Sysoev <igor@sysoev.ru>
parents:
1640
diff
changeset
|
763 /* ~}| {zyx wvut srqp onml kjih gfed cba` */ |
4191
08d8af70760c
Improved access log escaping to better protect other software.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4133
diff
changeset
|
764 0x80000000, /* 1000 0000 0000 0000 0000 0000 0000 0000 */ |
2008
66dc85397a90
escape 0x00-0x1f, ", and \ in access log variables
Igor Sysoev <igor@sysoev.ru>
parents:
1640
diff
changeset
|
765 |
4191
08d8af70760c
Improved access log escaping to better protect other software.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4133
diff
changeset
|
766 0xffffffff, /* 1111 1111 1111 1111 1111 1111 1111 1111 */ |
08d8af70760c
Improved access log escaping to better protect other software.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4133
diff
changeset
|
767 0xffffffff, /* 1111 1111 1111 1111 1111 1111 1111 1111 */ |
08d8af70760c
Improved access log escaping to better protect other software.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4133
diff
changeset
|
768 0xffffffff, /* 1111 1111 1111 1111 1111 1111 1111 1111 */ |
08d8af70760c
Improved access log escaping to better protect other software.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4133
diff
changeset
|
769 0xffffffff, /* 1111 1111 1111 1111 1111 1111 1111 1111 */ |
2008
66dc85397a90
escape 0x00-0x1f, ", and \ in access log variables
Igor Sysoev <igor@sysoev.ru>
parents:
1640
diff
changeset
|
770 }; |
66dc85397a90
escape 0x00-0x1f, ", and \ in access log variables
Igor Sysoev <igor@sysoev.ru>
parents:
1640
diff
changeset
|
771 |
66dc85397a90
escape 0x00-0x1f, ", and \ in access log variables
Igor Sysoev <igor@sysoev.ru>
parents:
1640
diff
changeset
|
772 |
66dc85397a90
escape 0x00-0x1f, ", and \ in access log variables
Igor Sysoev <igor@sysoev.ru>
parents:
1640
diff
changeset
|
773 if (dst == NULL) { |
66dc85397a90
escape 0x00-0x1f, ", and \ in access log variables
Igor Sysoev <igor@sysoev.ru>
parents:
1640
diff
changeset
|
774 |
66dc85397a90
escape 0x00-0x1f, ", and \ in access log variables
Igor Sysoev <igor@sysoev.ru>
parents:
1640
diff
changeset
|
775 /* find the number of the characters to be escaped */ |
66dc85397a90
escape 0x00-0x1f, ", and \ in access log variables
Igor Sysoev <igor@sysoev.ru>
parents:
1640
diff
changeset
|
776 |
3115 | 777 n = 0; |
2008
66dc85397a90
escape 0x00-0x1f, ", and \ in access log variables
Igor Sysoev <igor@sysoev.ru>
parents:
1640
diff
changeset
|
778 |
3275 | 779 while (size) { |
6626
b3682580c1bd
Avoid left-shifting integers into the sign bit, which is undefined.
Sergey Kandaurov <pluknet@nginx.com>
parents:
5927
diff
changeset
|
780 if (escape[*src >> 5] & (1U << (*src & 0x1f))) { |
2008
66dc85397a90
escape 0x00-0x1f, ", and \ in access log variables
Igor Sysoev <igor@sysoev.ru>
parents:
1640
diff
changeset
|
781 n++; |
66dc85397a90
escape 0x00-0x1f, ", and \ in access log variables
Igor Sysoev <igor@sysoev.ru>
parents:
1640
diff
changeset
|
782 } |
66dc85397a90
escape 0x00-0x1f, ", and \ in access log variables
Igor Sysoev <igor@sysoev.ru>
parents:
1640
diff
changeset
|
783 src++; |
3275 | 784 size--; |
2008
66dc85397a90
escape 0x00-0x1f, ", and \ in access log variables
Igor Sysoev <igor@sysoev.ru>
parents:
1640
diff
changeset
|
785 } |
66dc85397a90
escape 0x00-0x1f, ", and \ in access log variables
Igor Sysoev <igor@sysoev.ru>
parents:
1640
diff
changeset
|
786 |
66dc85397a90
escape 0x00-0x1f, ", and \ in access log variables
Igor Sysoev <igor@sysoev.ru>
parents:
1640
diff
changeset
|
787 return (uintptr_t) n; |
66dc85397a90
escape 0x00-0x1f, ", and \ in access log variables
Igor Sysoev <igor@sysoev.ru>
parents:
1640
diff
changeset
|
788 } |
66dc85397a90
escape 0x00-0x1f, ", and \ in access log variables
Igor Sysoev <igor@sysoev.ru>
parents:
1640
diff
changeset
|
789 |
3275 | 790 while (size) { |
6626
b3682580c1bd
Avoid left-shifting integers into the sign bit, which is undefined.
Sergey Kandaurov <pluknet@nginx.com>
parents:
5927
diff
changeset
|
791 if (escape[*src >> 5] & (1U << (*src & 0x1f))) { |
2008
66dc85397a90
escape 0x00-0x1f, ", and \ in access log variables
Igor Sysoev <igor@sysoev.ru>
parents:
1640
diff
changeset
|
792 *dst++ = '\\'; |
66dc85397a90
escape 0x00-0x1f, ", and \ in access log variables
Igor Sysoev <igor@sysoev.ru>
parents:
1640
diff
changeset
|
793 *dst++ = 'x'; |
66dc85397a90
escape 0x00-0x1f, ", and \ in access log variables
Igor Sysoev <igor@sysoev.ru>
parents:
1640
diff
changeset
|
794 *dst++ = hex[*src >> 4]; |
66dc85397a90
escape 0x00-0x1f, ", and \ in access log variables
Igor Sysoev <igor@sysoev.ru>
parents:
1640
diff
changeset
|
795 *dst++ = hex[*src & 0xf]; |
66dc85397a90
escape 0x00-0x1f, ", and \ in access log variables
Igor Sysoev <igor@sysoev.ru>
parents:
1640
diff
changeset
|
796 src++; |
66dc85397a90
escape 0x00-0x1f, ", and \ in access log variables
Igor Sysoev <igor@sysoev.ru>
parents:
1640
diff
changeset
|
797 |
66dc85397a90
escape 0x00-0x1f, ", and \ in access log variables
Igor Sysoev <igor@sysoev.ru>
parents:
1640
diff
changeset
|
798 } else { |
66dc85397a90
escape 0x00-0x1f, ", and \ in access log variables
Igor Sysoev <igor@sysoev.ru>
parents:
1640
diff
changeset
|
799 *dst++ = *src++; |
66dc85397a90
escape 0x00-0x1f, ", and \ in access log variables
Igor Sysoev <igor@sysoev.ru>
parents:
1640
diff
changeset
|
800 } |
3275 | 801 size--; |
2008
66dc85397a90
escape 0x00-0x1f, ", and \ in access log variables
Igor Sysoev <igor@sysoev.ru>
parents:
1640
diff
changeset
|
802 } |
66dc85397a90
escape 0x00-0x1f, ", and \ in access log variables
Igor Sysoev <igor@sysoev.ru>
parents:
1640
diff
changeset
|
803 |
66dc85397a90
escape 0x00-0x1f, ", and \ in access log variables
Igor Sysoev <igor@sysoev.ru>
parents:
1640
diff
changeset
|
804 return (uintptr_t) dst; |
501 | 805 } |
806 | |
807 | |
6840
0cf4e82e7c48
Access log: support for json escaping.
Valentin Bartenev <vbart@nginx.com>
parents:
6693
diff
changeset
|
808 static size_t |
0cf4e82e7c48
Access log: support for json escaping.
Valentin Bartenev <vbart@nginx.com>
parents:
6693
diff
changeset
|
809 ngx_stream_log_json_variable_getlen(ngx_stream_session_t *s, uintptr_t data) |
0cf4e82e7c48
Access log: support for json escaping.
Valentin Bartenev <vbart@nginx.com>
parents:
6693
diff
changeset
|
810 { |
0cf4e82e7c48
Access log: support for json escaping.
Valentin Bartenev <vbart@nginx.com>
parents:
6693
diff
changeset
|
811 uintptr_t len; |
0cf4e82e7c48
Access log: support for json escaping.
Valentin Bartenev <vbart@nginx.com>
parents:
6693
diff
changeset
|
812 ngx_stream_variable_value_t *value; |
0cf4e82e7c48
Access log: support for json escaping.
Valentin Bartenev <vbart@nginx.com>
parents:
6693
diff
changeset
|
813 |
0cf4e82e7c48
Access log: support for json escaping.
Valentin Bartenev <vbart@nginx.com>
parents:
6693
diff
changeset
|
814 value = ngx_stream_get_indexed_variable(s, data); |
0cf4e82e7c48
Access log: support for json escaping.
Valentin Bartenev <vbart@nginx.com>
parents:
6693
diff
changeset
|
815 |
0cf4e82e7c48
Access log: support for json escaping.
Valentin Bartenev <vbart@nginx.com>
parents:
6693
diff
changeset
|
816 if (value == NULL || value->not_found) { |
0cf4e82e7c48
Access log: support for json escaping.
Valentin Bartenev <vbart@nginx.com>
parents:
6693
diff
changeset
|
817 return 0; |
0cf4e82e7c48
Access log: support for json escaping.
Valentin Bartenev <vbart@nginx.com>
parents:
6693
diff
changeset
|
818 } |
0cf4e82e7c48
Access log: support for json escaping.
Valentin Bartenev <vbart@nginx.com>
parents:
6693
diff
changeset
|
819 |
0cf4e82e7c48
Access log: support for json escaping.
Valentin Bartenev <vbart@nginx.com>
parents:
6693
diff
changeset
|
820 len = ngx_escape_json(NULL, value->data, value->len); |
0cf4e82e7c48
Access log: support for json escaping.
Valentin Bartenev <vbart@nginx.com>
parents:
6693
diff
changeset
|
821 |
0cf4e82e7c48
Access log: support for json escaping.
Valentin Bartenev <vbart@nginx.com>
parents:
6693
diff
changeset
|
822 value->escape = len ? 1 : 0; |
0cf4e82e7c48
Access log: support for json escaping.
Valentin Bartenev <vbart@nginx.com>
parents:
6693
diff
changeset
|
823 |
0cf4e82e7c48
Access log: support for json escaping.
Valentin Bartenev <vbart@nginx.com>
parents:
6693
diff
changeset
|
824 return value->len + len; |
0cf4e82e7c48
Access log: support for json escaping.
Valentin Bartenev <vbart@nginx.com>
parents:
6693
diff
changeset
|
825 } |
0cf4e82e7c48
Access log: support for json escaping.
Valentin Bartenev <vbart@nginx.com>
parents:
6693
diff
changeset
|
826 |
0cf4e82e7c48
Access log: support for json escaping.
Valentin Bartenev <vbart@nginx.com>
parents:
6693
diff
changeset
|
827 |
0cf4e82e7c48
Access log: support for json escaping.
Valentin Bartenev <vbart@nginx.com>
parents:
6693
diff
changeset
|
828 static u_char * |
0cf4e82e7c48
Access log: support for json escaping.
Valentin Bartenev <vbart@nginx.com>
parents:
6693
diff
changeset
|
829 ngx_stream_log_json_variable(ngx_stream_session_t *s, u_char *buf, |
0cf4e82e7c48
Access log: support for json escaping.
Valentin Bartenev <vbart@nginx.com>
parents:
6693
diff
changeset
|
830 ngx_stream_log_op_t *op) |
0cf4e82e7c48
Access log: support for json escaping.
Valentin Bartenev <vbart@nginx.com>
parents:
6693
diff
changeset
|
831 { |
0cf4e82e7c48
Access log: support for json escaping.
Valentin Bartenev <vbart@nginx.com>
parents:
6693
diff
changeset
|
832 ngx_stream_variable_value_t *value; |
0cf4e82e7c48
Access log: support for json escaping.
Valentin Bartenev <vbart@nginx.com>
parents:
6693
diff
changeset
|
833 |
0cf4e82e7c48
Access log: support for json escaping.
Valentin Bartenev <vbart@nginx.com>
parents:
6693
diff
changeset
|
834 value = ngx_stream_get_indexed_variable(s, op->data); |
0cf4e82e7c48
Access log: support for json escaping.
Valentin Bartenev <vbart@nginx.com>
parents:
6693
diff
changeset
|
835 |
0cf4e82e7c48
Access log: support for json escaping.
Valentin Bartenev <vbart@nginx.com>
parents:
6693
diff
changeset
|
836 if (value == NULL || value->not_found) { |
0cf4e82e7c48
Access log: support for json escaping.
Valentin Bartenev <vbart@nginx.com>
parents:
6693
diff
changeset
|
837 return buf; |
0cf4e82e7c48
Access log: support for json escaping.
Valentin Bartenev <vbart@nginx.com>
parents:
6693
diff
changeset
|
838 } |
0cf4e82e7c48
Access log: support for json escaping.
Valentin Bartenev <vbart@nginx.com>
parents:
6693
diff
changeset
|
839 |
0cf4e82e7c48
Access log: support for json escaping.
Valentin Bartenev <vbart@nginx.com>
parents:
6693
diff
changeset
|
840 if (value->escape == 0) { |
0cf4e82e7c48
Access log: support for json escaping.
Valentin Bartenev <vbart@nginx.com>
parents:
6693
diff
changeset
|
841 return ngx_cpymem(buf, value->data, value->len); |
0cf4e82e7c48
Access log: support for json escaping.
Valentin Bartenev <vbart@nginx.com>
parents:
6693
diff
changeset
|
842 |
0cf4e82e7c48
Access log: support for json escaping.
Valentin Bartenev <vbart@nginx.com>
parents:
6693
diff
changeset
|
843 } else { |
0cf4e82e7c48
Access log: support for json escaping.
Valentin Bartenev <vbart@nginx.com>
parents:
6693
diff
changeset
|
844 return (u_char *) ngx_escape_json(buf, value->data, value->len); |
0cf4e82e7c48
Access log: support for json escaping.
Valentin Bartenev <vbart@nginx.com>
parents:
6693
diff
changeset
|
845 } |
0cf4e82e7c48
Access log: support for json escaping.
Valentin Bartenev <vbart@nginx.com>
parents:
6693
diff
changeset
|
846 } |
0cf4e82e7c48
Access log: support for json escaping.
Valentin Bartenev <vbart@nginx.com>
parents:
6693
diff
changeset
|
847 |
0cf4e82e7c48
Access log: support for json escaping.
Valentin Bartenev <vbart@nginx.com>
parents:
6693
diff
changeset
|
848 |
497 | 849 static void * |
6678 | 850 ngx_stream_log_create_main_conf(ngx_conf_t *cf) |
176
c0552e5ab567
nginx-0.0.1-2003-11-09-23:03:38 import; separate building
Igor Sysoev <igor@sysoev.ru>
parents:
119
diff
changeset
|
851 { |
6678 | 852 ngx_stream_log_main_conf_t *conf; |
176
c0552e5ab567
nginx-0.0.1-2003-11-09-23:03:38 import; separate building
Igor Sysoev <igor@sysoev.ru>
parents:
119
diff
changeset
|
853 |
6678 | 854 conf = ngx_pcalloc(cf->pool, sizeof(ngx_stream_log_main_conf_t)); |
501 | 855 if (conf == NULL) { |
2912
c7d57b539248
return NULL instead of NGX_CONF_ERROR on a create conf failure
Igor Sysoev <igor@sysoev.ru>
parents:
2756
diff
changeset
|
856 return NULL; |
176
c0552e5ab567
nginx-0.0.1-2003-11-09-23:03:38 import; separate building
Igor Sysoev <igor@sysoev.ru>
parents:
119
diff
changeset
|
857 } |
c0552e5ab567
nginx-0.0.1-2003-11-09-23:03:38 import; separate building
Igor Sysoev <igor@sysoev.ru>
parents:
119
diff
changeset
|
858 |
6678 | 859 if (ngx_array_init(&conf->formats, cf->pool, 4, |
860 sizeof(ngx_stream_log_fmt_t)) | |
573 | 861 != NGX_OK) |
497 | 862 { |
2912
c7d57b539248
return NULL instead of NGX_CONF_ERROR on a create conf failure
Igor Sysoev <igor@sysoev.ru>
parents:
2756
diff
changeset
|
863 return NULL; |
497 | 864 } |
176
c0552e5ab567
nginx-0.0.1-2003-11-09-23:03:38 import; separate building
Igor Sysoev <igor@sysoev.ru>
parents:
119
diff
changeset
|
865 |
c0552e5ab567
nginx-0.0.1-2003-11-09-23:03:38 import; separate building
Igor Sysoev <igor@sysoev.ru>
parents:
119
diff
changeset
|
866 return conf; |
c0552e5ab567
nginx-0.0.1-2003-11-09-23:03:38 import; separate building
Igor Sysoev <igor@sysoev.ru>
parents:
119
diff
changeset
|
867 } |
c0552e5ab567
nginx-0.0.1-2003-11-09-23:03:38 import; separate building
Igor Sysoev <igor@sysoev.ru>
parents:
119
diff
changeset
|
868 |
c0552e5ab567
nginx-0.0.1-2003-11-09-23:03:38 import; separate building
Igor Sysoev <igor@sysoev.ru>
parents:
119
diff
changeset
|
869 |
497 | 870 static void * |
6678 | 871 ngx_stream_log_create_srv_conf(ngx_conf_t *cf) |
176
c0552e5ab567
nginx-0.0.1-2003-11-09-23:03:38 import; separate building
Igor Sysoev <igor@sysoev.ru>
parents:
119
diff
changeset
|
872 { |
6678 | 873 ngx_stream_log_srv_conf_t *conf; |
176
c0552e5ab567
nginx-0.0.1-2003-11-09-23:03:38 import; separate building
Igor Sysoev <igor@sysoev.ru>
parents:
119
diff
changeset
|
874 |
6678 | 875 conf = ngx_pcalloc(cf->pool, sizeof(ngx_stream_log_srv_conf_t)); |
501 | 876 if (conf == NULL) { |
2912
c7d57b539248
return NULL instead of NGX_CONF_ERROR on a create conf failure
Igor Sysoev <igor@sysoev.ru>
parents:
2756
diff
changeset
|
877 return NULL; |
427
0d08eabe5c7b
nginx-0.0.10-2004-09-15-20:00:43 import
Igor Sysoev <igor@sysoev.ru>
parents:
415
diff
changeset
|
878 } |
99
a059e1aa65d4
nginx-0.0.1-2003-06-02-19:24:30 import
Igor Sysoev <igor@sysoev.ru>
parents:
69
diff
changeset
|
879 |
2072 | 880 conf->open_file_cache = NGX_CONF_UNSET_PTR; |
881 | |
99
a059e1aa65d4
nginx-0.0.1-2003-06-02-19:24:30 import
Igor Sysoev <igor@sysoev.ru>
parents:
69
diff
changeset
|
882 return conf; |
a059e1aa65d4
nginx-0.0.1-2003-06-02-19:24:30 import
Igor Sysoev <igor@sysoev.ru>
parents:
69
diff
changeset
|
883 } |
a059e1aa65d4
nginx-0.0.1-2003-06-02-19:24:30 import
Igor Sysoev <igor@sysoev.ru>
parents:
69
diff
changeset
|
884 |
a059e1aa65d4
nginx-0.0.1-2003-06-02-19:24:30 import
Igor Sysoev <igor@sysoev.ru>
parents:
69
diff
changeset
|
885 |
497 | 886 static char * |
6678 | 887 ngx_stream_log_merge_srv_conf(ngx_conf_t *cf, void *parent, void *child) |
99
a059e1aa65d4
nginx-0.0.1-2003-06-02-19:24:30 import
Igor Sysoev <igor@sysoev.ru>
parents:
69
diff
changeset
|
888 { |
6678 | 889 ngx_stream_log_srv_conf_t *prev = parent; |
890 ngx_stream_log_srv_conf_t *conf = child; | |
176
c0552e5ab567
nginx-0.0.1-2003-11-09-23:03:38 import; separate building
Igor Sysoev <igor@sysoev.ru>
parents:
119
diff
changeset
|
891 |
2072 | 892 if (conf->open_file_cache == NGX_CONF_UNSET_PTR) { |
893 | |
894 conf->open_file_cache = prev->open_file_cache; | |
895 conf->open_file_cache_valid = prev->open_file_cache_valid; | |
896 conf->open_file_cache_min_uses = prev->open_file_cache_min_uses; | |
897 | |
898 if (conf->open_file_cache == NGX_CONF_UNSET_PTR) { | |
899 conf->open_file_cache = NULL; | |
900 } | |
901 } | |
902 | |
1074 | 903 if (conf->logs || conf->off) { |
904 return NGX_CONF_OK; | |
905 } | |
427
0d08eabe5c7b
nginx-0.0.10-2004-09-15-20:00:43 import
Igor Sysoev <igor@sysoev.ru>
parents:
415
diff
changeset
|
906 |
2078
9acbc5e7bcbd
fix variable access_log merging
Igor Sysoev <igor@sysoev.ru>
parents:
2077
diff
changeset
|
907 conf->logs = prev->logs; |
9acbc5e7bcbd
fix variable access_log merging
Igor Sysoev <igor@sysoev.ru>
parents:
2077
diff
changeset
|
908 conf->off = prev->off; |
176
c0552e5ab567
nginx-0.0.1-2003-11-09-23:03:38 import; separate building
Igor Sysoev <igor@sysoev.ru>
parents:
119
diff
changeset
|
909 |
99
a059e1aa65d4
nginx-0.0.1-2003-06-02-19:24:30 import
Igor Sysoev <igor@sysoev.ru>
parents:
69
diff
changeset
|
910 return NGX_CONF_OK; |
a059e1aa65d4
nginx-0.0.1-2003-06-02-19:24:30 import
Igor Sysoev <igor@sysoev.ru>
parents:
69
diff
changeset
|
911 } |
a059e1aa65d4
nginx-0.0.1-2003-06-02-19:24:30 import
Igor Sysoev <igor@sysoev.ru>
parents:
69
diff
changeset
|
912 |
a059e1aa65d4
nginx-0.0.1-2003-06-02-19:24:30 import
Igor Sysoev <igor@sysoev.ru>
parents:
69
diff
changeset
|
913 |
497 | 914 static char * |
6678 | 915 ngx_stream_log_set_log(ngx_conf_t *cf, ngx_command_t *cmd, void *conf) |
99
a059e1aa65d4
nginx-0.0.1-2003-06-02-19:24:30 import
Igor Sysoev <igor@sysoev.ru>
parents:
69
diff
changeset
|
916 { |
6678 | 917 ngx_stream_log_srv_conf_t *lscf = conf; |
99
a059e1aa65d4
nginx-0.0.1-2003-06-02-19:24:30 import
Igor Sysoev <igor@sysoev.ru>
parents:
69
diff
changeset
|
918 |
6678 | 919 ssize_t size; |
920 ngx_int_t gzip; | |
921 ngx_uint_t i, n; | |
922 ngx_msec_t flush; | |
923 ngx_str_t *value, name, s; | |
924 ngx_stream_log_t *log; | |
925 ngx_syslog_peer_t *peer; | |
926 ngx_stream_log_buf_t *buffer; | |
927 ngx_stream_log_fmt_t *fmt; | |
928 ngx_stream_script_compile_t sc; | |
929 ngx_stream_log_main_conf_t *lmcf; | |
930 ngx_stream_compile_complex_value_t ccv; | |
176
c0552e5ab567
nginx-0.0.1-2003-11-09-23:03:38 import; separate building
Igor Sysoev <igor@sysoev.ru>
parents:
119
diff
changeset
|
931 |
427
0d08eabe5c7b
nginx-0.0.10-2004-09-15-20:00:43 import
Igor Sysoev <igor@sysoev.ru>
parents:
415
diff
changeset
|
932 value = cf->args->elts; |
0d08eabe5c7b
nginx-0.0.10-2004-09-15-20:00:43 import
Igor Sysoev <igor@sysoev.ru>
parents:
415
diff
changeset
|
933 |
0d08eabe5c7b
nginx-0.0.10-2004-09-15-20:00:43 import
Igor Sysoev <igor@sysoev.ru>
parents:
415
diff
changeset
|
934 if (ngx_strcmp(value[1].data, "off") == 0) { |
6678 | 935 lscf->off = 1; |
3038
cd8738e76610
strict testing "access_log off"
Igor Sysoev <igor@sysoev.ru>
parents:
2912
diff
changeset
|
936 if (cf->args->nelts == 2) { |
cd8738e76610
strict testing "access_log off"
Igor Sysoev <igor@sysoev.ru>
parents:
2912
diff
changeset
|
937 return NGX_CONF_OK; |
cd8738e76610
strict testing "access_log off"
Igor Sysoev <igor@sysoev.ru>
parents:
2912
diff
changeset
|
938 } |
cd8738e76610
strict testing "access_log off"
Igor Sysoev <igor@sysoev.ru>
parents:
2912
diff
changeset
|
939 |
cd8738e76610
strict testing "access_log off"
Igor Sysoev <igor@sysoev.ru>
parents:
2912
diff
changeset
|
940 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, |
cd8738e76610
strict testing "access_log off"
Igor Sysoev <igor@sysoev.ru>
parents:
2912
diff
changeset
|
941 "invalid parameter \"%V\"", &value[2]); |
cd8738e76610
strict testing "access_log off"
Igor Sysoev <igor@sysoev.ru>
parents:
2912
diff
changeset
|
942 return NGX_CONF_ERROR; |
427
0d08eabe5c7b
nginx-0.0.10-2004-09-15-20:00:43 import
Igor Sysoev <igor@sysoev.ru>
parents:
415
diff
changeset
|
943 } |
0d08eabe5c7b
nginx-0.0.10-2004-09-15-20:00:43 import
Igor Sysoev <igor@sysoev.ru>
parents:
415
diff
changeset
|
944 |
6678 | 945 if (lscf->logs == NULL) { |
946 lscf->logs = ngx_array_create(cf->pool, 2, sizeof(ngx_stream_log_t)); | |
947 if (lscf->logs == NULL) { | |
176
c0552e5ab567
nginx-0.0.1-2003-11-09-23:03:38 import; separate building
Igor Sysoev <igor@sysoev.ru>
parents:
119
diff
changeset
|
948 return NGX_CONF_ERROR; |
c0552e5ab567
nginx-0.0.1-2003-11-09-23:03:38 import; separate building
Igor Sysoev <igor@sysoev.ru>
parents:
119
diff
changeset
|
949 } |
c0552e5ab567
nginx-0.0.1-2003-11-09-23:03:38 import; separate building
Igor Sysoev <igor@sysoev.ru>
parents:
119
diff
changeset
|
950 } |
99
a059e1aa65d4
nginx-0.0.1-2003-06-02-19:24:30 import
Igor Sysoev <igor@sysoev.ru>
parents:
69
diff
changeset
|
951 |
6678 | 952 lmcf = ngx_stream_conf_get_module_main_conf(cf, ngx_stream_log_module); |
99
a059e1aa65d4
nginx-0.0.1-2003-06-02-19:24:30 import
Igor Sysoev <igor@sysoev.ru>
parents:
69
diff
changeset
|
953 |
6678 | 954 log = ngx_array_push(lscf->logs); |
501 | 955 if (log == NULL) { |
176
c0552e5ab567
nginx-0.0.1-2003-11-09-23:03:38 import; separate building
Igor Sysoev <igor@sysoev.ru>
parents:
119
diff
changeset
|
956 return NGX_CONF_ERROR; |
c0552e5ab567
nginx-0.0.1-2003-11-09-23:03:38 import; separate building
Igor Sysoev <igor@sysoev.ru>
parents:
119
diff
changeset
|
957 } |
c0552e5ab567
nginx-0.0.1-2003-11-09-23:03:38 import; separate building
Igor Sysoev <igor@sysoev.ru>
parents:
119
diff
changeset
|
958 |
6678 | 959 ngx_memzero(log, sizeof(ngx_stream_log_t)); |
2072 | 960 |
5702
777202558122
Added syslog support for error_log and access_log directives.
Vladimir Homutov <vl@nginx.com>
parents:
5653
diff
changeset
|
961 |
777202558122
Added syslog support for error_log and access_log directives.
Vladimir Homutov <vl@nginx.com>
parents:
5653
diff
changeset
|
962 if (ngx_strncmp(value[1].data, "syslog:", 7) == 0) { |
777202558122
Added syslog support for error_log and access_log directives.
Vladimir Homutov <vl@nginx.com>
parents:
5653
diff
changeset
|
963 |
777202558122
Added syslog support for error_log and access_log directives.
Vladimir Homutov <vl@nginx.com>
parents:
5653
diff
changeset
|
964 peer = ngx_pcalloc(cf->pool, sizeof(ngx_syslog_peer_t)); |
777202558122
Added syslog support for error_log and access_log directives.
Vladimir Homutov <vl@nginx.com>
parents:
5653
diff
changeset
|
965 if (peer == NULL) { |
777202558122
Added syslog support for error_log and access_log directives.
Vladimir Homutov <vl@nginx.com>
parents:
5653
diff
changeset
|
966 return NGX_CONF_ERROR; |
777202558122
Added syslog support for error_log and access_log directives.
Vladimir Homutov <vl@nginx.com>
parents:
5653
diff
changeset
|
967 } |
777202558122
Added syslog support for error_log and access_log directives.
Vladimir Homutov <vl@nginx.com>
parents:
5653
diff
changeset
|
968 |
777202558122
Added syslog support for error_log and access_log directives.
Vladimir Homutov <vl@nginx.com>
parents:
5653
diff
changeset
|
969 if (ngx_syslog_process_conf(cf, peer) != NGX_CONF_OK) { |
777202558122
Added syslog support for error_log and access_log directives.
Vladimir Homutov <vl@nginx.com>
parents:
5653
diff
changeset
|
970 return NGX_CONF_ERROR; |
777202558122
Added syslog support for error_log and access_log directives.
Vladimir Homutov <vl@nginx.com>
parents:
5653
diff
changeset
|
971 } |
777202558122
Added syslog support for error_log and access_log directives.
Vladimir Homutov <vl@nginx.com>
parents:
5653
diff
changeset
|
972 |
777202558122
Added syslog support for error_log and access_log directives.
Vladimir Homutov <vl@nginx.com>
parents:
5653
diff
changeset
|
973 log->syslog_peer = peer; |
777202558122
Added syslog support for error_log and access_log directives.
Vladimir Homutov <vl@nginx.com>
parents:
5653
diff
changeset
|
974 |
777202558122
Added syslog support for error_log and access_log directives.
Vladimir Homutov <vl@nginx.com>
parents:
5653
diff
changeset
|
975 goto process_formats; |
777202558122
Added syslog support for error_log and access_log directives.
Vladimir Homutov <vl@nginx.com>
parents:
5653
diff
changeset
|
976 } |
777202558122
Added syslog support for error_log and access_log directives.
Vladimir Homutov <vl@nginx.com>
parents:
5653
diff
changeset
|
977 |
6678 | 978 n = ngx_stream_script_variables_count(&value[1]); |
2072 | 979 |
980 if (n == 0) { | |
981 log->file = ngx_conf_open_file(cf->cycle, &value[1]); | |
982 if (log->file == NULL) { | |
983 return NGX_CONF_ERROR; | |
984 } | |
985 | |
986 } else { | |
5330
314c3d7cc3a5
Backed out f1a91825730a and 7094bd12c1ff.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5317
diff
changeset
|
987 if (ngx_conf_full_name(cf->cycle, &value[1], 0) != NGX_OK) { |
2072 | 988 return NGX_CONF_ERROR; |
989 } | |
990 | |
6678 | 991 log->script = ngx_pcalloc(cf->pool, sizeof(ngx_stream_log_script_t)); |
2072 | 992 if (log->script == NULL) { |
993 return NGX_CONF_ERROR; | |
994 } | |
995 | |
6678 | 996 ngx_memzero(&sc, sizeof(ngx_stream_script_compile_t)); |
2072 | 997 |
998 sc.cf = cf; | |
999 sc.source = &value[1]; | |
1000 sc.lengths = &log->script->lengths; | |
1001 sc.values = &log->script->values; | |
1002 sc.variables = n; | |
1003 sc.complete_lengths = 1; | |
1004 sc.complete_values = 1; | |
1005 | |
6678 | 1006 if (ngx_stream_script_compile(&sc) != NGX_OK) { |
2072 | 1007 return NGX_CONF_ERROR; |
1008 } | |
176
c0552e5ab567
nginx-0.0.1-2003-11-09-23:03:38 import; separate building
Igor Sysoev <igor@sysoev.ru>
parents:
119
diff
changeset
|
1009 } |
c0552e5ab567
nginx-0.0.1-2003-11-09-23:03:38 import; separate building
Igor Sysoev <igor@sysoev.ru>
parents:
119
diff
changeset
|
1010 |
5702
777202558122
Added syslog support for error_log and access_log directives.
Vladimir Homutov <vl@nginx.com>
parents:
5653
diff
changeset
|
1011 process_formats: |
777202558122
Added syslog support for error_log and access_log directives.
Vladimir Homutov <vl@nginx.com>
parents:
5653
diff
changeset
|
1012 |
571 | 1013 if (cf->args->nelts >= 3) { |
176
c0552e5ab567
nginx-0.0.1-2003-11-09-23:03:38 import; separate building
Igor Sysoev <igor@sysoev.ru>
parents:
119
diff
changeset
|
1014 name = value[2]; |
581 | 1015 |
176
c0552e5ab567
nginx-0.0.1-2003-11-09-23:03:38 import; separate building
Igor Sysoev <igor@sysoev.ru>
parents:
119
diff
changeset
|
1016 } else { |
6678 | 1017 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, |
1018 "log format is not specified"); | |
1019 return NGX_CONF_ERROR; | |
176
c0552e5ab567
nginx-0.0.1-2003-11-09-23:03:38 import; separate building
Igor Sysoev <igor@sysoev.ru>
parents:
119
diff
changeset
|
1020 } |
c0552e5ab567
nginx-0.0.1-2003-11-09-23:03:38 import; separate building
Igor Sysoev <igor@sysoev.ru>
parents:
119
diff
changeset
|
1021 |
c0552e5ab567
nginx-0.0.1-2003-11-09-23:03:38 import; separate building
Igor Sysoev <igor@sysoev.ru>
parents:
119
diff
changeset
|
1022 fmt = lmcf->formats.elts; |
c0552e5ab567
nginx-0.0.1-2003-11-09-23:03:38 import; separate building
Igor Sysoev <igor@sysoev.ru>
parents:
119
diff
changeset
|
1023 for (i = 0; i < lmcf->formats.nelts; i++) { |
c0552e5ab567
nginx-0.0.1-2003-11-09-23:03:38 import; separate building
Igor Sysoev <igor@sysoev.ru>
parents:
119
diff
changeset
|
1024 if (fmt[i].name.len == name.len |
c0552e5ab567
nginx-0.0.1-2003-11-09-23:03:38 import; separate building
Igor Sysoev <igor@sysoev.ru>
parents:
119
diff
changeset
|
1025 && ngx_strcasecmp(fmt[i].name.data, name.data) == 0) |
c0552e5ab567
nginx-0.0.1-2003-11-09-23:03:38 import; separate building
Igor Sysoev <igor@sysoev.ru>
parents:
119
diff
changeset
|
1026 { |
2261 | 1027 log->format = &fmt[i]; |
4986
3efc49b156d9
Access log: the "flush" parameter of the "access_log" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4985
diff
changeset
|
1028 break; |
176
c0552e5ab567
nginx-0.0.1-2003-11-09-23:03:38 import; separate building
Igor Sysoev <igor@sysoev.ru>
parents:
119
diff
changeset
|
1029 } |
c0552e5ab567
nginx-0.0.1-2003-11-09-23:03:38 import; separate building
Igor Sysoev <igor@sysoev.ru>
parents:
119
diff
changeset
|
1030 } |
100
7ebc8b7fb816
nginx-0.0.1-2003-06-03-19:42:58 import
Igor Sysoev <igor@sysoev.ru>
parents:
99
diff
changeset
|
1031 |
4986
3efc49b156d9
Access log: the "flush" parameter of the "access_log" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4985
diff
changeset
|
1032 if (log->format == NULL) { |
3efc49b156d9
Access log: the "flush" parameter of the "access_log" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4985
diff
changeset
|
1033 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, |
3efc49b156d9
Access log: the "flush" parameter of the "access_log" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4985
diff
changeset
|
1034 "unknown log format \"%V\"", &name); |
3efc49b156d9
Access log: the "flush" parameter of the "access_log" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4985
diff
changeset
|
1035 return NGX_CONF_ERROR; |
3efc49b156d9
Access log: the "flush" parameter of the "access_log" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4985
diff
changeset
|
1036 } |
3efc49b156d9
Access log: the "flush" parameter of the "access_log" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4985
diff
changeset
|
1037 |
3efc49b156d9
Access log: the "flush" parameter of the "access_log" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4985
diff
changeset
|
1038 size = 0; |
3efc49b156d9
Access log: the "flush" parameter of the "access_log" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4985
diff
changeset
|
1039 flush = 0; |
4988
3849bb380605
Access log: the "gzip" parameter of the "access_log" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4986
diff
changeset
|
1040 gzip = 0; |
4986
3efc49b156d9
Access log: the "flush" parameter of the "access_log" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4985
diff
changeset
|
1041 |
3efc49b156d9
Access log: the "flush" parameter of the "access_log" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4985
diff
changeset
|
1042 for (i = 3; i < cf->args->nelts; i++) { |
487 | 1043 |
4986
3efc49b156d9
Access log: the "flush" parameter of the "access_log" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4985
diff
changeset
|
1044 if (ngx_strncmp(value[i].data, "buffer=", 7) == 0) { |
3efc49b156d9
Access log: the "flush" parameter of the "access_log" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4985
diff
changeset
|
1045 s.len = value[i].len - 7; |
3efc49b156d9
Access log: the "flush" parameter of the "access_log" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4985
diff
changeset
|
1046 s.data = value[i].data + 7; |
3efc49b156d9
Access log: the "flush" parameter of the "access_log" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4985
diff
changeset
|
1047 |
3efc49b156d9
Access log: the "flush" parameter of the "access_log" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4985
diff
changeset
|
1048 size = ngx_parse_size(&s); |
3efc49b156d9
Access log: the "flush" parameter of the "access_log" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4985
diff
changeset
|
1049 |
3efc49b156d9
Access log: the "flush" parameter of the "access_log" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4985
diff
changeset
|
1050 if (size == NGX_ERROR || size == 0) { |
3efc49b156d9
Access log: the "flush" parameter of the "access_log" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4985
diff
changeset
|
1051 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, |
3efc49b156d9
Access log: the "flush" parameter of the "access_log" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4985
diff
changeset
|
1052 "invalid buffer size \"%V\"", &s); |
3efc49b156d9
Access log: the "flush" parameter of the "access_log" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4985
diff
changeset
|
1053 return NGX_CONF_ERROR; |
3efc49b156d9
Access log: the "flush" parameter of the "access_log" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4985
diff
changeset
|
1054 } |
3efc49b156d9
Access log: the "flush" parameter of the "access_log" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4985
diff
changeset
|
1055 |
3efc49b156d9
Access log: the "flush" parameter of the "access_log" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4985
diff
changeset
|
1056 continue; |
3efc49b156d9
Access log: the "flush" parameter of the "access_log" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4985
diff
changeset
|
1057 } |
571 | 1058 |
4986
3efc49b156d9
Access log: the "flush" parameter of the "access_log" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4985
diff
changeset
|
1059 if (ngx_strncmp(value[i].data, "flush=", 6) == 0) { |
3efc49b156d9
Access log: the "flush" parameter of the "access_log" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4985
diff
changeset
|
1060 s.len = value[i].len - 6; |
3efc49b156d9
Access log: the "flush" parameter of the "access_log" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4985
diff
changeset
|
1061 s.data = value[i].data + 6; |
3efc49b156d9
Access log: the "flush" parameter of the "access_log" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4985
diff
changeset
|
1062 |
3efc49b156d9
Access log: the "flush" parameter of the "access_log" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4985
diff
changeset
|
1063 flush = ngx_parse_time(&s, 0); |
3efc49b156d9
Access log: the "flush" parameter of the "access_log" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4985
diff
changeset
|
1064 |
3efc49b156d9
Access log: the "flush" parameter of the "access_log" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4985
diff
changeset
|
1065 if (flush == (ngx_msec_t) NGX_ERROR || flush == 0) { |
3efc49b156d9
Access log: the "flush" parameter of the "access_log" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4985
diff
changeset
|
1066 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, |
3efc49b156d9
Access log: the "flush" parameter of the "access_log" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4985
diff
changeset
|
1067 "invalid flush time \"%V\"", &s); |
3efc49b156d9
Access log: the "flush" parameter of the "access_log" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4985
diff
changeset
|
1068 return NGX_CONF_ERROR; |
3efc49b156d9
Access log: the "flush" parameter of the "access_log" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4985
diff
changeset
|
1069 } |
3efc49b156d9
Access log: the "flush" parameter of the "access_log" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4985
diff
changeset
|
1070 |
3efc49b156d9
Access log: the "flush" parameter of the "access_log" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4985
diff
changeset
|
1071 continue; |
571 | 1072 } |
1073 | |
4988
3849bb380605
Access log: the "gzip" parameter of the "access_log" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4986
diff
changeset
|
1074 if (ngx_strncmp(value[i].data, "gzip", 4) == 0 |
3849bb380605
Access log: the "gzip" parameter of the "access_log" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4986
diff
changeset
|
1075 && (value[i].len == 4 || value[i].data[4] == '=')) |
3849bb380605
Access log: the "gzip" parameter of the "access_log" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4986
diff
changeset
|
1076 { |
3849bb380605
Access log: the "gzip" parameter of the "access_log" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4986
diff
changeset
|
1077 #if (NGX_ZLIB) |
3849bb380605
Access log: the "gzip" parameter of the "access_log" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4986
diff
changeset
|
1078 if (size == 0) { |
3849bb380605
Access log: the "gzip" parameter of the "access_log" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4986
diff
changeset
|
1079 size = 64 * 1024; |
3849bb380605
Access log: the "gzip" parameter of the "access_log" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4986
diff
changeset
|
1080 } |
3849bb380605
Access log: the "gzip" parameter of the "access_log" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4986
diff
changeset
|
1081 |
3849bb380605
Access log: the "gzip" parameter of the "access_log" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4986
diff
changeset
|
1082 if (value[i].len == 4) { |
3849bb380605
Access log: the "gzip" parameter of the "access_log" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4986
diff
changeset
|
1083 gzip = Z_BEST_SPEED; |
3849bb380605
Access log: the "gzip" parameter of the "access_log" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4986
diff
changeset
|
1084 continue; |
3849bb380605
Access log: the "gzip" parameter of the "access_log" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4986
diff
changeset
|
1085 } |
3849bb380605
Access log: the "gzip" parameter of the "access_log" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4986
diff
changeset
|
1086 |
3849bb380605
Access log: the "gzip" parameter of the "access_log" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4986
diff
changeset
|
1087 s.len = value[i].len - 5; |
3849bb380605
Access log: the "gzip" parameter of the "access_log" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4986
diff
changeset
|
1088 s.data = value[i].data + 5; |
3849bb380605
Access log: the "gzip" parameter of the "access_log" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4986
diff
changeset
|
1089 |
3849bb380605
Access log: the "gzip" parameter of the "access_log" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4986
diff
changeset
|
1090 gzip = ngx_atoi(s.data, s.len); |
3849bb380605
Access log: the "gzip" parameter of the "access_log" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4986
diff
changeset
|
1091 |
3849bb380605
Access log: the "gzip" parameter of the "access_log" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4986
diff
changeset
|
1092 if (gzip < 1 || gzip > 9) { |
3849bb380605
Access log: the "gzip" parameter of the "access_log" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4986
diff
changeset
|
1093 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, |
3849bb380605
Access log: the "gzip" parameter of the "access_log" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4986
diff
changeset
|
1094 "invalid compression level \"%V\"", &s); |
3849bb380605
Access log: the "gzip" parameter of the "access_log" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4986
diff
changeset
|
1095 return NGX_CONF_ERROR; |
3849bb380605
Access log: the "gzip" parameter of the "access_log" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4986
diff
changeset
|
1096 } |
3849bb380605
Access log: the "gzip" parameter of the "access_log" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4986
diff
changeset
|
1097 |
3849bb380605
Access log: the "gzip" parameter of the "access_log" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4986
diff
changeset
|
1098 continue; |
3849bb380605
Access log: the "gzip" parameter of the "access_log" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4986
diff
changeset
|
1099 |
3849bb380605
Access log: the "gzip" parameter of the "access_log" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4986
diff
changeset
|
1100 #else |
3849bb380605
Access log: the "gzip" parameter of the "access_log" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4986
diff
changeset
|
1101 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, |
3849bb380605
Access log: the "gzip" parameter of the "access_log" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4986
diff
changeset
|
1102 "nginx was built without zlib support"); |
3849bb380605
Access log: the "gzip" parameter of the "access_log" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4986
diff
changeset
|
1103 return NGX_CONF_ERROR; |
3849bb380605
Access log: the "gzip" parameter of the "access_log" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4986
diff
changeset
|
1104 #endif |
3849bb380605
Access log: the "gzip" parameter of the "access_log" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4986
diff
changeset
|
1105 } |
3849bb380605
Access log: the "gzip" parameter of the "access_log" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4986
diff
changeset
|
1106 |
5653
cb308813b453
Access log: the "if" parameter of the "access_log" directive.
Sergey Kandaurov <pluknet@nginx.com>
parents:
5361
diff
changeset
|
1107 if (ngx_strncmp(value[i].data, "if=", 3) == 0) { |
5833
e3016ee8dba3
Access log: fixed the "if=" parameter with buffering (ticket #625).
Valentin Bartenev <vbart@nginx.com>
parents:
5799
diff
changeset
|
1108 s.len = value[i].len - 3; |
e3016ee8dba3
Access log: fixed the "if=" parameter with buffering (ticket #625).
Valentin Bartenev <vbart@nginx.com>
parents:
5799
diff
changeset
|
1109 s.data = value[i].data + 3; |
e3016ee8dba3
Access log: fixed the "if=" parameter with buffering (ticket #625).
Valentin Bartenev <vbart@nginx.com>
parents:
5799
diff
changeset
|
1110 |
6678 | 1111 ngx_memzero(&ccv, sizeof(ngx_stream_compile_complex_value_t)); |
5833
e3016ee8dba3
Access log: fixed the "if=" parameter with buffering (ticket #625).
Valentin Bartenev <vbart@nginx.com>
parents:
5799
diff
changeset
|
1112 |
e3016ee8dba3
Access log: fixed the "if=" parameter with buffering (ticket #625).
Valentin Bartenev <vbart@nginx.com>
parents:
5799
diff
changeset
|
1113 ccv.cf = cf; |
e3016ee8dba3
Access log: fixed the "if=" parameter with buffering (ticket #625).
Valentin Bartenev <vbart@nginx.com>
parents:
5799
diff
changeset
|
1114 ccv.value = &s; |
e3016ee8dba3
Access log: fixed the "if=" parameter with buffering (ticket #625).
Valentin Bartenev <vbart@nginx.com>
parents:
5799
diff
changeset
|
1115 ccv.complex_value = ngx_palloc(cf->pool, |
6678 | 1116 sizeof(ngx_stream_complex_value_t)); |
5833
e3016ee8dba3
Access log: fixed the "if=" parameter with buffering (ticket #625).
Valentin Bartenev <vbart@nginx.com>
parents:
5799
diff
changeset
|
1117 if (ccv.complex_value == NULL) { |
e3016ee8dba3
Access log: fixed the "if=" parameter with buffering (ticket #625).
Valentin Bartenev <vbart@nginx.com>
parents:
5799
diff
changeset
|
1118 return NGX_CONF_ERROR; |
e3016ee8dba3
Access log: fixed the "if=" parameter with buffering (ticket #625).
Valentin Bartenev <vbart@nginx.com>
parents:
5799
diff
changeset
|
1119 } |
e3016ee8dba3
Access log: fixed the "if=" parameter with buffering (ticket #625).
Valentin Bartenev <vbart@nginx.com>
parents:
5799
diff
changeset
|
1120 |
6678 | 1121 if (ngx_stream_compile_complex_value(&ccv) != NGX_OK) { |
5833
e3016ee8dba3
Access log: fixed the "if=" parameter with buffering (ticket #625).
Valentin Bartenev <vbart@nginx.com>
parents:
5799
diff
changeset
|
1122 return NGX_CONF_ERROR; |
e3016ee8dba3
Access log: fixed the "if=" parameter with buffering (ticket #625).
Valentin Bartenev <vbart@nginx.com>
parents:
5799
diff
changeset
|
1123 } |
e3016ee8dba3
Access log: fixed the "if=" parameter with buffering (ticket #625).
Valentin Bartenev <vbart@nginx.com>
parents:
5799
diff
changeset
|
1124 |
e3016ee8dba3
Access log: fixed the "if=" parameter with buffering (ticket #625).
Valentin Bartenev <vbart@nginx.com>
parents:
5799
diff
changeset
|
1125 log->filter = ccv.complex_value; |
e3016ee8dba3
Access log: fixed the "if=" parameter with buffering (ticket #625).
Valentin Bartenev <vbart@nginx.com>
parents:
5799
diff
changeset
|
1126 |
5653
cb308813b453
Access log: the "if" parameter of the "access_log" directive.
Sergey Kandaurov <pluknet@nginx.com>
parents:
5361
diff
changeset
|
1127 continue; |
cb308813b453
Access log: the "if" parameter of the "access_log" directive.
Sergey Kandaurov <pluknet@nginx.com>
parents:
5361
diff
changeset
|
1128 } |
cb308813b453
Access log: the "if" parameter of the "access_log" directive.
Sergey Kandaurov <pluknet@nginx.com>
parents:
5361
diff
changeset
|
1129 |
4986
3efc49b156d9
Access log: the "flush" parameter of the "access_log" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4985
diff
changeset
|
1130 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, |
3efc49b156d9
Access log: the "flush" parameter of the "access_log" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4985
diff
changeset
|
1131 "invalid parameter \"%V\"", &value[i]); |
3efc49b156d9
Access log: the "flush" parameter of the "access_log" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4985
diff
changeset
|
1132 return NGX_CONF_ERROR; |
3efc49b156d9
Access log: the "flush" parameter of the "access_log" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4985
diff
changeset
|
1133 } |
3efc49b156d9
Access log: the "flush" parameter of the "access_log" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4985
diff
changeset
|
1134 |
3efc49b156d9
Access log: the "flush" parameter of the "access_log" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4985
diff
changeset
|
1135 if (flush && size == 0) { |
3efc49b156d9
Access log: the "flush" parameter of the "access_log" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4985
diff
changeset
|
1136 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, |
3efc49b156d9
Access log: the "flush" parameter of the "access_log" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4985
diff
changeset
|
1137 "no buffer is defined for access_log \"%V\"", |
3efc49b156d9
Access log: the "flush" parameter of the "access_log" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4985
diff
changeset
|
1138 &value[1]); |
3efc49b156d9
Access log: the "flush" parameter of the "access_log" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4985
diff
changeset
|
1139 return NGX_CONF_ERROR; |
3efc49b156d9
Access log: the "flush" parameter of the "access_log" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4985
diff
changeset
|
1140 } |
3efc49b156d9
Access log: the "flush" parameter of the "access_log" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4985
diff
changeset
|
1141 |
3efc49b156d9
Access log: the "flush" parameter of the "access_log" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4985
diff
changeset
|
1142 if (size) { |
3efc49b156d9
Access log: the "flush" parameter of the "access_log" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4985
diff
changeset
|
1143 |
2072 | 1144 if (log->script) { |
1145 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, | |
4133
59b99f217c6d
Replaced "can not" with "cannot" and "could not" in a bunch of places.
Ruslan Ermilov <ru@nginx.com>
parents:
3991
diff
changeset
|
1146 "buffered logs cannot have variables in name"); |
2072 | 1147 return NGX_CONF_ERROR; |
1148 } | |
1149 | |
5799
b1f8285297a7
Access log: allowed logs to syslog with "if=" (ticket #596).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5719
diff
changeset
|
1150 if (log->syslog_peer) { |
b1f8285297a7
Access log: allowed logs to syslog with "if=" (ticket #596).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5719
diff
changeset
|
1151 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, |
b1f8285297a7
Access log: allowed logs to syslog with "if=" (ticket #596).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5719
diff
changeset
|
1152 "logs to syslog cannot be buffered"); |
b1f8285297a7
Access log: allowed logs to syslog with "if=" (ticket #596).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5719
diff
changeset
|
1153 return NGX_CONF_ERROR; |
b1f8285297a7
Access log: allowed logs to syslog with "if=" (ticket #596).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5719
diff
changeset
|
1154 } |
b1f8285297a7
Access log: allowed logs to syslog with "if=" (ticket #596).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5719
diff
changeset
|
1155 |
4985
a0599b56e748
Reopening log files code moved to a separate function.
Valentin Bartenev <vbart@nginx.com>
parents:
4984
diff
changeset
|
1156 if (log->file->data) { |
a0599b56e748
Reopening log files code moved to a separate function.
Valentin Bartenev <vbart@nginx.com>
parents:
4984
diff
changeset
|
1157 buffer = log->file->data; |
a0599b56e748
Reopening log files code moved to a separate function.
Valentin Bartenev <vbart@nginx.com>
parents:
4984
diff
changeset
|
1158 |
4986
3efc49b156d9
Access log: the "flush" parameter of the "access_log" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4985
diff
changeset
|
1159 if (buffer->last - buffer->start != size |
4988
3849bb380605
Access log: the "gzip" parameter of the "access_log" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4986
diff
changeset
|
1160 || buffer->flush != flush |
3849bb380605
Access log: the "gzip" parameter of the "access_log" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4986
diff
changeset
|
1161 || buffer->gzip != gzip) |
4986
3efc49b156d9
Access log: the "flush" parameter of the "access_log" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4985
diff
changeset
|
1162 { |
4984
7737f0d788c1
Access log: fixed redundant buffer reallocation.
Valentin Bartenev <vbart@nginx.com>
parents:
4893
diff
changeset
|
1163 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, |
7737f0d788c1
Access log: fixed redundant buffer reallocation.
Valentin Bartenev <vbart@nginx.com>
parents:
4893
diff
changeset
|
1164 "access_log \"%V\" already defined " |
4986
3efc49b156d9
Access log: the "flush" parameter of the "access_log" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4985
diff
changeset
|
1165 "with conflicting parameters", |
3efc49b156d9
Access log: the "flush" parameter of the "access_log" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4985
diff
changeset
|
1166 &value[1]); |
4984
7737f0d788c1
Access log: fixed redundant buffer reallocation.
Valentin Bartenev <vbart@nginx.com>
parents:
4893
diff
changeset
|
1167 return NGX_CONF_ERROR; |
7737f0d788c1
Access log: fixed redundant buffer reallocation.
Valentin Bartenev <vbart@nginx.com>
parents:
4893
diff
changeset
|
1168 } |
7737f0d788c1
Access log: fixed redundant buffer reallocation.
Valentin Bartenev <vbart@nginx.com>
parents:
4893
diff
changeset
|
1169 |
7737f0d788c1
Access log: fixed redundant buffer reallocation.
Valentin Bartenev <vbart@nginx.com>
parents:
4893
diff
changeset
|
1170 return NGX_CONF_OK; |
571 | 1171 } |
1172 | |
6678 | 1173 buffer = ngx_pcalloc(cf->pool, sizeof(ngx_stream_log_buf_t)); |
4985
a0599b56e748
Reopening log files code moved to a separate function.
Valentin Bartenev <vbart@nginx.com>
parents:
4984
diff
changeset
|
1174 if (buffer == NULL) { |
571 | 1175 return NGX_CONF_ERROR; |
1176 } | |
1177 | |
4985
a0599b56e748
Reopening log files code moved to a separate function.
Valentin Bartenev <vbart@nginx.com>
parents:
4984
diff
changeset
|
1178 buffer->start = ngx_pnalloc(cf->pool, size); |
a0599b56e748
Reopening log files code moved to a separate function.
Valentin Bartenev <vbart@nginx.com>
parents:
4984
diff
changeset
|
1179 if (buffer->start == NULL) { |
a0599b56e748
Reopening log files code moved to a separate function.
Valentin Bartenev <vbart@nginx.com>
parents:
4984
diff
changeset
|
1180 return NGX_CONF_ERROR; |
a0599b56e748
Reopening log files code moved to a separate function.
Valentin Bartenev <vbart@nginx.com>
parents:
4984
diff
changeset
|
1181 } |
a0599b56e748
Reopening log files code moved to a separate function.
Valentin Bartenev <vbart@nginx.com>
parents:
4984
diff
changeset
|
1182 |
a0599b56e748
Reopening log files code moved to a separate function.
Valentin Bartenev <vbart@nginx.com>
parents:
4984
diff
changeset
|
1183 buffer->pos = buffer->start; |
a0599b56e748
Reopening log files code moved to a separate function.
Valentin Bartenev <vbart@nginx.com>
parents:
4984
diff
changeset
|
1184 buffer->last = buffer->start + size; |
a0599b56e748
Reopening log files code moved to a separate function.
Valentin Bartenev <vbart@nginx.com>
parents:
4984
diff
changeset
|
1185 |
4986
3efc49b156d9
Access log: the "flush" parameter of the "access_log" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4985
diff
changeset
|
1186 if (flush) { |
3efc49b156d9
Access log: the "flush" parameter of the "access_log" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4985
diff
changeset
|
1187 buffer->event = ngx_pcalloc(cf->pool, sizeof(ngx_event_t)); |
3efc49b156d9
Access log: the "flush" parameter of the "access_log" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4985
diff
changeset
|
1188 if (buffer->event == NULL) { |
3efc49b156d9
Access log: the "flush" parameter of the "access_log" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4985
diff
changeset
|
1189 return NGX_CONF_ERROR; |
3efc49b156d9
Access log: the "flush" parameter of the "access_log" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4985
diff
changeset
|
1190 } |
3efc49b156d9
Access log: the "flush" parameter of the "access_log" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4985
diff
changeset
|
1191 |
3efc49b156d9
Access log: the "flush" parameter of the "access_log" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4985
diff
changeset
|
1192 buffer->event->data = log->file; |
6678 | 1193 buffer->event->handler = ngx_stream_log_flush_handler; |
4986
3efc49b156d9
Access log: the "flush" parameter of the "access_log" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4985
diff
changeset
|
1194 buffer->event->log = &cf->cycle->new_log; |
5897
dff86e2246a5
Access log: cancel the flush timer on graceful shutdown.
Valentin Bartenev <vbart@nginx.com>
parents:
5833
diff
changeset
|
1195 buffer->event->cancelable = 1; |
4986
3efc49b156d9
Access log: the "flush" parameter of the "access_log" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4985
diff
changeset
|
1196 |
3efc49b156d9
Access log: the "flush" parameter of the "access_log" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4985
diff
changeset
|
1197 buffer->flush = flush; |
3efc49b156d9
Access log: the "flush" parameter of the "access_log" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4985
diff
changeset
|
1198 } |
3efc49b156d9
Access log: the "flush" parameter of the "access_log" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4985
diff
changeset
|
1199 |
4988
3849bb380605
Access log: the "gzip" parameter of the "access_log" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4986
diff
changeset
|
1200 buffer->gzip = gzip; |
3849bb380605
Access log: the "gzip" parameter of the "access_log" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4986
diff
changeset
|
1201 |
6678 | 1202 log->file->flush = ngx_stream_log_flush; |
4985
a0599b56e748
Reopening log files code moved to a separate function.
Valentin Bartenev <vbart@nginx.com>
parents:
4984
diff
changeset
|
1203 log->file->data = buffer; |
571 | 1204 } |
1205 | |
1206 return NGX_CONF_OK; | |
99
a059e1aa65d4
nginx-0.0.1-2003-06-02-19:24:30 import
Igor Sysoev <igor@sysoev.ru>
parents:
69
diff
changeset
|
1207 } |
176
c0552e5ab567
nginx-0.0.1-2003-11-09-23:03:38 import; separate building
Igor Sysoev <igor@sysoev.ru>
parents:
119
diff
changeset
|
1208 |
c0552e5ab567
nginx-0.0.1-2003-11-09-23:03:38 import; separate building
Igor Sysoev <igor@sysoev.ru>
parents:
119
diff
changeset
|
1209 |
497 | 1210 static char * |
6678 | 1211 ngx_stream_log_set_format(ngx_conf_t *cf, ngx_command_t *cmd, void *conf) |
176
c0552e5ab567
nginx-0.0.1-2003-11-09-23:03:38 import; separate building
Igor Sysoev <igor@sysoev.ru>
parents:
119
diff
changeset
|
1212 { |
6678 | 1213 ngx_stream_log_main_conf_t *lmcf = conf; |
176
c0552e5ab567
nginx-0.0.1-2003-11-09-23:03:38 import; separate building
Igor Sysoev <igor@sysoev.ru>
parents:
119
diff
changeset
|
1214 |
6678 | 1215 ngx_str_t *value; |
1216 ngx_uint_t i; | |
1217 ngx_stream_log_fmt_t *fmt; | |
176
c0552e5ab567
nginx-0.0.1-2003-11-09-23:03:38 import; separate building
Igor Sysoev <igor@sysoev.ru>
parents:
119
diff
changeset
|
1218 |
c0552e5ab567
nginx-0.0.1-2003-11-09-23:03:38 import; separate building
Igor Sysoev <igor@sysoev.ru>
parents:
119
diff
changeset
|
1219 value = cf->args->elts; |
c0552e5ab567
nginx-0.0.1-2003-11-09-23:03:38 import; separate building
Igor Sysoev <igor@sysoev.ru>
parents:
119
diff
changeset
|
1220 |
c0552e5ab567
nginx-0.0.1-2003-11-09-23:03:38 import; separate building
Igor Sysoev <igor@sysoev.ru>
parents:
119
diff
changeset
|
1221 fmt = lmcf->formats.elts; |
573 | 1222 for (i = 0; i < lmcf->formats.nelts; i++) { |
1223 if (fmt[i].name.len == value[1].len | |
1224 && ngx_strcmp(fmt[i].name.data, value[1].data) == 0) | |
176
c0552e5ab567
nginx-0.0.1-2003-11-09-23:03:38 import; separate building
Igor Sysoev <igor@sysoev.ru>
parents:
119
diff
changeset
|
1225 { |
2036 | 1226 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, |
1227 "duplicate \"log_format\" name \"%V\"", | |
1228 &value[1]); | |
1229 return NGX_CONF_ERROR; | |
176
c0552e5ab567
nginx-0.0.1-2003-11-09-23:03:38 import; separate building
Igor Sysoev <igor@sysoev.ru>
parents:
119
diff
changeset
|
1230 } |
c0552e5ab567
nginx-0.0.1-2003-11-09-23:03:38 import; separate building
Igor Sysoev <igor@sysoev.ru>
parents:
119
diff
changeset
|
1231 } |
c0552e5ab567
nginx-0.0.1-2003-11-09-23:03:38 import; separate building
Igor Sysoev <igor@sysoev.ru>
parents:
119
diff
changeset
|
1232 |
501 | 1233 fmt = ngx_array_push(&lmcf->formats); |
1234 if (fmt == NULL) { | |
176
c0552e5ab567
nginx-0.0.1-2003-11-09-23:03:38 import; separate building
Igor Sysoev <igor@sysoev.ru>
parents:
119
diff
changeset
|
1235 return NGX_CONF_ERROR; |
c0552e5ab567
nginx-0.0.1-2003-11-09-23:03:38 import; separate building
Igor Sysoev <igor@sysoev.ru>
parents:
119
diff
changeset
|
1236 } |
c0552e5ab567
nginx-0.0.1-2003-11-09-23:03:38 import; separate building
Igor Sysoev <igor@sysoev.ru>
parents:
119
diff
changeset
|
1237 |
c0552e5ab567
nginx-0.0.1-2003-11-09-23:03:38 import; separate building
Igor Sysoev <igor@sysoev.ru>
parents:
119
diff
changeset
|
1238 fmt->name = value[1]; |
c0552e5ab567
nginx-0.0.1-2003-11-09-23:03:38 import; separate building
Igor Sysoev <igor@sysoev.ru>
parents:
119
diff
changeset
|
1239 |
2261 | 1240 fmt->flushes = ngx_array_create(cf->pool, 4, sizeof(ngx_int_t)); |
1241 if (fmt->flushes == NULL) { | |
1242 return NGX_CONF_ERROR; | |
1243 } | |
1244 | |
6678 | 1245 fmt->ops = ngx_array_create(cf->pool, 16, sizeof(ngx_stream_log_op_t)); |
501 | 1246 if (fmt->ops == NULL) { |
176
c0552e5ab567
nginx-0.0.1-2003-11-09-23:03:38 import; separate building
Igor Sysoev <igor@sysoev.ru>
parents:
119
diff
changeset
|
1247 return NGX_CONF_ERROR; |
c0552e5ab567
nginx-0.0.1-2003-11-09-23:03:38 import; separate building
Igor Sysoev <igor@sysoev.ru>
parents:
119
diff
changeset
|
1248 } |
c0552e5ab567
nginx-0.0.1-2003-11-09-23:03:38 import; separate building
Igor Sysoev <igor@sysoev.ru>
parents:
119
diff
changeset
|
1249 |
6678 | 1250 return ngx_stream_log_compile_format(cf, fmt->flushes, fmt->ops, |
1251 cf->args, 2); | |
573 | 1252 } |
1253 | |
176
c0552e5ab567
nginx-0.0.1-2003-11-09-23:03:38 import; separate building
Igor Sysoev <igor@sysoev.ru>
parents:
119
diff
changeset
|
1254 |
573 | 1255 static char * |
6678 | 1256 ngx_stream_log_compile_format(ngx_conf_t *cf, ngx_array_t *flushes, |
2261 | 1257 ngx_array_t *ops, ngx_array_t *args, ngx_uint_t s) |
573 | 1258 { |
6678 | 1259 u_char *data, *p, ch; |
1260 size_t i, len; | |
1261 ngx_str_t *value, var; | |
1262 ngx_int_t *flush; | |
6840
0cf4e82e7c48
Access log: support for json escaping.
Valentin Bartenev <vbart@nginx.com>
parents:
6693
diff
changeset
|
1263 ngx_uint_t bracket, json; |
6678 | 1264 ngx_stream_log_op_t *op; |
573 | 1265 |
6840
0cf4e82e7c48
Access log: support for json escaping.
Valentin Bartenev <vbart@nginx.com>
parents:
6693
diff
changeset
|
1266 json = 0; |
573 | 1267 value = args->elts; |
1268 | |
6840
0cf4e82e7c48
Access log: support for json escaping.
Valentin Bartenev <vbart@nginx.com>
parents:
6693
diff
changeset
|
1269 if (s < args->nelts && ngx_strncmp(value[s].data, "escape=", 7) == 0) { |
0cf4e82e7c48
Access log: support for json escaping.
Valentin Bartenev <vbart@nginx.com>
parents:
6693
diff
changeset
|
1270 data = value[s].data + 7; |
0cf4e82e7c48
Access log: support for json escaping.
Valentin Bartenev <vbart@nginx.com>
parents:
6693
diff
changeset
|
1271 |
0cf4e82e7c48
Access log: support for json escaping.
Valentin Bartenev <vbart@nginx.com>
parents:
6693
diff
changeset
|
1272 if (ngx_strcmp(data, "json") == 0) { |
0cf4e82e7c48
Access log: support for json escaping.
Valentin Bartenev <vbart@nginx.com>
parents:
6693
diff
changeset
|
1273 json = 1; |
0cf4e82e7c48
Access log: support for json escaping.
Valentin Bartenev <vbart@nginx.com>
parents:
6693
diff
changeset
|
1274 |
0cf4e82e7c48
Access log: support for json escaping.
Valentin Bartenev <vbart@nginx.com>
parents:
6693
diff
changeset
|
1275 } else if (ngx_strcmp(data, "default") != 0) { |
0cf4e82e7c48
Access log: support for json escaping.
Valentin Bartenev <vbart@nginx.com>
parents:
6693
diff
changeset
|
1276 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, |
0cf4e82e7c48
Access log: support for json escaping.
Valentin Bartenev <vbart@nginx.com>
parents:
6693
diff
changeset
|
1277 "unknown log format escaping \"%s\"", data); |
0cf4e82e7c48
Access log: support for json escaping.
Valentin Bartenev <vbart@nginx.com>
parents:
6693
diff
changeset
|
1278 return NGX_CONF_ERROR; |
0cf4e82e7c48
Access log: support for json escaping.
Valentin Bartenev <vbart@nginx.com>
parents:
6693
diff
changeset
|
1279 } |
0cf4e82e7c48
Access log: support for json escaping.
Valentin Bartenev <vbart@nginx.com>
parents:
6693
diff
changeset
|
1280 |
0cf4e82e7c48
Access log: support for json escaping.
Valentin Bartenev <vbart@nginx.com>
parents:
6693
diff
changeset
|
1281 s++; |
0cf4e82e7c48
Access log: support for json escaping.
Valentin Bartenev <vbart@nginx.com>
parents:
6693
diff
changeset
|
1282 } |
0cf4e82e7c48
Access log: support for json escaping.
Valentin Bartenev <vbart@nginx.com>
parents:
6693
diff
changeset
|
1283 |
573 | 1284 for ( /* void */ ; s < args->nelts; s++) { |
176
c0552e5ab567
nginx-0.0.1-2003-11-09-23:03:38 import; separate building
Igor Sysoev <igor@sysoev.ru>
parents:
119
diff
changeset
|
1285 |
c0552e5ab567
nginx-0.0.1-2003-11-09-23:03:38 import; separate building
Igor Sysoev <igor@sysoev.ru>
parents:
119
diff
changeset
|
1286 i = 0; |
c0552e5ab567
nginx-0.0.1-2003-11-09-23:03:38 import; separate building
Igor Sysoev <igor@sysoev.ru>
parents:
119
diff
changeset
|
1287 |
c0552e5ab567
nginx-0.0.1-2003-11-09-23:03:38 import; separate building
Igor Sysoev <igor@sysoev.ru>
parents:
119
diff
changeset
|
1288 while (i < value[s].len) { |
c0552e5ab567
nginx-0.0.1-2003-11-09-23:03:38 import; separate building
Igor Sysoev <igor@sysoev.ru>
parents:
119
diff
changeset
|
1289 |
573 | 1290 op = ngx_array_push(ops); |
501 | 1291 if (op == NULL) { |
176
c0552e5ab567
nginx-0.0.1-2003-11-09-23:03:38 import; separate building
Igor Sysoev <igor@sysoev.ru>
parents:
119
diff
changeset
|
1292 return NGX_CONF_ERROR; |
c0552e5ab567
nginx-0.0.1-2003-11-09-23:03:38 import; separate building
Igor Sysoev <igor@sysoev.ru>
parents:
119
diff
changeset
|
1293 } |
c0552e5ab567
nginx-0.0.1-2003-11-09-23:03:38 import; separate building
Igor Sysoev <igor@sysoev.ru>
parents:
119
diff
changeset
|
1294 |
c0552e5ab567
nginx-0.0.1-2003-11-09-23:03:38 import; separate building
Igor Sysoev <igor@sysoev.ru>
parents:
119
diff
changeset
|
1295 data = &value[s].data[i]; |
c0552e5ab567
nginx-0.0.1-2003-11-09-23:03:38 import; separate building
Igor Sysoev <igor@sysoev.ru>
parents:
119
diff
changeset
|
1296 |
880 | 1297 if (value[s].data[i] == '$') { |
569 | 1298 |
1299 if (++i == value[s].len) { | |
1300 goto invalid; | |
1301 } | |
1302 | |
1303 if (value[s].data[i] == '{') { | |
1304 bracket = 1; | |
1305 | |
1306 if (++i == value[s].len) { | |
1307 goto invalid; | |
1308 } | |
1309 | |
1310 var.data = &value[s].data[i]; | |
1311 | |
1312 } else { | |
1313 bracket = 0; | |
1314 var.data = &value[s].data[i]; | |
1315 } | |
1316 | |
1317 for (var.len = 0; i < value[s].len; i++, var.len++) { | |
1318 ch = value[s].data[i]; | |
1319 | |
1320 if (ch == '}' && bracket) { | |
1321 i++; | |
1322 bracket = 0; | |
1323 break; | |
1324 } | |
1325 | |
1326 if ((ch >= 'A' && ch <= 'Z') | |
1327 || (ch >= 'a' && ch <= 'z') | |
1328 || (ch >= '0' && ch <= '9') | |
1329 || ch == '_') | |
1330 { | |
1331 continue; | |
1332 } | |
1333 | |
176
c0552e5ab567
nginx-0.0.1-2003-11-09-23:03:38 import; separate building
Igor Sysoev <igor@sysoev.ru>
parents:
119
diff
changeset
|
1334 break; |
c0552e5ab567
nginx-0.0.1-2003-11-09-23:03:38 import; separate building
Igor Sysoev <igor@sysoev.ru>
parents:
119
diff
changeset
|
1335 } |
c0552e5ab567
nginx-0.0.1-2003-11-09-23:03:38 import; separate building
Igor Sysoev <igor@sysoev.ru>
parents:
119
diff
changeset
|
1336 |
569 | 1337 if (bracket) { |
1338 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, | |
1339 "the closing bracket in \"%V\" " | |
1340 "variable is missing", &var); | |
1341 return NGX_CONF_ERROR; | |
1342 } | |
1343 | |
1344 if (var.len == 0) { | |
1345 goto invalid; | |
1346 } | |
1347 | |
6840
0cf4e82e7c48
Access log: support for json escaping.
Valentin Bartenev <vbart@nginx.com>
parents:
6693
diff
changeset
|
1348 if (ngx_stream_log_variable_compile(cf, op, &var, json) |
0cf4e82e7c48
Access log: support for json escaping.
Valentin Bartenev <vbart@nginx.com>
parents:
6693
diff
changeset
|
1349 != NGX_OK) |
0cf4e82e7c48
Access log: support for json escaping.
Valentin Bartenev <vbart@nginx.com>
parents:
6693
diff
changeset
|
1350 { |
569 | 1351 return NGX_CONF_ERROR; |
1352 } | |
1353 | |
2261 | 1354 if (flushes) { |
1355 | |
1356 flush = ngx_array_push(flushes); | |
1357 if (flush == NULL) { | |
1358 return NGX_CONF_ERROR; | |
1359 } | |
1360 | |
1361 *flush = op->data; /* variable index */ | |
1362 } | |
1363 | |
573 | 1364 continue; |
1365 } | |
1366 | |
1367 i++; | |
176
c0552e5ab567
nginx-0.0.1-2003-11-09-23:03:38 import; separate building
Igor Sysoev <igor@sysoev.ru>
parents:
119
diff
changeset
|
1368 |
880 | 1369 while (i < value[s].len && value[s].data[i] != '$') { |
573 | 1370 i++; |
1371 } | |
176
c0552e5ab567
nginx-0.0.1-2003-11-09-23:03:38 import; separate building
Igor Sysoev <igor@sysoev.ru>
parents:
119
diff
changeset
|
1372 |
573 | 1373 len = &value[s].data[i] - data; |
176
c0552e5ab567
nginx-0.0.1-2003-11-09-23:03:38 import; separate building
Igor Sysoev <igor@sysoev.ru>
parents:
119
diff
changeset
|
1374 |
573 | 1375 if (len) { |
176
c0552e5ab567
nginx-0.0.1-2003-11-09-23:03:38 import; separate building
Igor Sysoev <igor@sysoev.ru>
parents:
119
diff
changeset
|
1376 |
573 | 1377 op->len = len; |
1378 op->getlen = NULL; | |
176
c0552e5ab567
nginx-0.0.1-2003-11-09-23:03:38 import; separate building
Igor Sysoev <igor@sysoev.ru>
parents:
119
diff
changeset
|
1379 |
573 | 1380 if (len <= sizeof(uintptr_t)) { |
6678 | 1381 op->run = ngx_stream_log_copy_short; |
573 | 1382 op->data = 0; |
176
c0552e5ab567
nginx-0.0.1-2003-11-09-23:03:38 import; separate building
Igor Sysoev <igor@sysoev.ru>
parents:
119
diff
changeset
|
1383 |
573 | 1384 while (len--) { |
1385 op->data <<= 8; | |
1386 op->data |= data[len]; | |
1387 } | |
1388 | |
1389 } else { | |
6678 | 1390 op->run = ngx_stream_log_copy_long; |
176
c0552e5ab567
nginx-0.0.1-2003-11-09-23:03:38 import; separate building
Igor Sysoev <igor@sysoev.ru>
parents:
119
diff
changeset
|
1391 |
2049 | 1392 p = ngx_pnalloc(cf->pool, len); |
573 | 1393 if (p == NULL) { |
1394 return NGX_CONF_ERROR; | |
1395 } | |
176
c0552e5ab567
nginx-0.0.1-2003-11-09-23:03:38 import; separate building
Igor Sysoev <igor@sysoev.ru>
parents:
119
diff
changeset
|
1396 |
573 | 1397 ngx_memcpy(p, data, len); |
1398 op->data = (uintptr_t) p; | |
176
c0552e5ab567
nginx-0.0.1-2003-11-09-23:03:38 import; separate building
Igor Sysoev <igor@sysoev.ru>
parents:
119
diff
changeset
|
1399 } |
c0552e5ab567
nginx-0.0.1-2003-11-09-23:03:38 import; separate building
Igor Sysoev <igor@sysoev.ru>
parents:
119
diff
changeset
|
1400 } |
c0552e5ab567
nginx-0.0.1-2003-11-09-23:03:38 import; separate building
Igor Sysoev <igor@sysoev.ru>
parents:
119
diff
changeset
|
1401 } |
c0552e5ab567
nginx-0.0.1-2003-11-09-23:03:38 import; separate building
Igor Sysoev <igor@sysoev.ru>
parents:
119
diff
changeset
|
1402 } |
c0552e5ab567
nginx-0.0.1-2003-11-09-23:03:38 import; separate building
Igor Sysoev <igor@sysoev.ru>
parents:
119
diff
changeset
|
1403 |
569 | 1404 return NGX_CONF_OK; |
1405 | |
1406 invalid: | |
1407 | |
1408 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, "invalid parameter \"%s\"", data); | |
1409 | |
1410 return NGX_CONF_ERROR; | |
1411 } | |
1412 | |
176
c0552e5ab567
nginx-0.0.1-2003-11-09-23:03:38 import; separate building
Igor Sysoev <igor@sysoev.ru>
parents:
119
diff
changeset
|
1413 |
2072 | 1414 static char * |
6678 | 1415 ngx_stream_log_open_file_cache(ngx_conf_t *cf, ngx_command_t *cmd, void *conf) |
2072 | 1416 { |
6678 | 1417 ngx_stream_log_srv_conf_t *lscf = conf; |
2072 | 1418 |
1419 time_t inactive, valid; | |
1420 ngx_str_t *value, s; | |
1421 ngx_int_t max, min_uses; | |
1422 ngx_uint_t i; | |
1423 | |
6678 | 1424 if (lscf->open_file_cache != NGX_CONF_UNSET_PTR) { |
2072 | 1425 return "is duplicate"; |
1426 } | |
1427 | |
1428 value = cf->args->elts; | |
1429 | |
1430 max = 0; | |
1431 inactive = 10; | |
1432 valid = 60; | |
1433 min_uses = 1; | |
1434 | |
1435 for (i = 1; i < cf->args->nelts; i++) { | |
1436 | |
1437 if (ngx_strncmp(value[i].data, "max=", 4) == 0) { | |
1438 | |
1439 max = ngx_atoi(value[i].data + 4, value[i].len - 4); | |
1440 if (max == NGX_ERROR) { | |
1441 goto failed; | |
1442 } | |
1443 | |
1444 continue; | |
1445 } | |
1446 | |
1447 if (ngx_strncmp(value[i].data, "inactive=", 9) == 0) { | |
1448 | |
1449 s.len = value[i].len - 9; | |
1450 s.data = value[i].data + 9; | |
1451 | |
1452 inactive = ngx_parse_time(&s, 1); | |
4474 | 1453 if (inactive == (time_t) NGX_ERROR) { |
2072 | 1454 goto failed; |
1455 } | |
1456 | |
1457 continue; | |
1458 } | |
1459 | |
1460 if (ngx_strncmp(value[i].data, "min_uses=", 9) == 0) { | |
1461 | |
1462 min_uses = ngx_atoi(value[i].data + 9, value[i].len - 9); | |
1463 if (min_uses == NGX_ERROR) { | |
1464 goto failed; | |
1465 } | |
1466 | |
1467 continue; | |
1468 } | |
1469 | |
1470 if (ngx_strncmp(value[i].data, "valid=", 6) == 0) { | |
1471 | |
1472 s.len = value[i].len - 6; | |
1473 s.data = value[i].data + 6; | |
1474 | |
1475 valid = ngx_parse_time(&s, 1); | |
4474 | 1476 if (valid == (time_t) NGX_ERROR) { |
2072 | 1477 goto failed; |
1478 } | |
1479 | |
1480 continue; | |
1481 } | |
1482 | |
1483 if (ngx_strcmp(value[i].data, "off") == 0) { | |
1484 | |
6678 | 1485 lscf->open_file_cache = NULL; |
2072 | 1486 |
1487 continue; | |
1488 } | |
1489 | |
1490 failed: | |
1491 | |
1492 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, | |
1493 "invalid \"open_log_file_cache\" parameter \"%V\"", | |
1494 &value[i]); | |
1495 return NGX_CONF_ERROR; | |
1496 } | |
1497 | |
6678 | 1498 if (lscf->open_file_cache == NULL) { |
2072 | 1499 return NGX_CONF_OK; |
1500 } | |
1501 | |
1502 if (max == 0) { | |
1503 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, | |
1504 "\"open_log_file_cache\" must have \"max\" parameter"); | |
1505 return NGX_CONF_ERROR; | |
1506 } | |
1507 | |
6678 | 1508 lscf->open_file_cache = ngx_open_file_cache_init(cf->pool, max, inactive); |
2072 | 1509 |
6678 | 1510 if (lscf->open_file_cache) { |
2072 | 1511 |
6678 | 1512 lscf->open_file_cache_valid = valid; |
1513 lscf->open_file_cache_min_uses = min_uses; | |
2072 | 1514 |
1515 return NGX_CONF_OK; | |
1516 } | |
1517 | |
1518 return NGX_CONF_ERROR; | |
1519 } | |
1520 | |
1521 | |
569 | 1522 static ngx_int_t |
6678 | 1523 ngx_stream_log_init(ngx_conf_t *cf) |
569 | 1524 { |
6693 | 1525 ngx_stream_handler_pt *h; |
6678 | 1526 ngx_stream_core_main_conf_t *cmcf; |
573 | 1527 |
6678 | 1528 cmcf = ngx_stream_conf_get_module_main_conf(cf, ngx_stream_core_module); |
573 | 1529 |
6693 | 1530 h = ngx_array_push(&cmcf->phases[NGX_STREAM_LOG_PHASE].handlers); |
1531 if (h == NULL) { | |
1532 return NGX_ERROR; | |
1533 } | |
1534 | |
1535 *h = ngx_stream_log_handler; | |
569 | 1536 |
1537 return NGX_OK; | |
176
c0552e5ab567
nginx-0.0.1-2003-11-09-23:03:38 import; separate building
Igor Sysoev <igor@sysoev.ru>
parents:
119
diff
changeset
|
1538 } |