Mercurial > hg > nginx
annotate src/http/modules/ngx_http_log_module.c @ 9331:dbf76fdd109f default tip
release-1.27.4 tag
author | Maxim Dounin <mdounin@mdounin.ru> |
---|---|
date | Tue, 03 Sep 2024 13:11:25 +0300 |
parents | c7c8354f99fa |
children |
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> |
53cb81681040
nginx-0.0.1-2002-12-15-09:25:09 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
10 #include <ngx_http.h> |
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 |
880 | 17 typedef struct ngx_http_log_op_s ngx_http_log_op_t; |
18 | |
19 typedef u_char *(*ngx_http_log_op_run_pt) (ngx_http_request_t *r, u_char *buf, | |
20 ngx_http_log_op_t *op); | |
21 | |
22 typedef size_t (*ngx_http_log_op_getlen_pt) (ngx_http_request_t *r, | |
23 uintptr_t data); | |
24 | |
25 | |
26 struct ngx_http_log_op_s { | |
27 size_t len; | |
28 ngx_http_log_op_getlen_pt getlen; | |
29 ngx_http_log_op_run_pt run; | |
30 uintptr_t data; | |
31 }; | |
32 | |
573 | 33 |
34 typedef struct { | |
35 ngx_str_t name; | |
2261 | 36 ngx_array_t *flushes; |
573 | 37 ngx_array_t *ops; /* array of ngx_http_log_op_t */ |
38 } ngx_http_log_fmt_t; | |
39 | |
657 | 40 |
573 | 41 typedef struct { |
42 ngx_array_t formats; /* array of ngx_http_log_fmt_t */ | |
43 ngx_uint_t combined_used; /* unsigned combined_used:1 */ | |
44 } ngx_http_log_main_conf_t; | |
45 | |
657 | 46 |
573 | 47 typedef struct { |
4985
a0599b56e748
Reopening log files code moved to a separate function.
Valentin Bartenev <vbart@nginx.com>
parents:
4984
diff
changeset
|
48 u_char *start; |
a0599b56e748
Reopening log files code moved to a separate function.
Valentin Bartenev <vbart@nginx.com>
parents:
4984
diff
changeset
|
49 u_char *pos; |
a0599b56e748
Reopening log files code moved to a separate function.
Valentin Bartenev <vbart@nginx.com>
parents:
4984
diff
changeset
|
50 u_char *last; |
4986
3efc49b156d9
Access log: the "flush" parameter of the "access_log" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4985
diff
changeset
|
51 |
3efc49b156d9
Access log: the "flush" parameter of the "access_log" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4985
diff
changeset
|
52 ngx_event_t *event; |
3efc49b156d9
Access log: the "flush" parameter of the "access_log" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4985
diff
changeset
|
53 ngx_msec_t flush; |
4988
3849bb380605
Access log: the "gzip" parameter of the "access_log" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4986
diff
changeset
|
54 ngx_int_t gzip; |
4985
a0599b56e748
Reopening log files code moved to a separate function.
Valentin Bartenev <vbart@nginx.com>
parents:
4984
diff
changeset
|
55 } ngx_http_log_buf_t; |
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 |
a0599b56e748
Reopening log files code moved to a separate function.
Valentin Bartenev <vbart@nginx.com>
parents:
4984
diff
changeset
|
58 typedef struct { |
2072 | 59 ngx_array_t *lengths; |
60 ngx_array_t *values; | |
61 } ngx_http_log_script_t; | |
62 | |
63 | |
64 typedef struct { | |
573 | 65 ngx_open_file_t *file; |
2072 | 66 ngx_http_log_script_t *script; |
633 | 67 time_t disk_full_time; |
1071
bd4202f92581
log a failure of the writing to access_log once per minute
Igor Sysoev <igor@sysoev.ru>
parents:
905
diff
changeset
|
68 time_t error_log_time; |
5702
777202558122
Added syslog support for error_log and access_log directives.
Vladimir Homutov <vl@nginx.com>
parents:
5653
diff
changeset
|
69 ngx_syslog_peer_t *syslog_peer; |
2261 | 70 ngx_http_log_fmt_t *format; |
5653
cb308813b453
Access log: the "if" parameter of the "access_log" directive.
Sergey Kandaurov <pluknet@nginx.com>
parents:
5361
diff
changeset
|
71 ngx_http_complex_value_t *filter; |
573 | 72 } ngx_http_log_t; |
73 | |
657 | 74 |
573 | 75 typedef struct { |
76 ngx_array_t *logs; /* array of ngx_http_log_t */ | |
2072 | 77 |
78 ngx_open_file_cache_t *open_file_cache; | |
79 time_t open_file_cache_valid; | |
80 ngx_uint_t open_file_cache_min_uses; | |
81 | |
573 | 82 ngx_uint_t off; /* unsigned off:1 */ |
83 } ngx_http_log_loc_conf_t; | |
84 | |
85 | |
86 typedef struct { | |
87 ngx_str_t name; | |
88 size_t len; | |
89 ngx_http_log_op_run_pt run; | |
90 } ngx_http_log_var_t; | |
91 | |
92 | |
7223
265c29b0b8b8
Access log: support for disabling escaping (ticket #1450).
Vladimir Homutov <vl@nginx.com>
parents:
6948
diff
changeset
|
93 #define NGX_HTTP_LOG_ESCAPE_DEFAULT 0 |
265c29b0b8b8
Access log: support for disabling escaping (ticket #1450).
Vladimir Homutov <vl@nginx.com>
parents:
6948
diff
changeset
|
94 #define NGX_HTTP_LOG_ESCAPE_JSON 1 |
265c29b0b8b8
Access log: support for disabling escaping (ticket #1450).
Vladimir Homutov <vl@nginx.com>
parents:
6948
diff
changeset
|
95 #define NGX_HTTP_LOG_ESCAPE_NONE 2 |
265c29b0b8b8
Access log: support for disabling escaping (ticket #1450).
Vladimir Homutov <vl@nginx.com>
parents:
6948
diff
changeset
|
96 |
265c29b0b8b8
Access log: support for disabling escaping (ticket #1450).
Vladimir Homutov <vl@nginx.com>
parents:
6948
diff
changeset
|
97 |
1071
bd4202f92581
log a failure of the writing to access_log once per minute
Igor Sysoev <igor@sysoev.ru>
parents:
905
diff
changeset
|
98 static void ngx_http_log_write(ngx_http_request_t *r, ngx_http_log_t *log, |
bd4202f92581
log a failure of the writing to access_log once per minute
Igor Sysoev <igor@sysoev.ru>
parents:
905
diff
changeset
|
99 u_char *buf, size_t len); |
2072 | 100 static ssize_t ngx_http_log_script_write(ngx_http_request_t *r, |
101 ngx_http_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
|
102 |
4988
3849bb380605
Access log: the "gzip" parameter of the "access_log" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4986
diff
changeset
|
103 #if (NGX_ZLIB) |
3849bb380605
Access log: the "gzip" parameter of the "access_log" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4986
diff
changeset
|
104 static ssize_t ngx_http_log_gzip(ngx_fd_t fd, u_char *buf, size_t len, |
3849bb380605
Access log: the "gzip" parameter of the "access_log" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4986
diff
changeset
|
105 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
|
106 |
3849bb380605
Access log: the "gzip" parameter of the "access_log" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4986
diff
changeset
|
107 static void *ngx_http_log_gzip_alloc(void *opaque, u_int items, u_int size); |
3849bb380605
Access log: the "gzip" parameter of the "access_log" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4986
diff
changeset
|
108 static void ngx_http_log_gzip_free(void *opaque, void *address); |
3849bb380605
Access log: the "gzip" parameter of the "access_log" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4986
diff
changeset
|
109 #endif |
3849bb380605
Access log: the "gzip" parameter of the "access_log" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4986
diff
changeset
|
110 |
4985
a0599b56e748
Reopening log files code moved to a separate function.
Valentin Bartenev <vbart@nginx.com>
parents:
4984
diff
changeset
|
111 static void ngx_http_log_flush(ngx_open_file_t *file, ngx_log_t *log); |
4986
3efc49b156d9
Access log: the "flush" parameter of the "access_log" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4985
diff
changeset
|
112 static void ngx_http_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
|
113 |
290
87e73f067470
nginx-0.0.2-2004-03-16-10:10:12 import
Igor Sysoev <igor@sysoev.ru>
parents:
282
diff
changeset
|
114 static u_char *ngx_http_log_pipe(ngx_http_request_t *r, u_char *buf, |
497 | 115 ngx_http_log_op_t *op); |
290
87e73f067470
nginx-0.0.2-2004-03-16-10:10:12 import
Igor Sysoev <igor@sysoev.ru>
parents:
282
diff
changeset
|
116 static u_char *ngx_http_log_time(ngx_http_request_t *r, u_char *buf, |
497 | 117 ngx_http_log_op_t *op); |
3873 | 118 static u_char *ngx_http_log_iso8601(ngx_http_request_t *r, u_char *buf, |
119 ngx_http_log_op_t *op); | |
409
8ac40cae79f0
nginx-0.0.10-2004-08-29-07:55:41 import
Igor Sysoev <igor@sysoev.ru>
parents:
393
diff
changeset
|
120 static u_char *ngx_http_log_msec(ngx_http_request_t *r, u_char *buf, |
497 | 121 ngx_http_log_op_t *op); |
122 static u_char *ngx_http_log_request_time(ngx_http_request_t *r, u_char *buf, | |
123 ngx_http_log_op_t *op); | |
290
87e73f067470
nginx-0.0.2-2004-03-16-10:10:12 import
Igor Sysoev <igor@sysoev.ru>
parents:
282
diff
changeset
|
124 static u_char *ngx_http_log_status(ngx_http_request_t *r, u_char *buf, |
497 | 125 ngx_http_log_op_t *op); |
573 | 126 static u_char *ngx_http_log_bytes_sent(ngx_http_request_t *r, u_char *buf, |
497 | 127 ngx_http_log_op_t *op); |
577 | 128 static u_char *ngx_http_log_body_bytes_sent(ngx_http_request_t *r, |
573 | 129 u_char *buf, ngx_http_log_op_t *op); |
475 | 130 static u_char *ngx_http_log_request_length(ngx_http_request_t *r, u_char *buf, |
497 | 131 ngx_http_log_op_t *op); |
479 | 132 |
501 | 133 static ngx_int_t ngx_http_log_variable_compile(ngx_conf_t *cf, |
7223
265c29b0b8b8
Access log: support for disabling escaping (ticket #1450).
Vladimir Homutov <vl@nginx.com>
parents:
6948
diff
changeset
|
134 ngx_http_log_op_t *op, ngx_str_t *value, ngx_uint_t escape); |
501 | 135 static size_t ngx_http_log_variable_getlen(ngx_http_request_t *r, |
136 uintptr_t data); | |
137 static u_char *ngx_http_log_variable(ngx_http_request_t *r, u_char *buf, | |
138 ngx_http_log_op_t *op); | |
2008
66dc85397a90
escape 0x00-0x1f, ", and \ in access log variables
Igor Sysoev <igor@sysoev.ru>
parents:
1640
diff
changeset
|
139 static uintptr_t ngx_http_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:
6626
diff
changeset
|
140 static size_t ngx_http_log_json_variable_getlen(ngx_http_request_t *r, |
0cf4e82e7c48
Access log: support for json escaping.
Valentin Bartenev <vbart@nginx.com>
parents:
6626
diff
changeset
|
141 uintptr_t data); |
0cf4e82e7c48
Access log: support for json escaping.
Valentin Bartenev <vbart@nginx.com>
parents:
6626
diff
changeset
|
142 static u_char *ngx_http_log_json_variable(ngx_http_request_t *r, u_char *buf, |
0cf4e82e7c48
Access log: support for json escaping.
Valentin Bartenev <vbart@nginx.com>
parents:
6626
diff
changeset
|
143 ngx_http_log_op_t *op); |
7223
265c29b0b8b8
Access log: support for disabling escaping (ticket #1450).
Vladimir Homutov <vl@nginx.com>
parents:
6948
diff
changeset
|
144 static size_t ngx_http_log_unescaped_variable_getlen(ngx_http_request_t *r, |
265c29b0b8b8
Access log: support for disabling escaping (ticket #1450).
Vladimir Homutov <vl@nginx.com>
parents:
6948
diff
changeset
|
145 uintptr_t data); |
265c29b0b8b8
Access log: support for disabling escaping (ticket #1450).
Vladimir Homutov <vl@nginx.com>
parents:
6948
diff
changeset
|
146 static u_char *ngx_http_log_unescaped_variable(ngx_http_request_t *r, |
265c29b0b8b8
Access log: support for disabling escaping (ticket #1450).
Vladimir Homutov <vl@nginx.com>
parents:
6948
diff
changeset
|
147 u_char *buf, ngx_http_log_op_t *op); |
501 | 148 |
149 | |
176
c0552e5ab567
nginx-0.0.1-2003-11-09-23:03:38 import; separate building
Igor Sysoev <igor@sysoev.ru>
parents:
119
diff
changeset
|
150 static void *ngx_http_log_create_main_conf(ngx_conf_t *cf); |
c0552e5ab567
nginx-0.0.1-2003-11-09-23:03:38 import; separate building
Igor Sysoev <igor@sysoev.ru>
parents:
119
diff
changeset
|
151 static void *ngx_http_log_create_loc_conf(ngx_conf_t *cf); |
c0552e5ab567
nginx-0.0.1-2003-11-09-23:03:38 import; separate building
Igor Sysoev <igor@sysoev.ru>
parents:
119
diff
changeset
|
152 static char *ngx_http_log_merge_loc_conf(ngx_conf_t *cf, void *parent, |
497 | 153 void *child); |
99
a059e1aa65d4
nginx-0.0.1-2003-06-02-19:24:30 import
Igor Sysoev <igor@sysoev.ru>
parents:
69
diff
changeset
|
154 static char *ngx_http_log_set_log(ngx_conf_t *cf, ngx_command_t *cmd, |
497 | 155 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
|
156 static char *ngx_http_log_set_format(ngx_conf_t *cf, ngx_command_t *cmd, |
497 | 157 void *conf); |
573 | 158 static char *ngx_http_log_compile_format(ngx_conf_t *cf, |
2261 | 159 ngx_array_t *flushes, ngx_array_t *ops, ngx_array_t *args, ngx_uint_t s); |
2072 | 160 static char *ngx_http_log_open_file_cache(ngx_conf_t *cf, ngx_command_t *cmd, |
161 void *conf); | |
573 | 162 static ngx_int_t ngx_http_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
|
163 |
176
c0552e5ab567
nginx-0.0.1-2003-11-09-23:03:38 import; separate building
Igor Sysoev <igor@sysoev.ru>
parents:
119
diff
changeset
|
164 |
c0552e5ab567
nginx-0.0.1-2003-11-09-23:03:38 import; separate building
Igor Sysoev <igor@sysoev.ru>
parents:
119
diff
changeset
|
165 static ngx_command_t ngx_http_log_commands[] = { |
c0552e5ab567
nginx-0.0.1-2003-11-09-23:03:38 import; separate building
Igor Sysoev <igor@sysoev.ru>
parents:
119
diff
changeset
|
166 |
497 | 167 { ngx_string("log_format"), |
5927
ac2a8e4d8f01
Access log: restricted "log_format" to "http" level.
Sergey Kandaurov <pluknet@nginx.com>
parents:
5897
diff
changeset
|
168 NGX_HTTP_MAIN_CONF|NGX_CONF_2MORE, |
497 | 169 ngx_http_log_set_format, |
170 NGX_HTTP_MAIN_CONF_OFFSET, | |
171 0, | |
172 NULL }, | |
99
a059e1aa65d4
nginx-0.0.1-2003-06-02-19:24:30 import
Igor Sysoev <igor@sysoev.ru>
parents:
69
diff
changeset
|
173 |
497 | 174 { ngx_string("access_log"), |
645 | 175 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_HTTP_LIF_CONF |
4986
3efc49b156d9
Access log: the "flush" parameter of the "access_log" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4985
diff
changeset
|
176 |NGX_HTTP_LMT_CONF|NGX_CONF_1MORE, |
497 | 177 ngx_http_log_set_log, |
178 NGX_HTTP_LOC_CONF_OFFSET, | |
179 0, | |
180 NULL }, | |
99
a059e1aa65d4
nginx-0.0.1-2003-06-02-19:24:30 import
Igor Sysoev <igor@sysoev.ru>
parents:
69
diff
changeset
|
181 |
2072 | 182 { ngx_string("open_log_file_cache"), |
183 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_TAKE1234, | |
184 ngx_http_log_open_file_cache, | |
185 NGX_HTTP_LOC_CONF_OFFSET, | |
186 0, | |
187 NULL }, | |
188 | |
497 | 189 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
|
190 }; |
a059e1aa65d4
nginx-0.0.1-2003-06-02-19:24:30 import
Igor Sysoev <igor@sysoev.ru>
parents:
69
diff
changeset
|
191 |
a059e1aa65d4
nginx-0.0.1-2003-06-02-19:24:30 import
Igor Sysoev <igor@sysoev.ru>
parents:
69
diff
changeset
|
192 |
667 | 193 static ngx_http_module_t ngx_http_log_module_ctx = { |
880 | 194 NULL, /* preconfiguration */ |
573 | 195 ngx_http_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
|
196 |
176
c0552e5ab567
nginx-0.0.1-2003-11-09-23:03:38 import; separate building
Igor Sysoev <igor@sysoev.ru>
parents:
119
diff
changeset
|
197 ngx_http_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
|
198 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
|
199 |
a059e1aa65d4
nginx-0.0.1-2003-06-02-19:24:30 import
Igor Sysoev <igor@sysoev.ru>
parents:
69
diff
changeset
|
200 NULL, /* create server configuration */ |
a059e1aa65d4
nginx-0.0.1-2003-06-02-19:24:30 import
Igor Sysoev <igor@sysoev.ru>
parents:
69
diff
changeset
|
201 NULL, /* merge server configuration */ |
a059e1aa65d4
nginx-0.0.1-2003-06-02-19:24:30 import
Igor Sysoev <igor@sysoev.ru>
parents:
69
diff
changeset
|
202 |
4499
778ef9c3fd2d
Fixed spelling in single-line comments.
Ruslan Ermilov <ru@nginx.com>
parents:
4494
diff
changeset
|
203 ngx_http_log_create_loc_conf, /* create location configuration */ |
778ef9c3fd2d
Fixed spelling in single-line comments.
Ruslan Ermilov <ru@nginx.com>
parents:
4494
diff
changeset
|
204 ngx_http_log_merge_loc_conf /* merge location configuration */ |
99
a059e1aa65d4
nginx-0.0.1-2003-06-02-19:24:30 import
Igor Sysoev <igor@sysoev.ru>
parents:
69
diff
changeset
|
205 }; |
a059e1aa65d4
nginx-0.0.1-2003-06-02-19:24:30 import
Igor Sysoev <igor@sysoev.ru>
parents:
69
diff
changeset
|
206 |
a059e1aa65d4
nginx-0.0.1-2003-06-02-19:24:30 import
Igor Sysoev <igor@sysoev.ru>
parents:
69
diff
changeset
|
207 |
a059e1aa65d4
nginx-0.0.1-2003-06-02-19:24:30 import
Igor Sysoev <igor@sysoev.ru>
parents:
69
diff
changeset
|
208 ngx_module_t ngx_http_log_module = { |
509 | 209 NGX_MODULE_V1, |
99
a059e1aa65d4
nginx-0.0.1-2003-06-02-19:24:30 import
Igor Sysoev <igor@sysoev.ru>
parents:
69
diff
changeset
|
210 &ngx_http_log_module_ctx, /* module context */ |
a059e1aa65d4
nginx-0.0.1-2003-06-02-19:24:30 import
Igor Sysoev <igor@sysoev.ru>
parents:
69
diff
changeset
|
211 ngx_http_log_commands, /* module directives */ |
a059e1aa65d4
nginx-0.0.1-2003-06-02-19:24:30 import
Igor Sysoev <igor@sysoev.ru>
parents:
69
diff
changeset
|
212 NGX_HTTP_MODULE, /* module type */ |
541 | 213 NULL, /* init master */ |
573 | 214 NULL, /* init module */ |
541 | 215 NULL, /* init process */ |
216 NULL, /* init thread */ | |
217 NULL, /* exit thread */ | |
218 NULL, /* exit process */ | |
219 NULL, /* exit master */ | |
220 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
|
221 }; |
a059e1aa65d4
nginx-0.0.1-2003-06-02-19:24:30 import
Igor Sysoev <igor@sysoev.ru>
parents:
69
diff
changeset
|
222 |
26
53cb81681040
nginx-0.0.1-2002-12-15-09:25:09 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
223 |
1074 | 224 static ngx_str_t ngx_http_access_log = ngx_string(NGX_HTTP_LOG_PATH); |
573 | 225 |
226 | |
227 static ngx_str_t ngx_http_combined_fmt = | |
581 | 228 ngx_string("$remote_addr - $remote_user [$time_local] " |
577 | 229 "\"$request\" $status $body_bytes_sent " |
573 | 230 "\"$http_referer\" \"$http_user_agent\""); |
119
cd54bcbaf3b5
nginx-0.0.1-2003-07-21-01:15:59 import
Igor Sysoev <igor@sysoev.ru>
parents:
116
diff
changeset
|
231 |
26
53cb81681040
nginx-0.0.1-2002-12-15-09:25:09 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
232 |
573 | 233 static ngx_http_log_var_t ngx_http_log_vars[] = { |
234 { ngx_string("pipe"), 1, ngx_http_log_pipe }, | |
581 | 235 { ngx_string("time_local"), sizeof("28/Sep/1970:12:00:00 +0600") - 1, |
573 | 236 ngx_http_log_time }, |
3873 | 237 { ngx_string("time_iso8601"), sizeof("1970-09-28T12:00:00+06:00") - 1, |
238 ngx_http_log_iso8601 }, | |
573 | 239 { ngx_string("msec"), NGX_TIME_T_LEN + 4, ngx_http_log_msec }, |
1179
6e2216ad2c87
$request_time has millisecond precision
Igor Sysoev <igor@sysoev.ru>
parents:
1161
diff
changeset
|
240 { ngx_string("request_time"), NGX_TIME_T_LEN + 4, |
6e2216ad2c87
$request_time has millisecond precision
Igor Sysoev <igor@sysoev.ru>
parents:
1161
diff
changeset
|
241 ngx_http_log_request_time }, |
4637
668ab1a21327
Zero padded the returned and logged HTTP status code, and fixed possible
Ruslan Ermilov <ru@nginx.com>
parents:
4539
diff
changeset
|
242 { ngx_string("status"), NGX_INT_T_LEN, ngx_http_log_status }, |
573 | 243 { ngx_string("bytes_sent"), NGX_OFF_T_LEN, ngx_http_log_bytes_sent }, |
577 | 244 { ngx_string("body_bytes_sent"), NGX_OFF_T_LEN, |
245 ngx_http_log_body_bytes_sent }, | |
573 | 246 { ngx_string("request_length"), NGX_SIZE_T_LEN, |
247 ngx_http_log_request_length }, | |
248 | |
249 { ngx_null_string, 0, NULL } | |
250 }; | |
176
c0552e5ab567
nginx-0.0.1-2003-11-09-23:03:38 import; separate building
Igor Sysoev <igor@sysoev.ru>
parents:
119
diff
changeset
|
251 |
c0552e5ab567
nginx-0.0.1-2003-11-09-23:03:38 import; separate building
Igor Sysoev <igor@sysoev.ru>
parents:
119
diff
changeset
|
252 |
4759
4c36e15651f7
Fixed compilation with -Wmissing-prototypes.
Ruslan Ermilov <ru@nginx.com>
parents:
4685
diff
changeset
|
253 static ngx_int_t |
497 | 254 ngx_http_log_handler(ngx_http_request_t *r) |
26
53cb81681040
nginx-0.0.1-2002-12-15-09:25:09 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
255 { |
290
87e73f067470
nginx-0.0.2-2004-03-16-10:10:12 import
Igor Sysoev <igor@sysoev.ru>
parents:
282
diff
changeset
|
256 u_char *line, *p; |
9224
c7c8354f99fa
Syslog: fixed duplicate errors with access logging to syslog.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7223
diff
changeset
|
257 size_t len; |
5653
cb308813b453
Access log: the "if" parameter of the "access_log" directive.
Sergey Kandaurov <pluknet@nginx.com>
parents:
5361
diff
changeset
|
258 ngx_str_t val; |
1071
bd4202f92581
log a failure of the writing to access_log once per minute
Igor Sysoev <igor@sysoev.ru>
parents:
905
diff
changeset
|
259 ngx_uint_t i, 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
|
260 ngx_http_log_t *log; |
c0552e5ab567
nginx-0.0.1-2003-11-09-23:03:38 import; separate building
Igor Sysoev <igor@sysoev.ru>
parents:
119
diff
changeset
|
261 ngx_http_log_op_t *op; |
4985
a0599b56e748
Reopening log files code moved to a separate function.
Valentin Bartenev <vbart@nginx.com>
parents:
4984
diff
changeset
|
262 ngx_http_log_buf_t *buffer; |
176
c0552e5ab567
nginx-0.0.1-2003-11-09-23:03:38 import; separate building
Igor Sysoev <igor@sysoev.ru>
parents:
119
diff
changeset
|
263 ngx_http_log_loc_conf_t *lcf; |
26
53cb81681040
nginx-0.0.1-2002-12-15-09:25:09 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
264 |
210
00cafae0bdf1
nginx-0.0.1-2003-12-14-23:10:27 import
Igor Sysoev <igor@sysoev.ru>
parents:
208
diff
changeset
|
265 ngx_log_debug0(NGX_LOG_DEBUG_HTTP, r->connection->log, 0, |
00cafae0bdf1
nginx-0.0.1-2003-12-14-23:10:27 import
Igor Sysoev <igor@sysoev.ru>
parents:
208
diff
changeset
|
266 "http log handler"); |
28
a117a7fdf042
nginx-0.0.1-2002-12-16-00:08:04 import
Igor Sysoev <igor@sysoev.ru>
parents:
26
diff
changeset
|
267 |
99
a059e1aa65d4
nginx-0.0.1-2003-06-02-19:24:30 import
Igor Sysoev <igor@sysoev.ru>
parents:
69
diff
changeset
|
268 lcf = ngx_http_get_module_loc_conf(r, ngx_http_log_module); |
a059e1aa65d4
nginx-0.0.1-2003-06-02-19:24:30 import
Igor Sysoev <igor@sysoev.ru>
parents:
69
diff
changeset
|
269 |
427
0d08eabe5c7b
nginx-0.0.10-2004-09-15-20:00:43 import
Igor Sysoev <igor@sysoev.ru>
parents:
415
diff
changeset
|
270 if (lcf->off) { |
0d08eabe5c7b
nginx-0.0.10-2004-09-15-20:00:43 import
Igor Sysoev <igor@sysoev.ru>
parents:
415
diff
changeset
|
271 return NGX_OK; |
0d08eabe5c7b
nginx-0.0.10-2004-09-15-20:00:43 import
Igor Sysoev <igor@sysoev.ru>
parents:
415
diff
changeset
|
272 } |
0d08eabe5c7b
nginx-0.0.10-2004-09-15-20:00:43 import
Igor Sysoev <igor@sysoev.ru>
parents:
415
diff
changeset
|
273 |
176
c0552e5ab567
nginx-0.0.1-2003-11-09-23:03:38 import; separate building
Igor Sysoev <igor@sysoev.ru>
parents:
119
diff
changeset
|
274 log = lcf->logs->elts; |
c0552e5ab567
nginx-0.0.1-2003-11-09-23:03:38 import; separate building
Igor Sysoev <igor@sysoev.ru>
parents:
119
diff
changeset
|
275 for (l = 0; l < lcf->logs->nelts; l++) { |
c0552e5ab567
nginx-0.0.1-2003-11-09-23:03:38 import; separate building
Igor Sysoev <igor@sysoev.ru>
parents:
119
diff
changeset
|
276 |
5653
cb308813b453
Access log: the "if" parameter of the "access_log" directive.
Sergey Kandaurov <pluknet@nginx.com>
parents:
5361
diff
changeset
|
277 if (log[l].filter) { |
cb308813b453
Access log: the "if" parameter of the "access_log" directive.
Sergey Kandaurov <pluknet@nginx.com>
parents:
5361
diff
changeset
|
278 if (ngx_http_complex_value(r, log[l].filter, &val) != NGX_OK) { |
cb308813b453
Access log: the "if" parameter of the "access_log" directive.
Sergey Kandaurov <pluknet@nginx.com>
parents:
5361
diff
changeset
|
279 return NGX_ERROR; |
cb308813b453
Access log: the "if" parameter of the "access_log" directive.
Sergey Kandaurov <pluknet@nginx.com>
parents:
5361
diff
changeset
|
280 } |
cb308813b453
Access log: the "if" parameter of the "access_log" directive.
Sergey Kandaurov <pluknet@nginx.com>
parents:
5361
diff
changeset
|
281 |
cb308813b453
Access log: the "if" parameter of the "access_log" directive.
Sergey Kandaurov <pluknet@nginx.com>
parents:
5361
diff
changeset
|
282 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
|
283 continue; |
cb308813b453
Access log: the "if" parameter of the "access_log" directive.
Sergey Kandaurov <pluknet@nginx.com>
parents:
5361
diff
changeset
|
284 } |
cb308813b453
Access log: the "if" parameter of the "access_log" directive.
Sergey Kandaurov <pluknet@nginx.com>
parents:
5361
diff
changeset
|
285 } |
cb308813b453
Access log: the "if" parameter of the "access_log" directive.
Sergey Kandaurov <pluknet@nginx.com>
parents:
5361
diff
changeset
|
286 |
633 | 287 if (ngx_time() == log[l].disk_full_time) { |
288 | |
289 /* | |
1071
bd4202f92581
log a failure of the writing to access_log once per minute
Igor Sysoev <igor@sysoev.ru>
parents:
905
diff
changeset
|
290 * on FreeBSD writing to a full filesystem with enabled softupdates |
633 | 291 * 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
|
292 * filesystem, so we skip writing to a log for one second |
633 | 293 */ |
294 | |
295 continue; | |
296 } | |
297 | |
2261 | 298 ngx_http_script_flush_no_cacheable_variables(r, log[l].format->flushes); |
299 | |
176
c0552e5ab567
nginx-0.0.1-2003-11-09-23:03:38 import; separate building
Igor Sysoev <igor@sysoev.ru>
parents:
119
diff
changeset
|
300 len = 0; |
2261 | 301 op = log[l].format->ops->elts; |
302 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
|
303 if (op[i].len == 0) { |
479 | 304 len += op[i].getlen(r, 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
|
305 |
c0552e5ab567
nginx-0.0.1-2003-11-09-23:03:38 import; separate building
Igor Sysoev <igor@sysoev.ru>
parents:
119
diff
changeset
|
306 } else { |
c0552e5ab567
nginx-0.0.1-2003-11-09-23:03:38 import; separate building
Igor Sysoev <igor@sysoev.ru>
parents:
119
diff
changeset
|
307 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
|
308 } |
c0552e5ab567
nginx-0.0.1-2003-11-09-23:03:38 import; separate building
Igor Sysoev <igor@sysoev.ru>
parents:
119
diff
changeset
|
309 } |
c0552e5ab567
nginx-0.0.1-2003-11-09-23:03:38 import; separate building
Igor Sysoev <igor@sysoev.ru>
parents:
119
diff
changeset
|
310 |
5702
777202558122
Added syslog support for error_log and access_log directives.
Vladimir Homutov <vl@nginx.com>
parents:
5653
diff
changeset
|
311 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
|
312 |
777202558122
Added syslog support for error_log and access_log directives.
Vladimir Homutov <vl@nginx.com>
parents:
5653
diff
changeset
|
313 /* 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
|
314 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
|
315 + 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
|
316 + 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
|
317 |
777202558122
Added syslog support for error_log and access_log directives.
Vladimir Homutov <vl@nginx.com>
parents:
5653
diff
changeset
|
318 goto alloc_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 |
571 | 321 len += NGX_LINEFEED_SIZE; |
322 | |
4985
a0599b56e748
Reopening log files code moved to a separate function.
Valentin Bartenev <vbart@nginx.com>
parents:
4984
diff
changeset
|
323 buffer = log[l].file ? log[l].file->data : NULL; |
571 | 324 |
4985
a0599b56e748
Reopening log files code moved to a separate function.
Valentin Bartenev <vbart@nginx.com>
parents:
4984
diff
changeset
|
325 if (buffer) { |
571 | 326 |
4985
a0599b56e748
Reopening log files code moved to a separate function.
Valentin Bartenev <vbart@nginx.com>
parents:
4984
diff
changeset
|
327 if (len > (size_t) (buffer->last - buffer->pos)) { |
571 | 328 |
4985
a0599b56e748
Reopening log files code moved to a separate function.
Valentin Bartenev <vbart@nginx.com>
parents:
4984
diff
changeset
|
329 ngx_http_log_write(r, &log[l], buffer->start, |
a0599b56e748
Reopening log files code moved to a separate function.
Valentin Bartenev <vbart@nginx.com>
parents:
4984
diff
changeset
|
330 buffer->pos - buffer->start); |
571 | 331 |
4985
a0599b56e748
Reopening log files code moved to a separate function.
Valentin Bartenev <vbart@nginx.com>
parents:
4984
diff
changeset
|
332 buffer->pos = buffer->start; |
571 | 333 } |
334 | |
4985
a0599b56e748
Reopening log files code moved to a separate function.
Valentin Bartenev <vbart@nginx.com>
parents:
4984
diff
changeset
|
335 if (len <= (size_t) (buffer->last - buffer->pos)) { |
571 | 336 |
4985
a0599b56e748
Reopening log files code moved to a separate function.
Valentin Bartenev <vbart@nginx.com>
parents:
4984
diff
changeset
|
337 p = buffer->pos; |
571 | 338 |
4986
3efc49b156d9
Access log: the "flush" parameter of the "access_log" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4985
diff
changeset
|
339 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
|
340 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
|
341 } |
3efc49b156d9
Access log: the "flush" parameter of the "access_log" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4985
diff
changeset
|
342 |
2261 | 343 for (i = 0; i < log[l].format->ops->nelts; i++) { |
571 | 344 p = op[i].run(r, p, &op[i]); |
345 } | |
346 | |
347 ngx_linefeed(p); | |
348 | |
4985
a0599b56e748
Reopening log files code moved to a separate function.
Valentin Bartenev <vbart@nginx.com>
parents:
4984
diff
changeset
|
349 buffer->pos = p; |
571 | 350 |
351 continue; | |
352 } | |
4986
3efc49b156d9
Access log: the "flush" parameter of the "access_log" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4985
diff
changeset
|
353 |
3efc49b156d9
Access log: the "flush" parameter of the "access_log" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4985
diff
changeset
|
354 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
|
355 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
|
356 } |
571 | 357 } |
26
53cb81681040
nginx-0.0.1-2002-12-15-09:25:09 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
358 |
5702
777202558122
Added syslog support for error_log and access_log directives.
Vladimir Homutov <vl@nginx.com>
parents:
5653
diff
changeset
|
359 alloc_line: |
777202558122
Added syslog support for error_log and access_log directives.
Vladimir Homutov <vl@nginx.com>
parents:
5653
diff
changeset
|
360 |
2049 | 361 line = ngx_pnalloc(r->pool, len); |
501 | 362 if (line == NULL) { |
473 | 363 return NGX_ERROR; |
364 } | |
365 | |
176
c0552e5ab567
nginx-0.0.1-2003-11-09-23:03:38 import; separate building
Igor Sysoev <igor@sysoev.ru>
parents:
119
diff
changeset
|
366 p = line; |
26
53cb81681040
nginx-0.0.1-2002-12-15-09:25:09 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
367 |
5702
777202558122
Added syslog support for error_log and access_log directives.
Vladimir Homutov <vl@nginx.com>
parents:
5653
diff
changeset
|
368 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
|
369 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
|
370 } |
777202558122
Added syslog support for error_log and access_log directives.
Vladimir Homutov <vl@nginx.com>
parents:
5653
diff
changeset
|
371 |
2261 | 372 for (i = 0; i < log[l].format->ops->nelts; i++) { |
479 | 373 p = op[i].run(r, 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
|
374 } |
99
a059e1aa65d4
nginx-0.0.1-2003-06-02-19:24:30 import
Igor Sysoev <igor@sysoev.ru>
parents:
69
diff
changeset
|
375 |
5702
777202558122
Added syslog support for error_log and access_log directives.
Vladimir Homutov <vl@nginx.com>
parents:
5653
diff
changeset
|
376 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
|
377 |
9224
c7c8354f99fa
Syslog: fixed duplicate errors with access logging to syslog.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7223
diff
changeset
|
378 (void) ngx_syslog_send(log[l].syslog_peer, line, p - line); |
5702
777202558122
Added syslog support for error_log and access_log directives.
Vladimir Homutov <vl@nginx.com>
parents:
5653
diff
changeset
|
379 |
777202558122
Added syslog support for error_log and access_log directives.
Vladimir Homutov <vl@nginx.com>
parents:
5653
diff
changeset
|
380 continue; |
777202558122
Added syslog support for error_log and access_log directives.
Vladimir Homutov <vl@nginx.com>
parents:
5653
diff
changeset
|
381 } |
777202558122
Added syslog support for error_log and access_log directives.
Vladimir Homutov <vl@nginx.com>
parents:
5653
diff
changeset
|
382 |
571 | 383 ngx_linefeed(p); |
384 | |
1071
bd4202f92581
log a failure of the writing to access_log once per minute
Igor Sysoev <igor@sysoev.ru>
parents:
905
diff
changeset
|
385 ngx_http_log_write(r, &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
|
386 } |
26
53cb81681040
nginx-0.0.1-2002-12-15-09:25:09 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
387 |
53cb81681040
nginx-0.0.1-2002-12-15-09:25:09 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
388 return NGX_OK; |
53cb81681040
nginx-0.0.1-2002-12-15-09:25:09 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
389 } |
99
a059e1aa65d4
nginx-0.0.1-2003-06-02-19:24:30 import
Igor Sysoev <igor@sysoev.ru>
parents:
69
diff
changeset
|
390 |
a059e1aa65d4
nginx-0.0.1-2003-06-02-19:24:30 import
Igor Sysoev <igor@sysoev.ru>
parents:
69
diff
changeset
|
391 |
1071
bd4202f92581
log a failure of the writing to access_log once per minute
Igor Sysoev <igor@sysoev.ru>
parents:
905
diff
changeset
|
392 static void |
bd4202f92581
log a failure of the writing to access_log once per minute
Igor Sysoev <igor@sysoev.ru>
parents:
905
diff
changeset
|
393 ngx_http_log_write(ngx_http_request_t *r, ngx_http_log_t *log, u_char *buf, |
bd4202f92581
log a failure of the writing to access_log once per minute
Igor Sysoev <igor@sysoev.ru>
parents:
905
diff
changeset
|
394 size_t len) |
bd4202f92581
log a failure of the writing to access_log once per minute
Igor Sysoev <igor@sysoev.ru>
parents:
905
diff
changeset
|
395 { |
4988
3849bb380605
Access log: the "gzip" parameter of the "access_log" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4986
diff
changeset
|
396 u_char *name; |
3849bb380605
Access log: the "gzip" parameter of the "access_log" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4986
diff
changeset
|
397 time_t now; |
3849bb380605
Access log: the "gzip" parameter of the "access_log" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4986
diff
changeset
|
398 ssize_t n; |
3849bb380605
Access log: the "gzip" parameter of the "access_log" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4986
diff
changeset
|
399 ngx_err_t err; |
3849bb380605
Access log: the "gzip" parameter of the "access_log" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4986
diff
changeset
|
400 #if (NGX_ZLIB) |
3849bb380605
Access log: the "gzip" parameter of the "access_log" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4986
diff
changeset
|
401 ngx_http_log_buf_t *buffer; |
3849bb380605
Access log: the "gzip" parameter of the "access_log" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4986
diff
changeset
|
402 #endif |
1071
bd4202f92581
log a failure of the writing to access_log once per minute
Igor Sysoev <igor@sysoev.ru>
parents:
905
diff
changeset
|
403 |
2072 | 404 if (log->script == NULL) { |
405 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
|
406 |
3849bb380605
Access log: the "gzip" parameter of the "access_log" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4986
diff
changeset
|
407 #if (NGX_ZLIB) |
3849bb380605
Access log: the "gzip" parameter of the "access_log" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4986
diff
changeset
|
408 buffer = log->file->data; |
3849bb380605
Access log: the "gzip" parameter of the "access_log" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4986
diff
changeset
|
409 |
3849bb380605
Access log: the "gzip" parameter of the "access_log" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4986
diff
changeset
|
410 if (buffer && buffer->gzip) { |
3849bb380605
Access log: the "gzip" parameter of the "access_log" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4986
diff
changeset
|
411 n = ngx_http_log_gzip(log->file->fd, buf, len, buffer->gzip, |
3849bb380605
Access log: the "gzip" parameter of the "access_log" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4986
diff
changeset
|
412 r->connection->log); |
3849bb380605
Access log: the "gzip" parameter of the "access_log" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4986
diff
changeset
|
413 } else { |
3849bb380605
Access log: the "gzip" parameter of the "access_log" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4986
diff
changeset
|
414 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
|
415 } |
3849bb380605
Access log: the "gzip" parameter of the "access_log" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4986
diff
changeset
|
416 #else |
2072 | 417 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
|
418 #endif |
2072 | 419 |
420 } else { | |
421 name = NULL; | |
422 n = ngx_http_log_script_write(r, log->script, &name, buf, len); | |
423 } | |
1071
bd4202f92581
log a failure of the writing to access_log once per minute
Igor Sysoev <igor@sysoev.ru>
parents:
905
diff
changeset
|
424 |
bd4202f92581
log a failure of the writing to access_log once per minute
Igor Sysoev <igor@sysoev.ru>
parents:
905
diff
changeset
|
425 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
|
426 return; |
bd4202f92581
log a failure of the writing to access_log once per minute
Igor Sysoev <igor@sysoev.ru>
parents:
905
diff
changeset
|
427 } |
bd4202f92581
log a failure of the writing to access_log once per minute
Igor Sysoev <igor@sysoev.ru>
parents:
905
diff
changeset
|
428 |
bd4202f92581
log a failure of the writing to access_log once per minute
Igor Sysoev <igor@sysoev.ru>
parents:
905
diff
changeset
|
429 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
|
430 |
bd4202f92581
log a failure of the writing to access_log once per minute
Igor Sysoev <igor@sysoev.ru>
parents:
905
diff
changeset
|
431 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
|
432 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
|
433 |
bd4202f92581
log a failure of the writing to access_log once per minute
Igor Sysoev <igor@sysoev.ru>
parents:
905
diff
changeset
|
434 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
|
435 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
|
436 } |
bd4202f92581
log a failure of the writing to access_log once per minute
Igor Sysoev <igor@sysoev.ru>
parents:
905
diff
changeset
|
437 |
1161
6002e0253221
use 60 seconds interval but not 61 seconds
Igor Sysoev <igor@sysoev.ru>
parents:
1074
diff
changeset
|
438 if (now - log->error_log_time > 59) { |
1071
bd4202f92581
log a failure of the writing to access_log once per minute
Igor Sysoev <igor@sysoev.ru>
parents:
905
diff
changeset
|
439 ngx_log_error(NGX_LOG_ALERT, r->connection->log, err, |
2072 | 440 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
|
441 |
bd4202f92581
log a failure of the writing to access_log once per minute
Igor Sysoev <igor@sysoev.ru>
parents:
905
diff
changeset
|
442 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
|
443 } |
bd4202f92581
log a failure of the writing to access_log once per minute
Igor Sysoev <igor@sysoev.ru>
parents:
905
diff
changeset
|
444 |
bd4202f92581
log a failure of the writing to access_log once per minute
Igor Sysoev <igor@sysoev.ru>
parents:
905
diff
changeset
|
445 return; |
bd4202f92581
log a failure of the writing to access_log once per minute
Igor Sysoev <igor@sysoev.ru>
parents:
905
diff
changeset
|
446 } |
bd4202f92581
log a failure of the writing to access_log once per minute
Igor Sysoev <igor@sysoev.ru>
parents:
905
diff
changeset
|
447 |
1161
6002e0253221
use 60 seconds interval but not 61 seconds
Igor Sysoev <igor@sysoev.ru>
parents:
1074
diff
changeset
|
448 if (now - log->error_log_time > 59) { |
1071
bd4202f92581
log a failure of the writing to access_log once per minute
Igor Sysoev <igor@sysoev.ru>
parents:
905
diff
changeset
|
449 ngx_log_error(NGX_LOG_ALERT, r->connection->log, 0, |
2072 | 450 ngx_write_fd_n " to \"%s\" was incomplete: %z of %uz", |
451 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
|
452 |
bd4202f92581
log a failure of the writing to access_log once per minute
Igor Sysoev <igor@sysoev.ru>
parents:
905
diff
changeset
|
453 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
|
454 } |
bd4202f92581
log a failure of the writing to access_log once per minute
Igor Sysoev <igor@sysoev.ru>
parents:
905
diff
changeset
|
455 } |
bd4202f92581
log a failure of the writing to access_log once per minute
Igor Sysoev <igor@sysoev.ru>
parents:
905
diff
changeset
|
456 |
bd4202f92581
log a failure of the writing to access_log once per minute
Igor Sysoev <igor@sysoev.ru>
parents:
905
diff
changeset
|
457 |
2072 | 458 static ssize_t |
459 ngx_http_log_script_write(ngx_http_request_t *r, ngx_http_log_script_t *script, | |
460 u_char **name, u_char *buf, size_t len) | |
461 { | |
462 size_t root; | |
463 ssize_t n; | |
464 ngx_str_t log, path; | |
465 ngx_open_file_info_t of; | |
466 ngx_http_log_loc_conf_t *llcf; | |
467 ngx_http_core_loc_conf_t *clcf; | |
468 | |
4478
08713bac87fc
Support for disable_symlinks in various modules.
Andrey Belov <defan@nginx.com>
parents:
4474
diff
changeset
|
469 clcf = ngx_http_get_module_loc_conf(r, ngx_http_core_module); |
08713bac87fc
Support for disable_symlinks in various modules.
Andrey Belov <defan@nginx.com>
parents:
4474
diff
changeset
|
470 |
2087
c8039b26a949
always test root existence for access_log with variables
Igor Sysoev <igor@sysoev.ru>
parents:
2080
diff
changeset
|
471 if (!r->root_tested) { |
2072 | 472 |
4499
778ef9c3fd2d
Fixed spelling in single-line comments.
Ruslan Ermilov <ru@nginx.com>
parents:
4494
diff
changeset
|
473 /* test root directory existence */ |
2072 | 474 |
475 if (ngx_http_map_uri_to_path(r, &path, &root, 0) == NULL) { | |
4499
778ef9c3fd2d
Fixed spelling in single-line comments.
Ruslan Ermilov <ru@nginx.com>
parents:
4494
diff
changeset
|
476 /* simulate successful logging */ |
2072 | 477 return len; |
478 } | |
479 | |
480 path.data[root] = '\0'; | |
481 | |
482 ngx_memzero(&of, sizeof(ngx_open_file_info_t)); | |
483 | |
484 of.valid = clcf->open_file_cache_valid; | |
485 of.min_uses = clcf->open_file_cache_min_uses; | |
2756
09cab3f8d92e
*) of.test_only to not open file if only stat() is enough
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
486 of.test_dir = 1; |
09cab3f8d92e
*) of.test_only to not open file if only stat() is enough
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
487 of.test_only = 1; |
2072 | 488 of.errors = clcf->open_file_cache_errors; |
489 of.events = clcf->open_file_cache_events; | |
4494
13e09cf11d4e
Disable symlinks: initialization of the "disable_symlinks" field in
Valentin Bartenev <vbart@nginx.com>
parents:
4478
diff
changeset
|
490 |
13e09cf11d4e
Disable symlinks: initialization of the "disable_symlinks" field in
Valentin Bartenev <vbart@nginx.com>
parents:
4478
diff
changeset
|
491 if (ngx_http_set_disable_symlinks(r, clcf, &path, &of) != NGX_OK) { |
13e09cf11d4e
Disable symlinks: initialization of the "disable_symlinks" field in
Valentin Bartenev <vbart@nginx.com>
parents:
4478
diff
changeset
|
492 /* simulate successful logging */ |
13e09cf11d4e
Disable symlinks: initialization of the "disable_symlinks" field in
Valentin Bartenev <vbart@nginx.com>
parents:
4478
diff
changeset
|
493 return len; |
13e09cf11d4e
Disable symlinks: initialization of the "disable_symlinks" field in
Valentin Bartenev <vbart@nginx.com>
parents:
4478
diff
changeset
|
494 } |
2072 | 495 |
496 if (ngx_open_cached_file(clcf->open_file_cache, &path, &of, r->pool) | |
2087
c8039b26a949
always test root existence for access_log with variables
Igor Sysoev <igor@sysoev.ru>
parents:
2080
diff
changeset
|
497 != NGX_OK) |
2072 | 498 { |
2087
c8039b26a949
always test root existence for access_log with variables
Igor Sysoev <igor@sysoev.ru>
parents:
2080
diff
changeset
|
499 if (of.err == 0) { |
4499
778ef9c3fd2d
Fixed spelling in single-line comments.
Ruslan Ermilov <ru@nginx.com>
parents:
4494
diff
changeset
|
500 /* simulate successful logging */ |
2087
c8039b26a949
always test root existence for access_log with variables
Igor Sysoev <igor@sysoev.ru>
parents:
2080
diff
changeset
|
501 return len; |
c8039b26a949
always test root existence for access_log with variables
Igor Sysoev <igor@sysoev.ru>
parents:
2080
diff
changeset
|
502 } |
c8039b26a949
always test root existence for access_log with variables
Igor Sysoev <igor@sysoev.ru>
parents:
2080
diff
changeset
|
503 |
c8039b26a949
always test root existence for access_log with variables
Igor Sysoev <igor@sysoev.ru>
parents:
2080
diff
changeset
|
504 ngx_log_error(NGX_LOG_ERR, r->connection->log, of.err, |
c8039b26a949
always test root existence for access_log with variables
Igor Sysoev <igor@sysoev.ru>
parents:
2080
diff
changeset
|
505 "testing \"%s\" existence failed", path.data); |
c8039b26a949
always test root existence for access_log with variables
Igor Sysoev <igor@sysoev.ru>
parents:
2080
diff
changeset
|
506 |
4499
778ef9c3fd2d
Fixed spelling in single-line comments.
Ruslan Ermilov <ru@nginx.com>
parents:
4494
diff
changeset
|
507 /* simulate successful logging */ |
2087
c8039b26a949
always test root existence for access_log with variables
Igor Sysoev <igor@sysoev.ru>
parents:
2080
diff
changeset
|
508 return len; |
c8039b26a949
always test root existence for access_log with variables
Igor Sysoev <igor@sysoev.ru>
parents:
2080
diff
changeset
|
509 } |
c8039b26a949
always test root existence for access_log with variables
Igor Sysoev <igor@sysoev.ru>
parents:
2080
diff
changeset
|
510 |
c8039b26a949
always test root existence for access_log with variables
Igor Sysoev <igor@sysoev.ru>
parents:
2080
diff
changeset
|
511 if (!of.is_dir) { |
c8039b26a949
always test root existence for access_log with variables
Igor Sysoev <igor@sysoev.ru>
parents:
2080
diff
changeset
|
512 ngx_log_error(NGX_LOG_ERR, r->connection->log, NGX_ENOTDIR, |
c8039b26a949
always test root existence for access_log with variables
Igor Sysoev <igor@sysoev.ru>
parents:
2080
diff
changeset
|
513 "testing \"%s\" existence failed", path.data); |
c8039b26a949
always test root existence for access_log with variables
Igor Sysoev <igor@sysoev.ru>
parents:
2080
diff
changeset
|
514 |
4499
778ef9c3fd2d
Fixed spelling in single-line comments.
Ruslan Ermilov <ru@nginx.com>
parents:
4494
diff
changeset
|
515 /* simulate successful logging */ |
2072 | 516 return len; |
517 } | |
518 } | |
519 | |
520 if (ngx_http_script_run(r, &log, script->lengths->elts, 1, | |
521 script->values->elts) | |
522 == NULL) | |
523 { | |
4499
778ef9c3fd2d
Fixed spelling in single-line comments.
Ruslan Ermilov <ru@nginx.com>
parents:
4494
diff
changeset
|
524 /* simulate successful logging */ |
2072 | 525 return len; |
526 } | |
527 | |
528 log.data[log.len - 1] = '\0'; | |
529 *name = log.data; | |
530 | |
531 ngx_log_debug1(NGX_LOG_DEBUG_HTTP, r->connection->log, 0, | |
532 "http log \"%s\"", log.data); | |
533 | |
534 llcf = ngx_http_get_module_loc_conf(r, ngx_http_log_module); | |
535 | |
536 ngx_memzero(&of, sizeof(ngx_open_file_info_t)); | |
537 | |
538 of.log = 1; | |
539 of.valid = llcf->open_file_cache_valid; | |
540 of.min_uses = llcf->open_file_cache_min_uses; | |
2277 | 541 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
|
542 |
13e09cf11d4e
Disable symlinks: initialization of the "disable_symlinks" field in
Valentin Bartenev <vbart@nginx.com>
parents:
4478
diff
changeset
|
543 if (ngx_http_set_disable_symlinks(r, clcf, &log, &of) != NGX_OK) { |
13e09cf11d4e
Disable symlinks: initialization of the "disable_symlinks" field in
Valentin Bartenev <vbart@nginx.com>
parents:
4478
diff
changeset
|
544 /* simulate successful logging */ |
13e09cf11d4e
Disable symlinks: initialization of the "disable_symlinks" field in
Valentin Bartenev <vbart@nginx.com>
parents:
4478
diff
changeset
|
545 return len; |
13e09cf11d4e
Disable symlinks: initialization of the "disable_symlinks" field in
Valentin Bartenev <vbart@nginx.com>
parents:
4478
diff
changeset
|
546 } |
2072 | 547 |
548 if (ngx_open_cached_file(llcf->open_file_cache, &log, &of, r->pool) | |
549 != NGX_OK) | |
550 { | |
6948
3fb9b5eb75c0
Fixed ngx_open_cached_file() error handling.
Sergey Kandaurov <pluknet@nginx.com>
parents:
6927
diff
changeset
|
551 if (of.err == 0) { |
3fb9b5eb75c0
Fixed ngx_open_cached_file() error handling.
Sergey Kandaurov <pluknet@nginx.com>
parents:
6927
diff
changeset
|
552 /* simulate successful logging */ |
3fb9b5eb75c0
Fixed ngx_open_cached_file() error handling.
Sergey Kandaurov <pluknet@nginx.com>
parents:
6927
diff
changeset
|
553 return len; |
3fb9b5eb75c0
Fixed ngx_open_cached_file() error handling.
Sergey Kandaurov <pluknet@nginx.com>
parents:
6927
diff
changeset
|
554 } |
3fb9b5eb75c0
Fixed ngx_open_cached_file() error handling.
Sergey Kandaurov <pluknet@nginx.com>
parents:
6927
diff
changeset
|
555 |
2072 | 556 ngx_log_error(NGX_LOG_CRIT, r->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
|
557 "%s \"%s\" failed", of.failed, log.data); |
4499
778ef9c3fd2d
Fixed spelling in single-line comments.
Ruslan Ermilov <ru@nginx.com>
parents:
4494
diff
changeset
|
558 /* simulate successful logging */ |
2077 | 559 return len; |
2072 | 560 } |
561 | |
562 ngx_log_debug1(NGX_LOG_DEBUG_HTTP, r->connection->log, 0, | |
563 "http log #%d", of.fd); | |
564 | |
565 n = ngx_write_fd(of.fd, buf, len); | |
566 | |
567 return n; | |
568 } | |
569 | |
570 | |
4988
3849bb380605
Access log: the "gzip" parameter of the "access_log" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4986
diff
changeset
|
571 #if (NGX_ZLIB) |
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 static ssize_t |
3849bb380605
Access log: the "gzip" parameter of the "access_log" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4986
diff
changeset
|
574 ngx_http_log_gzip(ngx_fd_t fd, u_char *buf, size_t len, ngx_int_t level, |
3849bb380605
Access log: the "gzip" parameter of the "access_log" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4986
diff
changeset
|
575 ngx_log_t *log) |
3849bb380605
Access log: the "gzip" parameter of the "access_log" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4986
diff
changeset
|
576 { |
3849bb380605
Access log: the "gzip" parameter of the "access_log" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4986
diff
changeset
|
577 int rc, wbits, memlevel; |
3849bb380605
Access log: the "gzip" parameter of the "access_log" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4986
diff
changeset
|
578 u_char *out; |
3849bb380605
Access log: the "gzip" parameter of the "access_log" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4986
diff
changeset
|
579 size_t size; |
3849bb380605
Access log: the "gzip" parameter of the "access_log" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4986
diff
changeset
|
580 ssize_t n; |
3849bb380605
Access log: the "gzip" parameter of the "access_log" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4986
diff
changeset
|
581 z_stream zstream; |
3849bb380605
Access log: the "gzip" parameter of the "access_log" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4986
diff
changeset
|
582 ngx_err_t err; |
3849bb380605
Access log: the "gzip" parameter of the "access_log" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4986
diff
changeset
|
583 ngx_pool_t *pool; |
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 wbits = MAX_WBITS; |
3849bb380605
Access log: the "gzip" parameter of the "access_log" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4986
diff
changeset
|
586 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
|
587 |
3849bb380605
Access log: the "gzip" parameter of the "access_log" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4986
diff
changeset
|
588 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
|
589 wbits--; |
3849bb380605
Access log: the "gzip" parameter of the "access_log" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4986
diff
changeset
|
590 memlevel--; |
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 /* |
3849bb380605
Access log: the "gzip" parameter of the "access_log" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4986
diff
changeset
|
594 * 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
|
595 * 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
|
596 */ |
3849bb380605
Access log: the "gzip" parameter of the "access_log" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4986
diff
changeset
|
597 |
3849bb380605
Access log: the "gzip" parameter of the "access_log" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4986
diff
changeset
|
598 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
|
599 |
3849bb380605
Access log: the "gzip" parameter of the "access_log" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4986
diff
changeset
|
600 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
|
601 |
3849bb380605
Access log: the "gzip" parameter of the "access_log" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4986
diff
changeset
|
602 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
|
603 if (pool == NULL) { |
3849bb380605
Access log: the "gzip" parameter of the "access_log" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4986
diff
changeset
|
604 /* simulate successful logging */ |
3849bb380605
Access log: the "gzip" parameter of the "access_log" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4986
diff
changeset
|
605 return len; |
3849bb380605
Access log: the "gzip" parameter of the "access_log" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4986
diff
changeset
|
606 } |
3849bb380605
Access log: the "gzip" parameter of the "access_log" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4986
diff
changeset
|
607 |
3849bb380605
Access log: the "gzip" parameter of the "access_log" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4986
diff
changeset
|
608 pool->log = log; |
3849bb380605
Access log: the "gzip" parameter of the "access_log" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4986
diff
changeset
|
609 |
3849bb380605
Access log: the "gzip" parameter of the "access_log" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4986
diff
changeset
|
610 zstream.zalloc = ngx_http_log_gzip_alloc; |
3849bb380605
Access log: the "gzip" parameter of the "access_log" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4986
diff
changeset
|
611 zstream.zfree = ngx_http_log_gzip_free; |
3849bb380605
Access log: the "gzip" parameter of the "access_log" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4986
diff
changeset
|
612 zstream.opaque = pool; |
3849bb380605
Access log: the "gzip" parameter of the "access_log" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4986
diff
changeset
|
613 |
3849bb380605
Access log: the "gzip" parameter of the "access_log" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4986
diff
changeset
|
614 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
|
615 if (out == NULL) { |
3849bb380605
Access log: the "gzip" parameter of the "access_log" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4986
diff
changeset
|
616 goto done; |
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 |
3849bb380605
Access log: the "gzip" parameter of the "access_log" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4986
diff
changeset
|
619 zstream.next_in = buf; |
3849bb380605
Access log: the "gzip" parameter of the "access_log" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4986
diff
changeset
|
620 zstream.avail_in = len; |
3849bb380605
Access log: the "gzip" parameter of the "access_log" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4986
diff
changeset
|
621 zstream.next_out = out; |
3849bb380605
Access log: the "gzip" parameter of the "access_log" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4986
diff
changeset
|
622 zstream.avail_out = size; |
3849bb380605
Access log: the "gzip" parameter of the "access_log" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4986
diff
changeset
|
623 |
3849bb380605
Access log: the "gzip" parameter of the "access_log" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4986
diff
changeset
|
624 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
|
625 Z_DEFAULT_STRATEGY); |
3849bb380605
Access log: the "gzip" parameter of the "access_log" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4986
diff
changeset
|
626 |
3849bb380605
Access log: the "gzip" parameter of the "access_log" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4986
diff
changeset
|
627 if (rc != Z_OK) { |
3849bb380605
Access log: the "gzip" parameter of the "access_log" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4986
diff
changeset
|
628 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
|
629 goto done; |
3849bb380605
Access log: the "gzip" parameter of the "access_log" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4986
diff
changeset
|
630 } |
3849bb380605
Access log: the "gzip" parameter of the "access_log" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4986
diff
changeset
|
631 |
3849bb380605
Access log: the "gzip" parameter of the "access_log" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4986
diff
changeset
|
632 ngx_log_debug4(NGX_LOG_DEBUG_HTTP, log, 0, |
3849bb380605
Access log: the "gzip" parameter of the "access_log" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4986
diff
changeset
|
633 "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
|
634 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
|
635 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
|
636 |
3849bb380605
Access log: the "gzip" parameter of the "access_log" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4986
diff
changeset
|
637 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
|
638 |
3849bb380605
Access log: the "gzip" parameter of the "access_log" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4986
diff
changeset
|
639 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
|
640 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
|
641 "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
|
642 goto done; |
3849bb380605
Access log: the "gzip" parameter of the "access_log" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4986
diff
changeset
|
643 } |
3849bb380605
Access log: the "gzip" parameter of the "access_log" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4986
diff
changeset
|
644 |
3849bb380605
Access log: the "gzip" parameter of the "access_log" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4986
diff
changeset
|
645 ngx_log_debug5(NGX_LOG_DEBUG_HTTP, log, 0, |
3849bb380605
Access log: the "gzip" parameter of the "access_log" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4986
diff
changeset
|
646 "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
|
647 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
|
648 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
|
649 rc); |
3849bb380605
Access log: the "gzip" parameter of the "access_log" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4986
diff
changeset
|
650 |
3849bb380605
Access log: the "gzip" parameter of the "access_log" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4986
diff
changeset
|
651 size -= zstream.avail_out; |
3849bb380605
Access log: the "gzip" parameter of the "access_log" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4986
diff
changeset
|
652 |
3849bb380605
Access log: the "gzip" parameter of the "access_log" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4986
diff
changeset
|
653 rc = deflateEnd(&zstream); |
3849bb380605
Access log: the "gzip" parameter of the "access_log" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4986
diff
changeset
|
654 |
3849bb380605
Access log: the "gzip" parameter of the "access_log" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4986
diff
changeset
|
655 if (rc != Z_OK) { |
3849bb380605
Access log: the "gzip" parameter of the "access_log" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4986
diff
changeset
|
656 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
|
657 goto done; |
3849bb380605
Access log: the "gzip" parameter of the "access_log" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4986
diff
changeset
|
658 } |
3849bb380605
Access log: the "gzip" parameter of the "access_log" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4986
diff
changeset
|
659 |
3849bb380605
Access log: the "gzip" parameter of the "access_log" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4986
diff
changeset
|
660 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
|
661 |
3849bb380605
Access log: the "gzip" parameter of the "access_log" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4986
diff
changeset
|
662 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
|
663 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
|
664 |
3849bb380605
Access log: the "gzip" parameter of the "access_log" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4986
diff
changeset
|
665 ngx_destroy_pool(pool); |
3849bb380605
Access log: the "gzip" parameter of the "access_log" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4986
diff
changeset
|
666 |
3849bb380605
Access log: the "gzip" parameter of the "access_log" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4986
diff
changeset
|
667 ngx_set_errno(err); |
3849bb380605
Access log: the "gzip" parameter of the "access_log" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4986
diff
changeset
|
668 return -1; |
3849bb380605
Access log: the "gzip" parameter of the "access_log" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4986
diff
changeset
|
669 } |
3849bb380605
Access log: the "gzip" parameter of the "access_log" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4986
diff
changeset
|
670 |
3849bb380605
Access log: the "gzip" parameter of the "access_log" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4986
diff
changeset
|
671 done: |
3849bb380605
Access log: the "gzip" parameter of the "access_log" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4986
diff
changeset
|
672 |
3849bb380605
Access log: the "gzip" parameter of the "access_log" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4986
diff
changeset
|
673 ngx_destroy_pool(pool); |
3849bb380605
Access log: the "gzip" parameter of the "access_log" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4986
diff
changeset
|
674 |
3849bb380605
Access log: the "gzip" parameter of the "access_log" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4986
diff
changeset
|
675 /* simulate successful logging */ |
3849bb380605
Access log: the "gzip" parameter of the "access_log" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4986
diff
changeset
|
676 return len; |
3849bb380605
Access log: the "gzip" parameter of the "access_log" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4986
diff
changeset
|
677 } |
3849bb380605
Access log: the "gzip" parameter of the "access_log" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4986
diff
changeset
|
678 |
3849bb380605
Access log: the "gzip" parameter of the "access_log" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4986
diff
changeset
|
679 |
3849bb380605
Access log: the "gzip" parameter of the "access_log" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4986
diff
changeset
|
680 static void * |
3849bb380605
Access log: the "gzip" parameter of the "access_log" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4986
diff
changeset
|
681 ngx_http_log_gzip_alloc(void *opaque, u_int items, u_int size) |
3849bb380605
Access log: the "gzip" parameter of the "access_log" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4986
diff
changeset
|
682 { |
3849bb380605
Access log: the "gzip" parameter of the "access_log" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4986
diff
changeset
|
683 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
|
684 |
3849bb380605
Access log: the "gzip" parameter of the "access_log" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4986
diff
changeset
|
685 ngx_log_debug2(NGX_LOG_DEBUG_HTTP, pool->log, 0, |
3849bb380605
Access log: the "gzip" parameter of the "access_log" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4986
diff
changeset
|
686 "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
|
687 |
3849bb380605
Access log: the "gzip" parameter of the "access_log" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4986
diff
changeset
|
688 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
|
689 } |
3849bb380605
Access log: the "gzip" parameter of the "access_log" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4986
diff
changeset
|
690 |
3849bb380605
Access log: the "gzip" parameter of the "access_log" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4986
diff
changeset
|
691 |
3849bb380605
Access log: the "gzip" parameter of the "access_log" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4986
diff
changeset
|
692 static void |
3849bb380605
Access log: the "gzip" parameter of the "access_log" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4986
diff
changeset
|
693 ngx_http_log_gzip_free(void *opaque, void *address) |
3849bb380605
Access log: the "gzip" parameter of the "access_log" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4986
diff
changeset
|
694 { |
3849bb380605
Access log: the "gzip" parameter of the "access_log" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4986
diff
changeset
|
695 #if 0 |
3849bb380605
Access log: the "gzip" parameter of the "access_log" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4986
diff
changeset
|
696 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
|
697 |
3849bb380605
Access log: the "gzip" parameter of the "access_log" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4986
diff
changeset
|
698 ngx_log_debug1(NGX_LOG_DEBUG_HTTP, pool->log, 0, "gzip free: %p", address); |
3849bb380605
Access log: the "gzip" parameter of the "access_log" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4986
diff
changeset
|
699 #endif |
3849bb380605
Access log: the "gzip" parameter of the "access_log" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4986
diff
changeset
|
700 } |
3849bb380605
Access log: the "gzip" parameter of the "access_log" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4986
diff
changeset
|
701 |
3849bb380605
Access log: the "gzip" parameter of the "access_log" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4986
diff
changeset
|
702 #endif |
3849bb380605
Access log: the "gzip" parameter of the "access_log" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4986
diff
changeset
|
703 |
3849bb380605
Access log: the "gzip" parameter of the "access_log" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4986
diff
changeset
|
704 |
4985
a0599b56e748
Reopening log files code moved to a separate function.
Valentin Bartenev <vbart@nginx.com>
parents:
4984
diff
changeset
|
705 static void |
a0599b56e748
Reopening log files code moved to a separate function.
Valentin Bartenev <vbart@nginx.com>
parents:
4984
diff
changeset
|
706 ngx_http_log_flush(ngx_open_file_t *file, ngx_log_t *log) |
a0599b56e748
Reopening log files code moved to a separate function.
Valentin Bartenev <vbart@nginx.com>
parents:
4984
diff
changeset
|
707 { |
a0599b56e748
Reopening log files code moved to a separate function.
Valentin Bartenev <vbart@nginx.com>
parents:
4984
diff
changeset
|
708 size_t len; |
a0599b56e748
Reopening log files code moved to a separate function.
Valentin Bartenev <vbart@nginx.com>
parents:
4984
diff
changeset
|
709 ssize_t n; |
a0599b56e748
Reopening log files code moved to a separate function.
Valentin Bartenev <vbart@nginx.com>
parents:
4984
diff
changeset
|
710 ngx_http_log_buf_t *buffer; |
a0599b56e748
Reopening log files code moved to a separate function.
Valentin Bartenev <vbart@nginx.com>
parents:
4984
diff
changeset
|
711 |
a0599b56e748
Reopening log files code moved to a separate function.
Valentin Bartenev <vbart@nginx.com>
parents:
4984
diff
changeset
|
712 buffer = file->data; |
a0599b56e748
Reopening log files code moved to a separate function.
Valentin Bartenev <vbart@nginx.com>
parents:
4984
diff
changeset
|
713 |
a0599b56e748
Reopening log files code moved to a separate function.
Valentin Bartenev <vbart@nginx.com>
parents:
4984
diff
changeset
|
714 len = buffer->pos - buffer->start; |
a0599b56e748
Reopening log files code moved to a separate function.
Valentin Bartenev <vbart@nginx.com>
parents:
4984
diff
changeset
|
715 |
a0599b56e748
Reopening log files code moved to a separate function.
Valentin Bartenev <vbart@nginx.com>
parents:
4984
diff
changeset
|
716 if (len == 0) { |
a0599b56e748
Reopening log files code moved to a separate function.
Valentin Bartenev <vbart@nginx.com>
parents:
4984
diff
changeset
|
717 return; |
a0599b56e748
Reopening log files code moved to a separate function.
Valentin Bartenev <vbart@nginx.com>
parents:
4984
diff
changeset
|
718 } |
a0599b56e748
Reopening log files code moved to a separate function.
Valentin Bartenev <vbart@nginx.com>
parents:
4984
diff
changeset
|
719 |
4988
3849bb380605
Access log: the "gzip" parameter of the "access_log" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4986
diff
changeset
|
720 #if (NGX_ZLIB) |
3849bb380605
Access log: the "gzip" parameter of the "access_log" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4986
diff
changeset
|
721 if (buffer->gzip) { |
3849bb380605
Access log: the "gzip" parameter of the "access_log" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4986
diff
changeset
|
722 n = ngx_http_log_gzip(file->fd, buffer->start, len, buffer->gzip, log); |
3849bb380605
Access log: the "gzip" parameter of the "access_log" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4986
diff
changeset
|
723 } else { |
3849bb380605
Access log: the "gzip" parameter of the "access_log" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4986
diff
changeset
|
724 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
|
725 } |
3849bb380605
Access log: the "gzip" parameter of the "access_log" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4986
diff
changeset
|
726 #else |
4985
a0599b56e748
Reopening log files code moved to a separate function.
Valentin Bartenev <vbart@nginx.com>
parents:
4984
diff
changeset
|
727 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
|
728 #endif |
4985
a0599b56e748
Reopening log files code moved to a separate function.
Valentin Bartenev <vbart@nginx.com>
parents:
4984
diff
changeset
|
729 |
a0599b56e748
Reopening log files code moved to a separate function.
Valentin Bartenev <vbart@nginx.com>
parents:
4984
diff
changeset
|
730 if (n == -1) { |
a0599b56e748
Reopening log files code moved to a separate function.
Valentin Bartenev <vbart@nginx.com>
parents:
4984
diff
changeset
|
731 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
|
732 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
|
733 file->name.data); |
a0599b56e748
Reopening log files code moved to a separate function.
Valentin Bartenev <vbart@nginx.com>
parents:
4984
diff
changeset
|
734 |
a0599b56e748
Reopening log files code moved to a separate function.
Valentin Bartenev <vbart@nginx.com>
parents:
4984
diff
changeset
|
735 } 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
|
736 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
|
737 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
|
738 file->name.data, n, len); |
a0599b56e748
Reopening log files code moved to a separate function.
Valentin Bartenev <vbart@nginx.com>
parents:
4984
diff
changeset
|
739 } |
a0599b56e748
Reopening log files code moved to a separate function.
Valentin Bartenev <vbart@nginx.com>
parents:
4984
diff
changeset
|
740 |
a0599b56e748
Reopening log files code moved to a separate function.
Valentin Bartenev <vbart@nginx.com>
parents:
4984
diff
changeset
|
741 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
|
742 |
3efc49b156d9
Access log: the "flush" parameter of the "access_log" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4985
diff
changeset
|
743 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
|
744 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
|
745 } |
3efc49b156d9
Access log: the "flush" parameter of the "access_log" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4985
diff
changeset
|
746 } |
3efc49b156d9
Access log: the "flush" parameter of the "access_log" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4985
diff
changeset
|
747 |
3efc49b156d9
Access log: the "flush" parameter of the "access_log" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4985
diff
changeset
|
748 |
3efc49b156d9
Access log: the "flush" parameter of the "access_log" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4985
diff
changeset
|
749 static void |
3efc49b156d9
Access log: the "flush" parameter of the "access_log" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4985
diff
changeset
|
750 ngx_http_log_flush_handler(ngx_event_t *ev) |
3efc49b156d9
Access log: the "flush" parameter of the "access_log" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4985
diff
changeset
|
751 { |
3efc49b156d9
Access log: the "flush" parameter of the "access_log" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4985
diff
changeset
|
752 ngx_log_debug0(NGX_LOG_DEBUG_EVENT, ev->log, 0, |
3efc49b156d9
Access log: the "flush" parameter of the "access_log" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4985
diff
changeset
|
753 "http log buffer flush handler"); |
3efc49b156d9
Access log: the "flush" parameter of the "access_log" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4985
diff
changeset
|
754 |
6927
c36d160cd4e0
Access log: removed dead ev->timedout check in flush timer handler.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6840
diff
changeset
|
755 ngx_http_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
|
756 } |
a0599b56e748
Reopening log files code moved to a separate function.
Valentin Bartenev <vbart@nginx.com>
parents:
4984
diff
changeset
|
757 |
a0599b56e748
Reopening log files code moved to a separate function.
Valentin Bartenev <vbart@nginx.com>
parents:
4984
diff
changeset
|
758 |
497 | 759 static u_char * |
760 ngx_http_log_copy_short(ngx_http_request_t *r, u_char *buf, | |
761 ngx_http_log_op_t *op) | |
479 | 762 { |
763 size_t len; | |
764 uintptr_t data; | |
765 | |
766 len = op->len; | |
767 data = op->data; | |
768 | |
769 while (len--) { | |
770 *buf++ = (u_char) (data & 0xff); | |
771 data >>= 8; | |
772 } | |
773 | |
774 return buf; | |
775 } | |
776 | |
777 | |
497 | 778 static u_char * |
779 ngx_http_log_copy_long(ngx_http_request_t *r, u_char *buf, | |
780 ngx_http_log_op_t *op) | |
479 | 781 { |
782 return ngx_cpymem(buf, (u_char *) op->data, op->len); | |
783 } | |
784 | |
785 | |
497 | 786 static u_char * |
787 ngx_http_log_pipe(ngx_http_request_t *r, u_char *buf, ngx_http_log_op_t *op) | |
176
c0552e5ab567
nginx-0.0.1-2003-11-09-23:03:38 import; separate building
Igor Sysoev <igor@sysoev.ru>
parents:
119
diff
changeset
|
788 { |
c0552e5ab567
nginx-0.0.1-2003-11-09-23:03:38 import; separate building
Igor Sysoev <igor@sysoev.ru>
parents:
119
diff
changeset
|
789 if (r->pipeline) { |
c0552e5ab567
nginx-0.0.1-2003-11-09-23:03:38 import; separate building
Igor Sysoev <igor@sysoev.ru>
parents:
119
diff
changeset
|
790 *buf = 'p'; |
c0552e5ab567
nginx-0.0.1-2003-11-09-23:03:38 import; separate building
Igor Sysoev <igor@sysoev.ru>
parents:
119
diff
changeset
|
791 } else { |
c0552e5ab567
nginx-0.0.1-2003-11-09-23:03:38 import; separate building
Igor Sysoev <igor@sysoev.ru>
parents:
119
diff
changeset
|
792 *buf = '.'; |
c0552e5ab567
nginx-0.0.1-2003-11-09-23:03:38 import; separate building
Igor Sysoev <igor@sysoev.ru>
parents:
119
diff
changeset
|
793 } |
c0552e5ab567
nginx-0.0.1-2003-11-09-23:03:38 import; separate building
Igor Sysoev <igor@sysoev.ru>
parents:
119
diff
changeset
|
794 |
c0552e5ab567
nginx-0.0.1-2003-11-09-23:03:38 import; separate building
Igor Sysoev <igor@sysoev.ru>
parents:
119
diff
changeset
|
795 return buf + 1; |
c0552e5ab567
nginx-0.0.1-2003-11-09-23:03:38 import; separate building
Igor Sysoev <igor@sysoev.ru>
parents:
119
diff
changeset
|
796 } |
c0552e5ab567
nginx-0.0.1-2003-11-09-23:03:38 import; separate building
Igor Sysoev <igor@sysoev.ru>
parents:
119
diff
changeset
|
797 |
c0552e5ab567
nginx-0.0.1-2003-11-09-23:03:38 import; separate building
Igor Sysoev <igor@sysoev.ru>
parents:
119
diff
changeset
|
798 |
497 | 799 static u_char * |
800 ngx_http_log_time(ngx_http_request_t *r, u_char *buf, ngx_http_log_op_t *op) | |
176
c0552e5ab567
nginx-0.0.1-2003-11-09-23:03:38 import; separate building
Igor Sysoev <igor@sysoev.ru>
parents:
119
diff
changeset
|
801 { |
178
a8ff48d26cca
nginx-0.0.1-2003-11-11-00:09:22 import
Igor Sysoev <igor@sysoev.ru>
parents:
177
diff
changeset
|
802 return ngx_cpymem(buf, ngx_cached_http_log_time.data, |
a8ff48d26cca
nginx-0.0.1-2003-11-11-00:09:22 import
Igor Sysoev <igor@sysoev.ru>
parents:
177
diff
changeset
|
803 ngx_cached_http_log_time.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
|
804 } |
c0552e5ab567
nginx-0.0.1-2003-11-09-23:03:38 import; separate building
Igor Sysoev <igor@sysoev.ru>
parents:
119
diff
changeset
|
805 |
3873 | 806 static u_char * |
807 ngx_http_log_iso8601(ngx_http_request_t *r, u_char *buf, ngx_http_log_op_t *op) | |
808 { | |
809 return ngx_cpymem(buf, ngx_cached_http_log_iso8601.data, | |
810 ngx_cached_http_log_iso8601.len); | |
811 } | |
176
c0552e5ab567
nginx-0.0.1-2003-11-09-23:03:38 import; separate building
Igor Sysoev <igor@sysoev.ru>
parents:
119
diff
changeset
|
812 |
497 | 813 static u_char * |
814 ngx_http_log_msec(ngx_http_request_t *r, u_char *buf, ngx_http_log_op_t *op) | |
409
8ac40cae79f0
nginx-0.0.10-2004-08-29-07:55:41 import
Igor Sysoev <igor@sysoev.ru>
parents:
393
diff
changeset
|
815 { |
563 | 816 ngx_time_t *tp; |
409
8ac40cae79f0
nginx-0.0.10-2004-08-29-07:55:41 import
Igor Sysoev <igor@sysoev.ru>
parents:
393
diff
changeset
|
817 |
563 | 818 tp = ngx_timeofday(); |
409
8ac40cae79f0
nginx-0.0.10-2004-08-29-07:55:41 import
Igor Sysoev <igor@sysoev.ru>
parents:
393
diff
changeset
|
819 |
563 | 820 return ngx_sprintf(buf, "%T.%03M", tp->sec, tp->msec); |
409
8ac40cae79f0
nginx-0.0.10-2004-08-29-07:55:41 import
Igor Sysoev <igor@sysoev.ru>
parents:
393
diff
changeset
|
821 } |
8ac40cae79f0
nginx-0.0.10-2004-08-29-07:55:41 import
Igor Sysoev <igor@sysoev.ru>
parents:
393
diff
changeset
|
822 |
8ac40cae79f0
nginx-0.0.10-2004-08-29-07:55:41 import
Igor Sysoev <igor@sysoev.ru>
parents:
393
diff
changeset
|
823 |
497 | 824 static u_char * |
825 ngx_http_log_request_time(ngx_http_request_t *r, u_char *buf, | |
826 ngx_http_log_op_t *op) | |
827 { | |
1179
6e2216ad2c87
$request_time has millisecond precision
Igor Sysoev <igor@sysoev.ru>
parents:
1161
diff
changeset
|
828 ngx_time_t *tp; |
6e2216ad2c87
$request_time has millisecond precision
Igor Sysoev <igor@sysoev.ru>
parents:
1161
diff
changeset
|
829 ngx_msec_int_t ms; |
6e2216ad2c87
$request_time has millisecond precision
Igor Sysoev <igor@sysoev.ru>
parents:
1161
diff
changeset
|
830 |
6e2216ad2c87
$request_time has millisecond precision
Igor Sysoev <igor@sysoev.ru>
parents:
1161
diff
changeset
|
831 tp = ngx_timeofday(); |
497 | 832 |
1640 | 833 ms = (ngx_msec_int_t) |
834 ((tp->sec - r->start_sec) * 1000 + (tp->msec - r->start_msec)); | |
3515 | 835 ms = ngx_max(ms, 0); |
497 | 836 |
5361
7094d6da2806
Win32: $request_time fixed.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5330
diff
changeset
|
837 return ngx_sprintf(buf, "%T.%03M", (time_t) ms / 1000, ms % 1000); |
497 | 838 } |
839 | |
840 | |
841 static u_char * | |
842 ngx_http_log_status(ngx_http_request_t *r, u_char *buf, ngx_http_log_op_t *op) | |
176
c0552e5ab567
nginx-0.0.1-2003-11-09-23:03:38 import; separate building
Igor Sysoev <igor@sysoev.ru>
parents:
119
diff
changeset
|
843 { |
3370
bfe37ab335b5
log proxied HTTP/0.9 responses status as "009"
Igor Sysoev <igor@sysoev.ru>
parents:
3275
diff
changeset
|
844 ngx_uint_t status; |
bfe37ab335b5
log proxied HTTP/0.9 responses status as "009"
Igor Sysoev <igor@sysoev.ru>
parents:
3275
diff
changeset
|
845 |
bfe37ab335b5
log proxied HTTP/0.9 responses status as "009"
Igor Sysoev <igor@sysoev.ru>
parents:
3275
diff
changeset
|
846 if (r->err_status) { |
bfe37ab335b5
log proxied HTTP/0.9 responses status as "009"
Igor Sysoev <igor@sysoev.ru>
parents:
3275
diff
changeset
|
847 status = r->err_status; |
bfe37ab335b5
log proxied HTTP/0.9 responses status as "009"
Igor Sysoev <igor@sysoev.ru>
parents:
3275
diff
changeset
|
848 |
bfe37ab335b5
log proxied HTTP/0.9 responses status as "009"
Igor Sysoev <igor@sysoev.ru>
parents:
3275
diff
changeset
|
849 } else if (r->headers_out.status) { |
bfe37ab335b5
log proxied HTTP/0.9 responses status as "009"
Igor Sysoev <igor@sysoev.ru>
parents:
3275
diff
changeset
|
850 status = r->headers_out.status; |
bfe37ab335b5
log proxied HTTP/0.9 responses status as "009"
Igor Sysoev <igor@sysoev.ru>
parents:
3275
diff
changeset
|
851 |
bfe37ab335b5
log proxied HTTP/0.9 responses status as "009"
Igor Sysoev <igor@sysoev.ru>
parents:
3275
diff
changeset
|
852 } else if (r->http_version == NGX_HTTP_VERSION_9) { |
4685
956edecaedeb
New core variable: $status.
Andrey Belov <defan@nginx.com>
parents:
4637
diff
changeset
|
853 status = 9; |
3370
bfe37ab335b5
log proxied HTTP/0.9 responses status as "009"
Igor Sysoev <igor@sysoev.ru>
parents:
3275
diff
changeset
|
854 |
bfe37ab335b5
log proxied HTTP/0.9 responses status as "009"
Igor Sysoev <igor@sysoev.ru>
parents:
3275
diff
changeset
|
855 } else { |
bfe37ab335b5
log proxied HTTP/0.9 responses status as "009"
Igor Sysoev <igor@sysoev.ru>
parents:
3275
diff
changeset
|
856 status = 0; |
bfe37ab335b5
log proxied HTTP/0.9 responses status as "009"
Igor Sysoev <igor@sysoev.ru>
parents:
3275
diff
changeset
|
857 } |
bfe37ab335b5
log proxied HTTP/0.9 responses status as "009"
Igor Sysoev <igor@sysoev.ru>
parents:
3275
diff
changeset
|
858 |
4637
668ab1a21327
Zero padded the returned and logged HTTP status code, and fixed possible
Ruslan Ermilov <ru@nginx.com>
parents:
4539
diff
changeset
|
859 return ngx_sprintf(buf, "%03ui", status); |
176
c0552e5ab567
nginx-0.0.1-2003-11-09-23:03:38 import; separate building
Igor Sysoev <igor@sysoev.ru>
parents:
119
diff
changeset
|
860 } |
c0552e5ab567
nginx-0.0.1-2003-11-09-23:03:38 import; separate building
Igor Sysoev <igor@sysoev.ru>
parents:
119
diff
changeset
|
861 |
c0552e5ab567
nginx-0.0.1-2003-11-09-23:03:38 import; separate building
Igor Sysoev <igor@sysoev.ru>
parents:
119
diff
changeset
|
862 |
497 | 863 static u_char * |
573 | 864 ngx_http_log_bytes_sent(ngx_http_request_t *r, u_char *buf, |
865 ngx_http_log_op_t *op) | |
176
c0552e5ab567
nginx-0.0.1-2003-11-09-23:03:38 import; separate building
Igor Sysoev <igor@sysoev.ru>
parents:
119
diff
changeset
|
866 { |
455 | 867 return ngx_sprintf(buf, "%O", r->connection->sent); |
176
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 |
c0552e5ab567
nginx-0.0.1-2003-11-09-23:03:38 import; separate building
Igor Sysoev <igor@sysoev.ru>
parents:
119
diff
changeset
|
870 |
1271 | 871 /* |
872 * although there is a real $body_bytes_sent variable, | |
873 * this log operation code function is more optimized for logging | |
874 */ | |
875 | |
497 | 876 static u_char * |
577 | 877 ngx_http_log_body_bytes_sent(ngx_http_request_t *r, u_char *buf, |
497 | 878 ngx_http_log_op_t *op) |
210
00cafae0bdf1
nginx-0.0.1-2003-12-14-23:10:27 import
Igor Sysoev <igor@sysoev.ru>
parents:
208
diff
changeset
|
879 { |
497 | 880 off_t length; |
881 | |
882 length = r->connection->sent - r->header_size; | |
883 | |
884 if (length > 0) { | |
885 return ngx_sprintf(buf, "%O", length); | |
886 } | |
887 | |
888 *buf = '0'; | |
889 | |
890 return buf + 1; | |
210
00cafae0bdf1
nginx-0.0.1-2003-12-14-23:10:27 import
Igor Sysoev <igor@sysoev.ru>
parents:
208
diff
changeset
|
891 } |
00cafae0bdf1
nginx-0.0.1-2003-12-14-23:10:27 import
Igor Sysoev <igor@sysoev.ru>
parents:
208
diff
changeset
|
892 |
00cafae0bdf1
nginx-0.0.1-2003-12-14-23:10:27 import
Igor Sysoev <igor@sysoev.ru>
parents:
208
diff
changeset
|
893 |
497 | 894 static u_char * |
895 ngx_http_log_request_length(ngx_http_request_t *r, u_char *buf, | |
896 ngx_http_log_op_t *op) | |
475 | 897 { |
663 | 898 return ngx_sprintf(buf, "%O", r->request_length); |
475 | 899 } |
900 | |
901 | |
497 | 902 static ngx_int_t |
501 | 903 ngx_http_log_variable_compile(ngx_conf_t *cf, ngx_http_log_op_t *op, |
7223
265c29b0b8b8
Access log: support for disabling escaping (ticket #1450).
Vladimir Homutov <vl@nginx.com>
parents:
6948
diff
changeset
|
904 ngx_str_t *value, ngx_uint_t escape) |
501 | 905 { |
509 | 906 ngx_int_t index; |
501 | 907 |
509 | 908 index = ngx_http_get_variable_index(cf, value); |
909 if (index == NGX_ERROR) { | |
501 | 910 return NGX_ERROR; |
911 } | |
912 | |
913 op->len = 0; | |
6840
0cf4e82e7c48
Access log: support for json escaping.
Valentin Bartenev <vbart@nginx.com>
parents:
6626
diff
changeset
|
914 |
7223
265c29b0b8b8
Access log: support for disabling escaping (ticket #1450).
Vladimir Homutov <vl@nginx.com>
parents:
6948
diff
changeset
|
915 switch (escape) { |
265c29b0b8b8
Access log: support for disabling escaping (ticket #1450).
Vladimir Homutov <vl@nginx.com>
parents:
6948
diff
changeset
|
916 case NGX_HTTP_LOG_ESCAPE_JSON: |
6840
0cf4e82e7c48
Access log: support for json escaping.
Valentin Bartenev <vbart@nginx.com>
parents:
6626
diff
changeset
|
917 op->getlen = ngx_http_log_json_variable_getlen; |
0cf4e82e7c48
Access log: support for json escaping.
Valentin Bartenev <vbart@nginx.com>
parents:
6626
diff
changeset
|
918 op->run = ngx_http_log_json_variable; |
7223
265c29b0b8b8
Access log: support for disabling escaping (ticket #1450).
Vladimir Homutov <vl@nginx.com>
parents:
6948
diff
changeset
|
919 break; |
6840
0cf4e82e7c48
Access log: support for json escaping.
Valentin Bartenev <vbart@nginx.com>
parents:
6626
diff
changeset
|
920 |
7223
265c29b0b8b8
Access log: support for disabling escaping (ticket #1450).
Vladimir Homutov <vl@nginx.com>
parents:
6948
diff
changeset
|
921 case NGX_HTTP_LOG_ESCAPE_NONE: |
265c29b0b8b8
Access log: support for disabling escaping (ticket #1450).
Vladimir Homutov <vl@nginx.com>
parents:
6948
diff
changeset
|
922 op->getlen = ngx_http_log_unescaped_variable_getlen; |
265c29b0b8b8
Access log: support for disabling escaping (ticket #1450).
Vladimir Homutov <vl@nginx.com>
parents:
6948
diff
changeset
|
923 op->run = ngx_http_log_unescaped_variable; |
265c29b0b8b8
Access log: support for disabling escaping (ticket #1450).
Vladimir Homutov <vl@nginx.com>
parents:
6948
diff
changeset
|
924 break; |
265c29b0b8b8
Access log: support for disabling escaping (ticket #1450).
Vladimir Homutov <vl@nginx.com>
parents:
6948
diff
changeset
|
925 |
265c29b0b8b8
Access log: support for disabling escaping (ticket #1450).
Vladimir Homutov <vl@nginx.com>
parents:
6948
diff
changeset
|
926 default: /* NGX_HTTP_LOG_ESCAPE_DEFAULT */ |
6840
0cf4e82e7c48
Access log: support for json escaping.
Valentin Bartenev <vbart@nginx.com>
parents:
6626
diff
changeset
|
927 op->getlen = ngx_http_log_variable_getlen; |
0cf4e82e7c48
Access log: support for json escaping.
Valentin Bartenev <vbart@nginx.com>
parents:
6626
diff
changeset
|
928 op->run = ngx_http_log_variable; |
0cf4e82e7c48
Access log: support for json escaping.
Valentin Bartenev <vbart@nginx.com>
parents:
6626
diff
changeset
|
929 } |
0cf4e82e7c48
Access log: support for json escaping.
Valentin Bartenev <vbart@nginx.com>
parents:
6626
diff
changeset
|
930 |
509 | 931 op->data = index; |
501 | 932 |
933 return NGX_OK; | |
934 } | |
935 | |
936 | |
937 static size_t | |
938 ngx_http_log_variable_getlen(ngx_http_request_t *r, uintptr_t data) | |
939 { | |
2008
66dc85397a90
escape 0x00-0x1f, ", and \ in access log variables
Igor Sysoev <igor@sysoev.ru>
parents:
1640
diff
changeset
|
940 uintptr_t len; |
501 | 941 ngx_http_variable_value_t *value; |
942 | |
943 value = ngx_http_get_indexed_variable(r, data); | |
944 | |
573 | 945 if (value == NULL || value->not_found) { |
501 | 946 return 1; |
947 } | |
948 | |
2008
66dc85397a90
escape 0x00-0x1f, ", and \ in access log variables
Igor Sysoev <igor@sysoev.ru>
parents:
1640
diff
changeset
|
949 len = ngx_http_log_escape(NULL, value->data, value->len); |
66dc85397a90
escape 0x00-0x1f, ", and \ in access log variables
Igor Sysoev <igor@sysoev.ru>
parents:
1640
diff
changeset
|
950 |
66dc85397a90
escape 0x00-0x1f, ", and \ in access log variables
Igor Sysoev <igor@sysoev.ru>
parents:
1640
diff
changeset
|
951 value->escape = len ? 1 : 0; |
66dc85397a90
escape 0x00-0x1f, ", and \ in access log variables
Igor Sysoev <igor@sysoev.ru>
parents:
1640
diff
changeset
|
952 |
66dc85397a90
escape 0x00-0x1f, ", and \ in access log variables
Igor Sysoev <igor@sysoev.ru>
parents:
1640
diff
changeset
|
953 return value->len + len * 3; |
501 | 954 } |
955 | |
956 | |
957 static u_char * | |
958 ngx_http_log_variable(ngx_http_request_t *r, u_char *buf, ngx_http_log_op_t *op) | |
959 { | |
960 ngx_http_variable_value_t *value; | |
961 | |
962 value = ngx_http_get_indexed_variable(r, op->data); | |
963 | |
573 | 964 if (value == NULL || value->not_found) { |
501 | 965 *buf = '-'; |
966 return buf + 1; | |
967 } | |
968 | |
2008
66dc85397a90
escape 0x00-0x1f, ", and \ in access log variables
Igor Sysoev <igor@sysoev.ru>
parents:
1640
diff
changeset
|
969 if (value->escape == 0) { |
66dc85397a90
escape 0x00-0x1f, ", and \ in access log variables
Igor Sysoev <igor@sysoev.ru>
parents:
1640
diff
changeset
|
970 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
|
971 |
66dc85397a90
escape 0x00-0x1f, ", and \ in access log variables
Igor Sysoev <igor@sysoev.ru>
parents:
1640
diff
changeset
|
972 } else { |
66dc85397a90
escape 0x00-0x1f, ", and \ in access log variables
Igor Sysoev <igor@sysoev.ru>
parents:
1640
diff
changeset
|
973 return (u_char *) ngx_http_log_escape(buf, value->data, value->len); |
66dc85397a90
escape 0x00-0x1f, ", and \ in access log variables
Igor Sysoev <igor@sysoev.ru>
parents:
1640
diff
changeset
|
974 } |
66dc85397a90
escape 0x00-0x1f, ", and \ in access log variables
Igor Sysoev <igor@sysoev.ru>
parents:
1640
diff
changeset
|
975 } |
66dc85397a90
escape 0x00-0x1f, ", and \ in access log variables
Igor Sysoev <igor@sysoev.ru>
parents:
1640
diff
changeset
|
976 |
66dc85397a90
escape 0x00-0x1f, ", and \ in access log variables
Igor Sysoev <igor@sysoev.ru>
parents:
1640
diff
changeset
|
977 |
66dc85397a90
escape 0x00-0x1f, ", and \ in access log variables
Igor Sysoev <igor@sysoev.ru>
parents:
1640
diff
changeset
|
978 static uintptr_t |
66dc85397a90
escape 0x00-0x1f, ", and \ in access log variables
Igor Sysoev <igor@sysoev.ru>
parents:
1640
diff
changeset
|
979 ngx_http_log_escape(u_char *dst, u_char *src, size_t size) |
66dc85397a90
escape 0x00-0x1f, ", and \ in access log variables
Igor Sysoev <igor@sysoev.ru>
parents:
1640
diff
changeset
|
980 { |
3275 | 981 ngx_uint_t n; |
2008
66dc85397a90
escape 0x00-0x1f, ", and \ in access log variables
Igor Sysoev <igor@sysoev.ru>
parents:
1640
diff
changeset
|
982 static u_char hex[] = "0123456789ABCDEF"; |
66dc85397a90
escape 0x00-0x1f, ", and \ in access log variables
Igor Sysoev <igor@sysoev.ru>
parents:
1640
diff
changeset
|
983 |
66dc85397a90
escape 0x00-0x1f, ", and \ in access log variables
Igor Sysoev <igor@sysoev.ru>
parents:
1640
diff
changeset
|
984 static uint32_t escape[] = { |
66dc85397a90
escape 0x00-0x1f, ", and \ in access log variables
Igor Sysoev <igor@sysoev.ru>
parents:
1640
diff
changeset
|
985 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
|
986 |
66dc85397a90
escape 0x00-0x1f, ", and \ in access log variables
Igor Sysoev <igor@sysoev.ru>
parents:
1640
diff
changeset
|
987 /* ?>=< ;:98 7654 3210 /.-, +*)( '&%$ #"! */ |
66dc85397a90
escape 0x00-0x1f, ", and \ in access log variables
Igor Sysoev <igor@sysoev.ru>
parents:
1640
diff
changeset
|
988 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
|
989 |
66dc85397a90
escape 0x00-0x1f, ", and \ in access log variables
Igor Sysoev <igor@sysoev.ru>
parents:
1640
diff
changeset
|
990 /* _^]\ [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
|
991 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
|
992 |
66dc85397a90
escape 0x00-0x1f, ", and \ in access log variables
Igor Sysoev <igor@sysoev.ru>
parents:
1640
diff
changeset
|
993 /* ~}| {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
|
994 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
|
995 |
4191
08d8af70760c
Improved access log escaping to better protect other software.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4133
diff
changeset
|
996 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
|
997 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
|
998 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
|
999 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
|
1000 }; |
66dc85397a90
escape 0x00-0x1f, ", and \ in access log variables
Igor Sysoev <igor@sysoev.ru>
parents:
1640
diff
changeset
|
1001 |
66dc85397a90
escape 0x00-0x1f, ", and \ in access log variables
Igor Sysoev <igor@sysoev.ru>
parents:
1640
diff
changeset
|
1002 |
66dc85397a90
escape 0x00-0x1f, ", and \ in access log variables
Igor Sysoev <igor@sysoev.ru>
parents:
1640
diff
changeset
|
1003 if (dst == NULL) { |
66dc85397a90
escape 0x00-0x1f, ", and \ in access log variables
Igor Sysoev <igor@sysoev.ru>
parents:
1640
diff
changeset
|
1004 |
66dc85397a90
escape 0x00-0x1f, ", and \ in access log variables
Igor Sysoev <igor@sysoev.ru>
parents:
1640
diff
changeset
|
1005 /* 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
|
1006 |
3115 | 1007 n = 0; |
2008
66dc85397a90
escape 0x00-0x1f, ", and \ in access log variables
Igor Sysoev <igor@sysoev.ru>
parents:
1640
diff
changeset
|
1008 |
3275 | 1009 while (size) { |
6626
b3682580c1bd
Avoid left-shifting integers into the sign bit, which is undefined.
Sergey Kandaurov <pluknet@nginx.com>
parents:
5927
diff
changeset
|
1010 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
|
1011 n++; |
66dc85397a90
escape 0x00-0x1f, ", and \ in access log variables
Igor Sysoev <igor@sysoev.ru>
parents:
1640
diff
changeset
|
1012 } |
66dc85397a90
escape 0x00-0x1f, ", and \ in access log variables
Igor Sysoev <igor@sysoev.ru>
parents:
1640
diff
changeset
|
1013 src++; |
3275 | 1014 size--; |
2008
66dc85397a90
escape 0x00-0x1f, ", and \ in access log variables
Igor Sysoev <igor@sysoev.ru>
parents:
1640
diff
changeset
|
1015 } |
66dc85397a90
escape 0x00-0x1f, ", and \ in access log variables
Igor Sysoev <igor@sysoev.ru>
parents:
1640
diff
changeset
|
1016 |
66dc85397a90
escape 0x00-0x1f, ", and \ in access log variables
Igor Sysoev <igor@sysoev.ru>
parents:
1640
diff
changeset
|
1017 return (uintptr_t) n; |
66dc85397a90
escape 0x00-0x1f, ", and \ in access log variables
Igor Sysoev <igor@sysoev.ru>
parents:
1640
diff
changeset
|
1018 } |
66dc85397a90
escape 0x00-0x1f, ", and \ in access log variables
Igor Sysoev <igor@sysoev.ru>
parents:
1640
diff
changeset
|
1019 |
3275 | 1020 while (size) { |
6626
b3682580c1bd
Avoid left-shifting integers into the sign bit, which is undefined.
Sergey Kandaurov <pluknet@nginx.com>
parents:
5927
diff
changeset
|
1021 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
|
1022 *dst++ = '\\'; |
66dc85397a90
escape 0x00-0x1f, ", and \ in access log variables
Igor Sysoev <igor@sysoev.ru>
parents:
1640
diff
changeset
|
1023 *dst++ = 'x'; |
66dc85397a90
escape 0x00-0x1f, ", and \ in access log variables
Igor Sysoev <igor@sysoev.ru>
parents:
1640
diff
changeset
|
1024 *dst++ = hex[*src >> 4]; |
66dc85397a90
escape 0x00-0x1f, ", and \ in access log variables
Igor Sysoev <igor@sysoev.ru>
parents:
1640
diff
changeset
|
1025 *dst++ = hex[*src & 0xf]; |
66dc85397a90
escape 0x00-0x1f, ", and \ in access log variables
Igor Sysoev <igor@sysoev.ru>
parents:
1640
diff
changeset
|
1026 src++; |
66dc85397a90
escape 0x00-0x1f, ", and \ in access log variables
Igor Sysoev <igor@sysoev.ru>
parents:
1640
diff
changeset
|
1027 |
66dc85397a90
escape 0x00-0x1f, ", and \ in access log variables
Igor Sysoev <igor@sysoev.ru>
parents:
1640
diff
changeset
|
1028 } else { |
66dc85397a90
escape 0x00-0x1f, ", and \ in access log variables
Igor Sysoev <igor@sysoev.ru>
parents:
1640
diff
changeset
|
1029 *dst++ = *src++; |
66dc85397a90
escape 0x00-0x1f, ", and \ in access log variables
Igor Sysoev <igor@sysoev.ru>
parents:
1640
diff
changeset
|
1030 } |
3275 | 1031 size--; |
2008
66dc85397a90
escape 0x00-0x1f, ", and \ in access log variables
Igor Sysoev <igor@sysoev.ru>
parents:
1640
diff
changeset
|
1032 } |
66dc85397a90
escape 0x00-0x1f, ", and \ in access log variables
Igor Sysoev <igor@sysoev.ru>
parents:
1640
diff
changeset
|
1033 |
66dc85397a90
escape 0x00-0x1f, ", and \ in access log variables
Igor Sysoev <igor@sysoev.ru>
parents:
1640
diff
changeset
|
1034 return (uintptr_t) dst; |
501 | 1035 } |
1036 | |
1037 | |
6840
0cf4e82e7c48
Access log: support for json escaping.
Valentin Bartenev <vbart@nginx.com>
parents:
6626
diff
changeset
|
1038 static size_t |
0cf4e82e7c48
Access log: support for json escaping.
Valentin Bartenev <vbart@nginx.com>
parents:
6626
diff
changeset
|
1039 ngx_http_log_json_variable_getlen(ngx_http_request_t *r, uintptr_t data) |
0cf4e82e7c48
Access log: support for json escaping.
Valentin Bartenev <vbart@nginx.com>
parents:
6626
diff
changeset
|
1040 { |
0cf4e82e7c48
Access log: support for json escaping.
Valentin Bartenev <vbart@nginx.com>
parents:
6626
diff
changeset
|
1041 uintptr_t len; |
0cf4e82e7c48
Access log: support for json escaping.
Valentin Bartenev <vbart@nginx.com>
parents:
6626
diff
changeset
|
1042 ngx_http_variable_value_t *value; |
0cf4e82e7c48
Access log: support for json escaping.
Valentin Bartenev <vbart@nginx.com>
parents:
6626
diff
changeset
|
1043 |
0cf4e82e7c48
Access log: support for json escaping.
Valentin Bartenev <vbart@nginx.com>
parents:
6626
diff
changeset
|
1044 value = ngx_http_get_indexed_variable(r, data); |
0cf4e82e7c48
Access log: support for json escaping.
Valentin Bartenev <vbart@nginx.com>
parents:
6626
diff
changeset
|
1045 |
0cf4e82e7c48
Access log: support for json escaping.
Valentin Bartenev <vbart@nginx.com>
parents:
6626
diff
changeset
|
1046 if (value == NULL || value->not_found) { |
0cf4e82e7c48
Access log: support for json escaping.
Valentin Bartenev <vbart@nginx.com>
parents:
6626
diff
changeset
|
1047 return 0; |
0cf4e82e7c48
Access log: support for json escaping.
Valentin Bartenev <vbart@nginx.com>
parents:
6626
diff
changeset
|
1048 } |
0cf4e82e7c48
Access log: support for json escaping.
Valentin Bartenev <vbart@nginx.com>
parents:
6626
diff
changeset
|
1049 |
0cf4e82e7c48
Access log: support for json escaping.
Valentin Bartenev <vbart@nginx.com>
parents:
6626
diff
changeset
|
1050 len = ngx_escape_json(NULL, value->data, value->len); |
0cf4e82e7c48
Access log: support for json escaping.
Valentin Bartenev <vbart@nginx.com>
parents:
6626
diff
changeset
|
1051 |
0cf4e82e7c48
Access log: support for json escaping.
Valentin Bartenev <vbart@nginx.com>
parents:
6626
diff
changeset
|
1052 value->escape = len ? 1 : 0; |
0cf4e82e7c48
Access log: support for json escaping.
Valentin Bartenev <vbart@nginx.com>
parents:
6626
diff
changeset
|
1053 |
0cf4e82e7c48
Access log: support for json escaping.
Valentin Bartenev <vbart@nginx.com>
parents:
6626
diff
changeset
|
1054 return value->len + len; |
0cf4e82e7c48
Access log: support for json escaping.
Valentin Bartenev <vbart@nginx.com>
parents:
6626
diff
changeset
|
1055 } |
0cf4e82e7c48
Access log: support for json escaping.
Valentin Bartenev <vbart@nginx.com>
parents:
6626
diff
changeset
|
1056 |
0cf4e82e7c48
Access log: support for json escaping.
Valentin Bartenev <vbart@nginx.com>
parents:
6626
diff
changeset
|
1057 |
0cf4e82e7c48
Access log: support for json escaping.
Valentin Bartenev <vbart@nginx.com>
parents:
6626
diff
changeset
|
1058 static u_char * |
0cf4e82e7c48
Access log: support for json escaping.
Valentin Bartenev <vbart@nginx.com>
parents:
6626
diff
changeset
|
1059 ngx_http_log_json_variable(ngx_http_request_t *r, u_char *buf, |
0cf4e82e7c48
Access log: support for json escaping.
Valentin Bartenev <vbart@nginx.com>
parents:
6626
diff
changeset
|
1060 ngx_http_log_op_t *op) |
0cf4e82e7c48
Access log: support for json escaping.
Valentin Bartenev <vbart@nginx.com>
parents:
6626
diff
changeset
|
1061 { |
0cf4e82e7c48
Access log: support for json escaping.
Valentin Bartenev <vbart@nginx.com>
parents:
6626
diff
changeset
|
1062 ngx_http_variable_value_t *value; |
0cf4e82e7c48
Access log: support for json escaping.
Valentin Bartenev <vbart@nginx.com>
parents:
6626
diff
changeset
|
1063 |
0cf4e82e7c48
Access log: support for json escaping.
Valentin Bartenev <vbart@nginx.com>
parents:
6626
diff
changeset
|
1064 value = ngx_http_get_indexed_variable(r, op->data); |
0cf4e82e7c48
Access log: support for json escaping.
Valentin Bartenev <vbart@nginx.com>
parents:
6626
diff
changeset
|
1065 |
0cf4e82e7c48
Access log: support for json escaping.
Valentin Bartenev <vbart@nginx.com>
parents:
6626
diff
changeset
|
1066 if (value == NULL || value->not_found) { |
0cf4e82e7c48
Access log: support for json escaping.
Valentin Bartenev <vbart@nginx.com>
parents:
6626
diff
changeset
|
1067 return buf; |
0cf4e82e7c48
Access log: support for json escaping.
Valentin Bartenev <vbart@nginx.com>
parents:
6626
diff
changeset
|
1068 } |
0cf4e82e7c48
Access log: support for json escaping.
Valentin Bartenev <vbart@nginx.com>
parents:
6626
diff
changeset
|
1069 |
0cf4e82e7c48
Access log: support for json escaping.
Valentin Bartenev <vbart@nginx.com>
parents:
6626
diff
changeset
|
1070 if (value->escape == 0) { |
0cf4e82e7c48
Access log: support for json escaping.
Valentin Bartenev <vbart@nginx.com>
parents:
6626
diff
changeset
|
1071 return ngx_cpymem(buf, value->data, value->len); |
0cf4e82e7c48
Access log: support for json escaping.
Valentin Bartenev <vbart@nginx.com>
parents:
6626
diff
changeset
|
1072 |
0cf4e82e7c48
Access log: support for json escaping.
Valentin Bartenev <vbart@nginx.com>
parents:
6626
diff
changeset
|
1073 } else { |
0cf4e82e7c48
Access log: support for json escaping.
Valentin Bartenev <vbart@nginx.com>
parents:
6626
diff
changeset
|
1074 return (u_char *) ngx_escape_json(buf, value->data, value->len); |
0cf4e82e7c48
Access log: support for json escaping.
Valentin Bartenev <vbart@nginx.com>
parents:
6626
diff
changeset
|
1075 } |
0cf4e82e7c48
Access log: support for json escaping.
Valentin Bartenev <vbart@nginx.com>
parents:
6626
diff
changeset
|
1076 } |
0cf4e82e7c48
Access log: support for json escaping.
Valentin Bartenev <vbart@nginx.com>
parents:
6626
diff
changeset
|
1077 |
0cf4e82e7c48
Access log: support for json escaping.
Valentin Bartenev <vbart@nginx.com>
parents:
6626
diff
changeset
|
1078 |
7223
265c29b0b8b8
Access log: support for disabling escaping (ticket #1450).
Vladimir Homutov <vl@nginx.com>
parents:
6948
diff
changeset
|
1079 static size_t |
265c29b0b8b8
Access log: support for disabling escaping (ticket #1450).
Vladimir Homutov <vl@nginx.com>
parents:
6948
diff
changeset
|
1080 ngx_http_log_unescaped_variable_getlen(ngx_http_request_t *r, uintptr_t data) |
265c29b0b8b8
Access log: support for disabling escaping (ticket #1450).
Vladimir Homutov <vl@nginx.com>
parents:
6948
diff
changeset
|
1081 { |
265c29b0b8b8
Access log: support for disabling escaping (ticket #1450).
Vladimir Homutov <vl@nginx.com>
parents:
6948
diff
changeset
|
1082 ngx_http_variable_value_t *value; |
265c29b0b8b8
Access log: support for disabling escaping (ticket #1450).
Vladimir Homutov <vl@nginx.com>
parents:
6948
diff
changeset
|
1083 |
265c29b0b8b8
Access log: support for disabling escaping (ticket #1450).
Vladimir Homutov <vl@nginx.com>
parents:
6948
diff
changeset
|
1084 value = ngx_http_get_indexed_variable(r, data); |
265c29b0b8b8
Access log: support for disabling escaping (ticket #1450).
Vladimir Homutov <vl@nginx.com>
parents:
6948
diff
changeset
|
1085 |
265c29b0b8b8
Access log: support for disabling escaping (ticket #1450).
Vladimir Homutov <vl@nginx.com>
parents:
6948
diff
changeset
|
1086 if (value == NULL || value->not_found) { |
265c29b0b8b8
Access log: support for disabling escaping (ticket #1450).
Vladimir Homutov <vl@nginx.com>
parents:
6948
diff
changeset
|
1087 return 0; |
265c29b0b8b8
Access log: support for disabling escaping (ticket #1450).
Vladimir Homutov <vl@nginx.com>
parents:
6948
diff
changeset
|
1088 } |
265c29b0b8b8
Access log: support for disabling escaping (ticket #1450).
Vladimir Homutov <vl@nginx.com>
parents:
6948
diff
changeset
|
1089 |
265c29b0b8b8
Access log: support for disabling escaping (ticket #1450).
Vladimir Homutov <vl@nginx.com>
parents:
6948
diff
changeset
|
1090 value->escape = 0; |
265c29b0b8b8
Access log: support for disabling escaping (ticket #1450).
Vladimir Homutov <vl@nginx.com>
parents:
6948
diff
changeset
|
1091 |
265c29b0b8b8
Access log: support for disabling escaping (ticket #1450).
Vladimir Homutov <vl@nginx.com>
parents:
6948
diff
changeset
|
1092 return value->len; |
265c29b0b8b8
Access log: support for disabling escaping (ticket #1450).
Vladimir Homutov <vl@nginx.com>
parents:
6948
diff
changeset
|
1093 } |
265c29b0b8b8
Access log: support for disabling escaping (ticket #1450).
Vladimir Homutov <vl@nginx.com>
parents:
6948
diff
changeset
|
1094 |
265c29b0b8b8
Access log: support for disabling escaping (ticket #1450).
Vladimir Homutov <vl@nginx.com>
parents:
6948
diff
changeset
|
1095 |
265c29b0b8b8
Access log: support for disabling escaping (ticket #1450).
Vladimir Homutov <vl@nginx.com>
parents:
6948
diff
changeset
|
1096 static u_char * |
265c29b0b8b8
Access log: support for disabling escaping (ticket #1450).
Vladimir Homutov <vl@nginx.com>
parents:
6948
diff
changeset
|
1097 ngx_http_log_unescaped_variable(ngx_http_request_t *r, u_char *buf, |
265c29b0b8b8
Access log: support for disabling escaping (ticket #1450).
Vladimir Homutov <vl@nginx.com>
parents:
6948
diff
changeset
|
1098 ngx_http_log_op_t *op) |
265c29b0b8b8
Access log: support for disabling escaping (ticket #1450).
Vladimir Homutov <vl@nginx.com>
parents:
6948
diff
changeset
|
1099 { |
265c29b0b8b8
Access log: support for disabling escaping (ticket #1450).
Vladimir Homutov <vl@nginx.com>
parents:
6948
diff
changeset
|
1100 ngx_http_variable_value_t *value; |
265c29b0b8b8
Access log: support for disabling escaping (ticket #1450).
Vladimir Homutov <vl@nginx.com>
parents:
6948
diff
changeset
|
1101 |
265c29b0b8b8
Access log: support for disabling escaping (ticket #1450).
Vladimir Homutov <vl@nginx.com>
parents:
6948
diff
changeset
|
1102 value = ngx_http_get_indexed_variable(r, op->data); |
265c29b0b8b8
Access log: support for disabling escaping (ticket #1450).
Vladimir Homutov <vl@nginx.com>
parents:
6948
diff
changeset
|
1103 |
265c29b0b8b8
Access log: support for disabling escaping (ticket #1450).
Vladimir Homutov <vl@nginx.com>
parents:
6948
diff
changeset
|
1104 if (value == NULL || value->not_found) { |
265c29b0b8b8
Access log: support for disabling escaping (ticket #1450).
Vladimir Homutov <vl@nginx.com>
parents:
6948
diff
changeset
|
1105 return buf; |
265c29b0b8b8
Access log: support for disabling escaping (ticket #1450).
Vladimir Homutov <vl@nginx.com>
parents:
6948
diff
changeset
|
1106 } |
265c29b0b8b8
Access log: support for disabling escaping (ticket #1450).
Vladimir Homutov <vl@nginx.com>
parents:
6948
diff
changeset
|
1107 |
265c29b0b8b8
Access log: support for disabling escaping (ticket #1450).
Vladimir Homutov <vl@nginx.com>
parents:
6948
diff
changeset
|
1108 return ngx_cpymem(buf, value->data, value->len); |
265c29b0b8b8
Access log: support for disabling escaping (ticket #1450).
Vladimir Homutov <vl@nginx.com>
parents:
6948
diff
changeset
|
1109 } |
265c29b0b8b8
Access log: support for disabling escaping (ticket #1450).
Vladimir Homutov <vl@nginx.com>
parents:
6948
diff
changeset
|
1110 |
265c29b0b8b8
Access log: support for disabling escaping (ticket #1450).
Vladimir Homutov <vl@nginx.com>
parents:
6948
diff
changeset
|
1111 |
497 | 1112 static void * |
1113 ngx_http_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
|
1114 { |
c0552e5ab567
nginx-0.0.1-2003-11-09-23:03:38 import; separate building
Igor Sysoev <igor@sysoev.ru>
parents:
119
diff
changeset
|
1115 ngx_http_log_main_conf_t *conf; |
c0552e5ab567
nginx-0.0.1-2003-11-09-23:03:38 import; separate building
Igor Sysoev <igor@sysoev.ru>
parents:
119
diff
changeset
|
1116 |
573 | 1117 ngx_http_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
|
1118 |
501 | 1119 conf = ngx_pcalloc(cf->pool, sizeof(ngx_http_log_main_conf_t)); |
1120 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
|
1121 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
|
1122 } |
c0552e5ab567
nginx-0.0.1-2003-11-09-23:03:38 import; separate building
Igor Sysoev <igor@sysoev.ru>
parents:
119
diff
changeset
|
1123 |
497 | 1124 if (ngx_array_init(&conf->formats, cf->pool, 4, sizeof(ngx_http_log_fmt_t)) |
573 | 1125 != NGX_OK) |
497 | 1126 { |
2912
c7d57b539248
return NULL instead of NGX_CONF_ERROR on a create conf failure
Igor Sysoev <igor@sysoev.ru>
parents:
2756
diff
changeset
|
1127 return NULL; |
497 | 1128 } |
176
c0552e5ab567
nginx-0.0.1-2003-11-09-23:03:38 import; separate building
Igor Sysoev <igor@sysoev.ru>
parents:
119
diff
changeset
|
1129 |
573 | 1130 fmt = ngx_array_push(&conf->formats); |
1131 if (fmt == NULL) { | |
2912
c7d57b539248
return NULL instead of NGX_CONF_ERROR on a create conf failure
Igor Sysoev <igor@sysoev.ru>
parents:
2756
diff
changeset
|
1132 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
|
1133 } |
c0552e5ab567
nginx-0.0.1-2003-11-09-23:03:38 import; separate building
Igor Sysoev <igor@sysoev.ru>
parents:
119
diff
changeset
|
1134 |
3516
dd1570b6f237
ngx_str_set() and ngx_str_null()
Igor Sysoev <igor@sysoev.ru>
parents:
3515
diff
changeset
|
1135 ngx_str_set(&fmt->name, "combined"); |
176
c0552e5ab567
nginx-0.0.1-2003-11-09-23:03:38 import; separate building
Igor Sysoev <igor@sysoev.ru>
parents:
119
diff
changeset
|
1136 |
2261 | 1137 fmt->flushes = NULL; |
1138 | |
573 | 1139 fmt->ops = ngx_array_create(cf->pool, 16, sizeof(ngx_http_log_op_t)); |
1140 if (fmt->ops == NULL) { | |
2912
c7d57b539248
return NULL instead of NGX_CONF_ERROR on a create conf failure
Igor Sysoev <igor@sysoev.ru>
parents:
2756
diff
changeset
|
1141 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
|
1142 } |
c0552e5ab567
nginx-0.0.1-2003-11-09-23:03:38 import; separate building
Igor Sysoev <igor@sysoev.ru>
parents:
119
diff
changeset
|
1143 |
c0552e5ab567
nginx-0.0.1-2003-11-09-23:03:38 import; separate building
Igor Sysoev <igor@sysoev.ru>
parents:
119
diff
changeset
|
1144 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
|
1145 } |
c0552e5ab567
nginx-0.0.1-2003-11-09-23:03:38 import; separate building
Igor Sysoev <igor@sysoev.ru>
parents:
119
diff
changeset
|
1146 |
c0552e5ab567
nginx-0.0.1-2003-11-09-23:03:38 import; separate building
Igor Sysoev <igor@sysoev.ru>
parents:
119
diff
changeset
|
1147 |
497 | 1148 static void * |
1149 ngx_http_log_create_loc_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
|
1150 { |
c0552e5ab567
nginx-0.0.1-2003-11-09-23:03:38 import; separate building
Igor Sysoev <igor@sysoev.ru>
parents:
119
diff
changeset
|
1151 ngx_http_log_loc_conf_t *conf; |
c0552e5ab567
nginx-0.0.1-2003-11-09-23:03:38 import; separate building
Igor Sysoev <igor@sysoev.ru>
parents:
119
diff
changeset
|
1152 |
501 | 1153 conf = ngx_pcalloc(cf->pool, sizeof(ngx_http_log_loc_conf_t)); |
1154 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
|
1155 return NULL; |
427
0d08eabe5c7b
nginx-0.0.10-2004-09-15-20:00:43 import
Igor Sysoev <igor@sysoev.ru>
parents:
415
diff
changeset
|
1156 } |
99
a059e1aa65d4
nginx-0.0.1-2003-06-02-19:24:30 import
Igor Sysoev <igor@sysoev.ru>
parents:
69
diff
changeset
|
1157 |
2072 | 1158 conf->open_file_cache = NGX_CONF_UNSET_PTR; |
1159 | |
99
a059e1aa65d4
nginx-0.0.1-2003-06-02-19:24:30 import
Igor Sysoev <igor@sysoev.ru>
parents:
69
diff
changeset
|
1160 return conf; |
a059e1aa65d4
nginx-0.0.1-2003-06-02-19:24:30 import
Igor Sysoev <igor@sysoev.ru>
parents:
69
diff
changeset
|
1161 } |
a059e1aa65d4
nginx-0.0.1-2003-06-02-19:24:30 import
Igor Sysoev <igor@sysoev.ru>
parents:
69
diff
changeset
|
1162 |
a059e1aa65d4
nginx-0.0.1-2003-06-02-19:24:30 import
Igor Sysoev <igor@sysoev.ru>
parents:
69
diff
changeset
|
1163 |
497 | 1164 static char * |
1165 ngx_http_log_merge_loc_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
|
1166 { |
176
c0552e5ab567
nginx-0.0.1-2003-11-09-23:03:38 import; separate building
Igor Sysoev <igor@sysoev.ru>
parents:
119
diff
changeset
|
1167 ngx_http_log_loc_conf_t *prev = parent; |
c0552e5ab567
nginx-0.0.1-2003-11-09-23:03:38 import; separate building
Igor Sysoev <igor@sysoev.ru>
parents:
119
diff
changeset
|
1168 ngx_http_log_loc_conf_t *conf = child; |
c0552e5ab567
nginx-0.0.1-2003-11-09-23:03:38 import; separate building
Igor Sysoev <igor@sysoev.ru>
parents:
119
diff
changeset
|
1169 |
c0552e5ab567
nginx-0.0.1-2003-11-09-23:03:38 import; separate building
Igor Sysoev <igor@sysoev.ru>
parents:
119
diff
changeset
|
1170 ngx_http_log_t *log; |
c0552e5ab567
nginx-0.0.1-2003-11-09-23:03:38 import; separate building
Igor Sysoev <igor@sysoev.ru>
parents:
119
diff
changeset
|
1171 ngx_http_log_fmt_t *fmt; |
c0552e5ab567
nginx-0.0.1-2003-11-09-23:03:38 import; separate building
Igor Sysoev <igor@sysoev.ru>
parents:
119
diff
changeset
|
1172 ngx_http_log_main_conf_t *lmcf; |
c0552e5ab567
nginx-0.0.1-2003-11-09-23:03:38 import; separate building
Igor Sysoev <igor@sysoev.ru>
parents:
119
diff
changeset
|
1173 |
2072 | 1174 if (conf->open_file_cache == NGX_CONF_UNSET_PTR) { |
1175 | |
1176 conf->open_file_cache = prev->open_file_cache; | |
1177 conf->open_file_cache_valid = prev->open_file_cache_valid; | |
1178 conf->open_file_cache_min_uses = prev->open_file_cache_min_uses; | |
1179 | |
1180 if (conf->open_file_cache == NGX_CONF_UNSET_PTR) { | |
1181 conf->open_file_cache = NULL; | |
1182 } | |
1183 } | |
1184 | |
1074 | 1185 if (conf->logs || conf->off) { |
1186 return NGX_CONF_OK; | |
1187 } | |
427
0d08eabe5c7b
nginx-0.0.10-2004-09-15-20:00:43 import
Igor Sysoev <igor@sysoev.ru>
parents:
415
diff
changeset
|
1188 |
2078
9acbc5e7bcbd
fix variable access_log merging
Igor Sysoev <igor@sysoev.ru>
parents:
2077
diff
changeset
|
1189 conf->logs = prev->logs; |
9acbc5e7bcbd
fix variable access_log merging
Igor Sysoev <igor@sysoev.ru>
parents:
2077
diff
changeset
|
1190 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
|
1191 |
1074 | 1192 if (conf->logs || conf->off) { |
1193 return NGX_CONF_OK; | |
1194 } | |
99
a059e1aa65d4
nginx-0.0.1-2003-06-02-19:24:30 import
Igor Sysoev <igor@sysoev.ru>
parents:
69
diff
changeset
|
1195 |
1074 | 1196 conf->logs = ngx_array_create(cf->pool, 2, sizeof(ngx_http_log_t)); |
1197 if (conf->logs == NULL) { | |
1198 return NGX_CONF_ERROR; | |
1199 } | |
176
c0552e5ab567
nginx-0.0.1-2003-11-09-23:03:38 import; separate building
Igor Sysoev <igor@sysoev.ru>
parents:
119
diff
changeset
|
1200 |
1074 | 1201 log = ngx_array_push(conf->logs); |
1202 if (log == NULL) { | |
1203 return NGX_CONF_ERROR; | |
1204 } | |
176
c0552e5ab567
nginx-0.0.1-2003-11-09-23:03:38 import; separate building
Igor Sysoev <igor@sysoev.ru>
parents:
119
diff
changeset
|
1205 |
5719
7f425d67f91a
Access log: fix default value, broken by cb308813b453.
Piotr Sikora <piotr@cloudflare.com>
parents:
5702
diff
changeset
|
1206 ngx_memzero(log, sizeof(ngx_http_log_t)); |
7f425d67f91a
Access log: fix default value, broken by cb308813b453.
Piotr Sikora <piotr@cloudflare.com>
parents:
5702
diff
changeset
|
1207 |
1074 | 1208 log->file = ngx_conf_open_file(cf->cycle, &ngx_http_access_log); |
1209 if (log->file == NULL) { | |
1210 return NGX_CONF_ERROR; | |
1211 } | |
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 |
1074 | 1213 lmcf = ngx_http_conf_get_module_main_conf(cf, ngx_http_log_module); |
1214 fmt = lmcf->formats.elts; | |
1215 | |
1216 /* the default "combined" format */ | |
2261 | 1217 log->format = &fmt[0]; |
1074 | 1218 lmcf->combined_used = 1; |
99
a059e1aa65d4
nginx-0.0.1-2003-06-02-19:24:30 import
Igor Sysoev <igor@sysoev.ru>
parents:
69
diff
changeset
|
1219 |
a059e1aa65d4
nginx-0.0.1-2003-06-02-19:24:30 import
Igor Sysoev <igor@sysoev.ru>
parents:
69
diff
changeset
|
1220 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
|
1221 } |
a059e1aa65d4
nginx-0.0.1-2003-06-02-19:24:30 import
Igor Sysoev <igor@sysoev.ru>
parents:
69
diff
changeset
|
1222 |
a059e1aa65d4
nginx-0.0.1-2003-06-02-19:24:30 import
Igor Sysoev <igor@sysoev.ru>
parents:
69
diff
changeset
|
1223 |
497 | 1224 static char * |
1225 ngx_http_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
|
1226 { |
176
c0552e5ab567
nginx-0.0.1-2003-11-09-23:03:38 import; separate building
Igor Sysoev <igor@sysoev.ru>
parents:
119
diff
changeset
|
1227 ngx_http_log_loc_conf_t *llcf = conf; |
99
a059e1aa65d4
nginx-0.0.1-2003-06-02-19:24:30 import
Igor Sysoev <igor@sysoev.ru>
parents:
69
diff
changeset
|
1228 |
5653
cb308813b453
Access log: the "if" parameter of the "access_log" directive.
Sergey Kandaurov <pluknet@nginx.com>
parents:
5361
diff
changeset
|
1229 ssize_t size; |
cb308813b453
Access log: the "if" parameter of the "access_log" directive.
Sergey Kandaurov <pluknet@nginx.com>
parents:
5361
diff
changeset
|
1230 ngx_int_t gzip; |
cb308813b453
Access log: the "if" parameter of the "access_log" directive.
Sergey Kandaurov <pluknet@nginx.com>
parents:
5361
diff
changeset
|
1231 ngx_uint_t i, n; |
cb308813b453
Access log: the "if" parameter of the "access_log" directive.
Sergey Kandaurov <pluknet@nginx.com>
parents:
5361
diff
changeset
|
1232 ngx_msec_t flush; |
5833
e3016ee8dba3
Access log: fixed the "if=" parameter with buffering (ticket #625).
Valentin Bartenev <vbart@nginx.com>
parents:
5799
diff
changeset
|
1233 ngx_str_t *value, name, s; |
5653
cb308813b453
Access log: the "if" parameter of the "access_log" directive.
Sergey Kandaurov <pluknet@nginx.com>
parents:
5361
diff
changeset
|
1234 ngx_http_log_t *log; |
5702
777202558122
Added syslog support for error_log and access_log directives.
Vladimir Homutov <vl@nginx.com>
parents:
5653
diff
changeset
|
1235 ngx_syslog_peer_t *peer; |
5653
cb308813b453
Access log: the "if" parameter of the "access_log" directive.
Sergey Kandaurov <pluknet@nginx.com>
parents:
5361
diff
changeset
|
1236 ngx_http_log_buf_t *buffer; |
cb308813b453
Access log: the "if" parameter of the "access_log" directive.
Sergey Kandaurov <pluknet@nginx.com>
parents:
5361
diff
changeset
|
1237 ngx_http_log_fmt_t *fmt; |
cb308813b453
Access log: the "if" parameter of the "access_log" directive.
Sergey Kandaurov <pluknet@nginx.com>
parents:
5361
diff
changeset
|
1238 ngx_http_log_main_conf_t *lmcf; |
cb308813b453
Access log: the "if" parameter of the "access_log" directive.
Sergey Kandaurov <pluknet@nginx.com>
parents:
5361
diff
changeset
|
1239 ngx_http_script_compile_t sc; |
cb308813b453
Access log: the "if" parameter of the "access_log" directive.
Sergey Kandaurov <pluknet@nginx.com>
parents:
5361
diff
changeset
|
1240 ngx_http_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
|
1241 |
427
0d08eabe5c7b
nginx-0.0.10-2004-09-15-20:00:43 import
Igor Sysoev <igor@sysoev.ru>
parents:
415
diff
changeset
|
1242 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
|
1243 |
0d08eabe5c7b
nginx-0.0.10-2004-09-15-20:00:43 import
Igor Sysoev <igor@sysoev.ru>
parents:
415
diff
changeset
|
1244 if (ngx_strcmp(value[1].data, "off") == 0) { |
0d08eabe5c7b
nginx-0.0.10-2004-09-15-20:00:43 import
Igor Sysoev <igor@sysoev.ru>
parents:
415
diff
changeset
|
1245 llcf->off = 1; |
3038
cd8738e76610
strict testing "access_log off"
Igor Sysoev <igor@sysoev.ru>
parents:
2912
diff
changeset
|
1246 if (cf->args->nelts == 2) { |
cd8738e76610
strict testing "access_log off"
Igor Sysoev <igor@sysoev.ru>
parents:
2912
diff
changeset
|
1247 return NGX_CONF_OK; |
cd8738e76610
strict testing "access_log off"
Igor Sysoev <igor@sysoev.ru>
parents:
2912
diff
changeset
|
1248 } |
cd8738e76610
strict testing "access_log off"
Igor Sysoev <igor@sysoev.ru>
parents:
2912
diff
changeset
|
1249 |
cd8738e76610
strict testing "access_log off"
Igor Sysoev <igor@sysoev.ru>
parents:
2912
diff
changeset
|
1250 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, |
cd8738e76610
strict testing "access_log off"
Igor Sysoev <igor@sysoev.ru>
parents:
2912
diff
changeset
|
1251 "invalid parameter \"%V\"", &value[2]); |
cd8738e76610
strict testing "access_log off"
Igor Sysoev <igor@sysoev.ru>
parents:
2912
diff
changeset
|
1252 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
|
1253 } |
0d08eabe5c7b
nginx-0.0.10-2004-09-15-20:00:43 import
Igor Sysoev <igor@sysoev.ru>
parents:
415
diff
changeset
|
1254 |
176
c0552e5ab567
nginx-0.0.1-2003-11-09-23:03:38 import; separate building
Igor Sysoev <igor@sysoev.ru>
parents:
119
diff
changeset
|
1255 if (llcf->logs == NULL) { |
427
0d08eabe5c7b
nginx-0.0.10-2004-09-15-20:00:43 import
Igor Sysoev <igor@sysoev.ru>
parents:
415
diff
changeset
|
1256 llcf->logs = ngx_array_create(cf->pool, 2, sizeof(ngx_http_log_t)); |
0d08eabe5c7b
nginx-0.0.10-2004-09-15-20:00:43 import
Igor Sysoev <igor@sysoev.ru>
parents:
415
diff
changeset
|
1257 if (llcf->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
|
1258 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
|
1259 } |
c0552e5ab567
nginx-0.0.1-2003-11-09-23:03:38 import; separate building
Igor Sysoev <igor@sysoev.ru>
parents:
119
diff
changeset
|
1260 } |
99
a059e1aa65d4
nginx-0.0.1-2003-06-02-19:24:30 import
Igor Sysoev <igor@sysoev.ru>
parents:
69
diff
changeset
|
1261 |
393
5659d773cfa8
nginx-0.0.7-2004-07-15-20:35:51 import
Igor Sysoev <igor@sysoev.ru>
parents:
356
diff
changeset
|
1262 lmcf = ngx_http_conf_get_module_main_conf(cf, ngx_http_log_module); |
99
a059e1aa65d4
nginx-0.0.1-2003-06-02-19:24:30 import
Igor Sysoev <igor@sysoev.ru>
parents:
69
diff
changeset
|
1263 |
501 | 1264 log = ngx_array_push(llcf->logs); |
1265 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
|
1266 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
|
1267 } |
c0552e5ab567
nginx-0.0.1-2003-11-09-23:03:38 import; separate building
Igor Sysoev <igor@sysoev.ru>
parents:
119
diff
changeset
|
1268 |
2072 | 1269 ngx_memzero(log, sizeof(ngx_http_log_t)); |
1270 | |
5702
777202558122
Added syslog support for error_log and access_log directives.
Vladimir Homutov <vl@nginx.com>
parents:
5653
diff
changeset
|
1271 |
777202558122
Added syslog support for error_log and access_log directives.
Vladimir Homutov <vl@nginx.com>
parents:
5653
diff
changeset
|
1272 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
|
1273 |
777202558122
Added syslog support for error_log and access_log directives.
Vladimir Homutov <vl@nginx.com>
parents:
5653
diff
changeset
|
1274 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
|
1275 if (peer == NULL) { |
777202558122
Added syslog support for error_log and access_log directives.
Vladimir Homutov <vl@nginx.com>
parents:
5653
diff
changeset
|
1276 return NGX_CONF_ERROR; |
777202558122
Added syslog support for error_log and access_log directives.
Vladimir Homutov <vl@nginx.com>
parents:
5653
diff
changeset
|
1277 } |
777202558122
Added syslog support for error_log and access_log directives.
Vladimir Homutov <vl@nginx.com>
parents:
5653
diff
changeset
|
1278 |
777202558122
Added syslog support for error_log and access_log directives.
Vladimir Homutov <vl@nginx.com>
parents:
5653
diff
changeset
|
1279 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
|
1280 return NGX_CONF_ERROR; |
777202558122
Added syslog support for error_log and access_log directives.
Vladimir Homutov <vl@nginx.com>
parents:
5653
diff
changeset
|
1281 } |
777202558122
Added syslog support for error_log and access_log directives.
Vladimir Homutov <vl@nginx.com>
parents:
5653
diff
changeset
|
1282 |
777202558122
Added syslog support for error_log and access_log directives.
Vladimir Homutov <vl@nginx.com>
parents:
5653
diff
changeset
|
1283 log->syslog_peer = peer; |
777202558122
Added syslog support for error_log and access_log directives.
Vladimir Homutov <vl@nginx.com>
parents:
5653
diff
changeset
|
1284 |
777202558122
Added syslog support for error_log and access_log directives.
Vladimir Homutov <vl@nginx.com>
parents:
5653
diff
changeset
|
1285 goto process_formats; |
777202558122
Added syslog support for error_log and access_log directives.
Vladimir Homutov <vl@nginx.com>
parents:
5653
diff
changeset
|
1286 } |
777202558122
Added syslog support for error_log and access_log directives.
Vladimir Homutov <vl@nginx.com>
parents:
5653
diff
changeset
|
1287 |
2072 | 1288 n = ngx_http_script_variables_count(&value[1]); |
1289 | |
1290 if (n == 0) { | |
1291 log->file = ngx_conf_open_file(cf->cycle, &value[1]); | |
1292 if (log->file == NULL) { | |
1293 return NGX_CONF_ERROR; | |
1294 } | |
1295 | |
1296 } else { | |
5330
314c3d7cc3a5
Backed out f1a91825730a and 7094bd12c1ff.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5317
diff
changeset
|
1297 if (ngx_conf_full_name(cf->cycle, &value[1], 0) != NGX_OK) { |
2072 | 1298 return NGX_CONF_ERROR; |
1299 } | |
1300 | |
1301 log->script = ngx_pcalloc(cf->pool, sizeof(ngx_http_log_script_t)); | |
1302 if (log->script == NULL) { | |
1303 return NGX_CONF_ERROR; | |
1304 } | |
1305 | |
1306 ngx_memzero(&sc, sizeof(ngx_http_script_compile_t)); | |
1307 | |
1308 sc.cf = cf; | |
1309 sc.source = &value[1]; | |
1310 sc.lengths = &log->script->lengths; | |
1311 sc.values = &log->script->values; | |
1312 sc.variables = n; | |
1313 sc.complete_lengths = 1; | |
1314 sc.complete_values = 1; | |
1315 | |
1316 if (ngx_http_script_compile(&sc) != NGX_OK) { | |
1317 return NGX_CONF_ERROR; | |
1318 } | |
176
c0552e5ab567
nginx-0.0.1-2003-11-09-23:03:38 import; separate building
Igor Sysoev <igor@sysoev.ru>
parents:
119
diff
changeset
|
1319 } |
c0552e5ab567
nginx-0.0.1-2003-11-09-23:03:38 import; separate building
Igor Sysoev <igor@sysoev.ru>
parents:
119
diff
changeset
|
1320 |
5702
777202558122
Added syslog support for error_log and access_log directives.
Vladimir Homutov <vl@nginx.com>
parents:
5653
diff
changeset
|
1321 process_formats: |
777202558122
Added syslog support for error_log and access_log directives.
Vladimir Homutov <vl@nginx.com>
parents:
5653
diff
changeset
|
1322 |
571 | 1323 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
|
1324 name = value[2]; |
581 | 1325 |
1326 if (ngx_strcmp(name.data, "combined") == 0) { | |
1327 lmcf->combined_used = 1; | |
1328 } | |
1329 | |
176
c0552e5ab567
nginx-0.0.1-2003-11-09-23:03:38 import; separate building
Igor Sysoev <igor@sysoev.ru>
parents:
119
diff
changeset
|
1330 } else { |
3516
dd1570b6f237
ngx_str_set() and ngx_str_null()
Igor Sysoev <igor@sysoev.ru>
parents:
3515
diff
changeset
|
1331 ngx_str_set(&name, "combined"); |
573 | 1332 lmcf->combined_used = 1; |
176
c0552e5ab567
nginx-0.0.1-2003-11-09-23:03:38 import; separate building
Igor Sysoev <igor@sysoev.ru>
parents:
119
diff
changeset
|
1333 } |
c0552e5ab567
nginx-0.0.1-2003-11-09-23:03:38 import; separate building
Igor Sysoev <igor@sysoev.ru>
parents:
119
diff
changeset
|
1334 |
c0552e5ab567
nginx-0.0.1-2003-11-09-23:03:38 import; separate building
Igor Sysoev <igor@sysoev.ru>
parents:
119
diff
changeset
|
1335 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
|
1336 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
|
1337 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
|
1338 && 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
|
1339 { |
2261 | 1340 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
|
1341 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
|
1342 } |
c0552e5ab567
nginx-0.0.1-2003-11-09-23:03:38 import; separate building
Igor Sysoev <igor@sysoev.ru>
parents:
119
diff
changeset
|
1343 } |
100
7ebc8b7fb816
nginx-0.0.1-2003-06-03-19:42:58 import
Igor Sysoev <igor@sysoev.ru>
parents:
99
diff
changeset
|
1344 |
4986
3efc49b156d9
Access log: the "flush" parameter of the "access_log" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4985
diff
changeset
|
1345 if (log->format == NULL) { |
3efc49b156d9
Access log: the "flush" parameter of the "access_log" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4985
diff
changeset
|
1346 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
|
1347 "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
|
1348 return NGX_CONF_ERROR; |
3efc49b156d9
Access log: the "flush" parameter of the "access_log" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4985
diff
changeset
|
1349 } |
3efc49b156d9
Access log: the "flush" parameter of the "access_log" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4985
diff
changeset
|
1350 |
3efc49b156d9
Access log: the "flush" parameter of the "access_log" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4985
diff
changeset
|
1351 size = 0; |
3efc49b156d9
Access log: the "flush" parameter of the "access_log" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4985
diff
changeset
|
1352 flush = 0; |
4988
3849bb380605
Access log: the "gzip" parameter of the "access_log" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4986
diff
changeset
|
1353 gzip = 0; |
4986
3efc49b156d9
Access log: the "flush" parameter of the "access_log" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4985
diff
changeset
|
1354 |
3efc49b156d9
Access log: the "flush" parameter of the "access_log" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4985
diff
changeset
|
1355 for (i = 3; i < cf->args->nelts; i++) { |
487 | 1356 |
4986
3efc49b156d9
Access log: the "flush" parameter of the "access_log" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4985
diff
changeset
|
1357 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
|
1358 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
|
1359 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
|
1360 |
3efc49b156d9
Access log: the "flush" parameter of the "access_log" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4985
diff
changeset
|
1361 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
|
1362 |
3efc49b156d9
Access log: the "flush" parameter of the "access_log" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4985
diff
changeset
|
1363 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
|
1364 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
|
1365 "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
|
1366 return NGX_CONF_ERROR; |
3efc49b156d9
Access log: the "flush" parameter of the "access_log" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4985
diff
changeset
|
1367 } |
3efc49b156d9
Access log: the "flush" parameter of the "access_log" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4985
diff
changeset
|
1368 |
3efc49b156d9
Access log: the "flush" parameter of the "access_log" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4985
diff
changeset
|
1369 continue; |
3efc49b156d9
Access log: the "flush" parameter of the "access_log" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4985
diff
changeset
|
1370 } |
571 | 1371 |
4986
3efc49b156d9
Access log: the "flush" parameter of the "access_log" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4985
diff
changeset
|
1372 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
|
1373 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
|
1374 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
|
1375 |
3efc49b156d9
Access log: the "flush" parameter of the "access_log" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4985
diff
changeset
|
1376 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
|
1377 |
3efc49b156d9
Access log: the "flush" parameter of the "access_log" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4985
diff
changeset
|
1378 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
|
1379 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
|
1380 "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
|
1381 return NGX_CONF_ERROR; |
3efc49b156d9
Access log: the "flush" parameter of the "access_log" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4985
diff
changeset
|
1382 } |
3efc49b156d9
Access log: the "flush" parameter of the "access_log" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4985
diff
changeset
|
1383 |
3efc49b156d9
Access log: the "flush" parameter of the "access_log" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4985
diff
changeset
|
1384 continue; |
571 | 1385 } |
1386 | |
4988
3849bb380605
Access log: the "gzip" parameter of the "access_log" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4986
diff
changeset
|
1387 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
|
1388 && (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
|
1389 { |
3849bb380605
Access log: the "gzip" parameter of the "access_log" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4986
diff
changeset
|
1390 #if (NGX_ZLIB) |
3849bb380605
Access log: the "gzip" parameter of the "access_log" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4986
diff
changeset
|
1391 if (size == 0) { |
3849bb380605
Access log: the "gzip" parameter of the "access_log" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4986
diff
changeset
|
1392 size = 64 * 1024; |
3849bb380605
Access log: the "gzip" parameter of the "access_log" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4986
diff
changeset
|
1393 } |
3849bb380605
Access log: the "gzip" parameter of the "access_log" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4986
diff
changeset
|
1394 |
3849bb380605
Access log: the "gzip" parameter of the "access_log" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4986
diff
changeset
|
1395 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
|
1396 gzip = Z_BEST_SPEED; |
3849bb380605
Access log: the "gzip" parameter of the "access_log" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4986
diff
changeset
|
1397 continue; |
3849bb380605
Access log: the "gzip" parameter of the "access_log" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4986
diff
changeset
|
1398 } |
3849bb380605
Access log: the "gzip" parameter of the "access_log" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4986
diff
changeset
|
1399 |
3849bb380605
Access log: the "gzip" parameter of the "access_log" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4986
diff
changeset
|
1400 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
|
1401 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
|
1402 |
3849bb380605
Access log: the "gzip" parameter of the "access_log" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4986
diff
changeset
|
1403 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
|
1404 |
3849bb380605
Access log: the "gzip" parameter of the "access_log" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4986
diff
changeset
|
1405 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
|
1406 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
|
1407 "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
|
1408 return NGX_CONF_ERROR; |
3849bb380605
Access log: the "gzip" parameter of the "access_log" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4986
diff
changeset
|
1409 } |
3849bb380605
Access log: the "gzip" parameter of the "access_log" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4986
diff
changeset
|
1410 |
3849bb380605
Access log: the "gzip" parameter of the "access_log" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4986
diff
changeset
|
1411 continue; |
3849bb380605
Access log: the "gzip" parameter of the "access_log" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4986
diff
changeset
|
1412 |
3849bb380605
Access log: the "gzip" parameter of the "access_log" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4986
diff
changeset
|
1413 #else |
3849bb380605
Access log: the "gzip" parameter of the "access_log" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4986
diff
changeset
|
1414 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
|
1415 "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
|
1416 return NGX_CONF_ERROR; |
3849bb380605
Access log: the "gzip" parameter of the "access_log" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4986
diff
changeset
|
1417 #endif |
3849bb380605
Access log: the "gzip" parameter of the "access_log" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4986
diff
changeset
|
1418 } |
3849bb380605
Access log: the "gzip" parameter of the "access_log" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4986
diff
changeset
|
1419 |
5653
cb308813b453
Access log: the "if" parameter of the "access_log" directive.
Sergey Kandaurov <pluknet@nginx.com>
parents:
5361
diff
changeset
|
1420 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
|
1421 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
|
1422 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
|
1423 |
e3016ee8dba3
Access log: fixed the "if=" parameter with buffering (ticket #625).
Valentin Bartenev <vbart@nginx.com>
parents:
5799
diff
changeset
|
1424 ngx_memzero(&ccv, sizeof(ngx_http_compile_complex_value_t)); |
e3016ee8dba3
Access log: fixed the "if=" parameter with buffering (ticket #625).
Valentin Bartenev <vbart@nginx.com>
parents:
5799
diff
changeset
|
1425 |
e3016ee8dba3
Access log: fixed the "if=" parameter with buffering (ticket #625).
Valentin Bartenev <vbart@nginx.com>
parents:
5799
diff
changeset
|
1426 ccv.cf = cf; |
e3016ee8dba3
Access log: fixed the "if=" parameter with buffering (ticket #625).
Valentin Bartenev <vbart@nginx.com>
parents:
5799
diff
changeset
|
1427 ccv.value = &s; |
e3016ee8dba3
Access log: fixed the "if=" parameter with buffering (ticket #625).
Valentin Bartenev <vbart@nginx.com>
parents:
5799
diff
changeset
|
1428 ccv.complex_value = ngx_palloc(cf->pool, |
e3016ee8dba3
Access log: fixed the "if=" parameter with buffering (ticket #625).
Valentin Bartenev <vbart@nginx.com>
parents:
5799
diff
changeset
|
1429 sizeof(ngx_http_complex_value_t)); |
e3016ee8dba3
Access log: fixed the "if=" parameter with buffering (ticket #625).
Valentin Bartenev <vbart@nginx.com>
parents:
5799
diff
changeset
|
1430 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
|
1431 return NGX_CONF_ERROR; |
e3016ee8dba3
Access log: fixed the "if=" parameter with buffering (ticket #625).
Valentin Bartenev <vbart@nginx.com>
parents:
5799
diff
changeset
|
1432 } |
e3016ee8dba3
Access log: fixed the "if=" parameter with buffering (ticket #625).
Valentin Bartenev <vbart@nginx.com>
parents:
5799
diff
changeset
|
1433 |
e3016ee8dba3
Access log: fixed the "if=" parameter with buffering (ticket #625).
Valentin Bartenev <vbart@nginx.com>
parents:
5799
diff
changeset
|
1434 if (ngx_http_compile_complex_value(&ccv) != NGX_OK) { |
e3016ee8dba3
Access log: fixed the "if=" parameter with buffering (ticket #625).
Valentin Bartenev <vbart@nginx.com>
parents:
5799
diff
changeset
|
1435 return NGX_CONF_ERROR; |
e3016ee8dba3
Access log: fixed the "if=" parameter with buffering (ticket #625).
Valentin Bartenev <vbart@nginx.com>
parents:
5799
diff
changeset
|
1436 } |
e3016ee8dba3
Access log: fixed the "if=" parameter with buffering (ticket #625).
Valentin Bartenev <vbart@nginx.com>
parents:
5799
diff
changeset
|
1437 |
e3016ee8dba3
Access log: fixed the "if=" parameter with buffering (ticket #625).
Valentin Bartenev <vbart@nginx.com>
parents:
5799
diff
changeset
|
1438 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
|
1439 |
5653
cb308813b453
Access log: the "if" parameter of the "access_log" directive.
Sergey Kandaurov <pluknet@nginx.com>
parents:
5361
diff
changeset
|
1440 continue; |
cb308813b453
Access log: the "if" parameter of the "access_log" directive.
Sergey Kandaurov <pluknet@nginx.com>
parents:
5361
diff
changeset
|
1441 } |
cb308813b453
Access log: the "if" parameter of the "access_log" directive.
Sergey Kandaurov <pluknet@nginx.com>
parents:
5361
diff
changeset
|
1442 |
4986
3efc49b156d9
Access log: the "flush" parameter of the "access_log" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4985
diff
changeset
|
1443 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
|
1444 "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
|
1445 return NGX_CONF_ERROR; |
3efc49b156d9
Access log: the "flush" parameter of the "access_log" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4985
diff
changeset
|
1446 } |
3efc49b156d9
Access log: the "flush" parameter of the "access_log" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4985
diff
changeset
|
1447 |
3efc49b156d9
Access log: the "flush" parameter of the "access_log" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4985
diff
changeset
|
1448 if (flush && size == 0) { |
3efc49b156d9
Access log: the "flush" parameter of the "access_log" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4985
diff
changeset
|
1449 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
|
1450 "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
|
1451 &value[1]); |
3efc49b156d9
Access log: the "flush" parameter of the "access_log" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4985
diff
changeset
|
1452 return NGX_CONF_ERROR; |
3efc49b156d9
Access log: the "flush" parameter of the "access_log" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4985
diff
changeset
|
1453 } |
3efc49b156d9
Access log: the "flush" parameter of the "access_log" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4985
diff
changeset
|
1454 |
3efc49b156d9
Access log: the "flush" parameter of the "access_log" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4985
diff
changeset
|
1455 if (size) { |
3efc49b156d9
Access log: the "flush" parameter of the "access_log" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4985
diff
changeset
|
1456 |
2072 | 1457 if (log->script) { |
1458 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
|
1459 "buffered logs cannot have variables in name"); |
2072 | 1460 return NGX_CONF_ERROR; |
1461 } | |
1462 | |
5799
b1f8285297a7
Access log: allowed logs to syslog with "if=" (ticket #596).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5719
diff
changeset
|
1463 if (log->syslog_peer) { |
b1f8285297a7
Access log: allowed logs to syslog with "if=" (ticket #596).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5719
diff
changeset
|
1464 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
|
1465 "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
|
1466 return NGX_CONF_ERROR; |
b1f8285297a7
Access log: allowed logs to syslog with "if=" (ticket #596).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5719
diff
changeset
|
1467 } |
b1f8285297a7
Access log: allowed logs to syslog with "if=" (ticket #596).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5719
diff
changeset
|
1468 |
4985
a0599b56e748
Reopening log files code moved to a separate function.
Valentin Bartenev <vbart@nginx.com>
parents:
4984
diff
changeset
|
1469 if (log->file->data) { |
a0599b56e748
Reopening log files code moved to a separate function.
Valentin Bartenev <vbart@nginx.com>
parents:
4984
diff
changeset
|
1470 buffer = log->file->data; |
a0599b56e748
Reopening log files code moved to a separate function.
Valentin Bartenev <vbart@nginx.com>
parents:
4984
diff
changeset
|
1471 |
4986
3efc49b156d9
Access log: the "flush" parameter of the "access_log" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4985
diff
changeset
|
1472 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
|
1473 || buffer->flush != flush |
3849bb380605
Access log: the "gzip" parameter of the "access_log" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4986
diff
changeset
|
1474 || buffer->gzip != gzip) |
4986
3efc49b156d9
Access log: the "flush" parameter of the "access_log" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4985
diff
changeset
|
1475 { |
4984
7737f0d788c1
Access log: fixed redundant buffer reallocation.
Valentin Bartenev <vbart@nginx.com>
parents:
4893
diff
changeset
|
1476 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
|
1477 "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
|
1478 "with conflicting parameters", |
3efc49b156d9
Access log: the "flush" parameter of the "access_log" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4985
diff
changeset
|
1479 &value[1]); |
4984
7737f0d788c1
Access log: fixed redundant buffer reallocation.
Valentin Bartenev <vbart@nginx.com>
parents:
4893
diff
changeset
|
1480 return NGX_CONF_ERROR; |
7737f0d788c1
Access log: fixed redundant buffer reallocation.
Valentin Bartenev <vbart@nginx.com>
parents:
4893
diff
changeset
|
1481 } |
7737f0d788c1
Access log: fixed redundant buffer reallocation.
Valentin Bartenev <vbart@nginx.com>
parents:
4893
diff
changeset
|
1482 |
7737f0d788c1
Access log: fixed redundant buffer reallocation.
Valentin Bartenev <vbart@nginx.com>
parents:
4893
diff
changeset
|
1483 return NGX_CONF_OK; |
571 | 1484 } |
1485 | |
4985
a0599b56e748
Reopening log files code moved to a separate function.
Valentin Bartenev <vbart@nginx.com>
parents:
4984
diff
changeset
|
1486 buffer = ngx_pcalloc(cf->pool, sizeof(ngx_http_log_buf_t)); |
a0599b56e748
Reopening log files code moved to a separate function.
Valentin Bartenev <vbart@nginx.com>
parents:
4984
diff
changeset
|
1487 if (buffer == NULL) { |
571 | 1488 return NGX_CONF_ERROR; |
1489 } | |
1490 | |
4985
a0599b56e748
Reopening log files code moved to a separate function.
Valentin Bartenev <vbart@nginx.com>
parents:
4984
diff
changeset
|
1491 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
|
1492 if (buffer->start == NULL) { |
a0599b56e748
Reopening log files code moved to a separate function.
Valentin Bartenev <vbart@nginx.com>
parents:
4984
diff
changeset
|
1493 return NGX_CONF_ERROR; |
a0599b56e748
Reopening log files code moved to a separate function.
Valentin Bartenev <vbart@nginx.com>
parents:
4984
diff
changeset
|
1494 } |
a0599b56e748
Reopening log files code moved to a separate function.
Valentin Bartenev <vbart@nginx.com>
parents:
4984
diff
changeset
|
1495 |
a0599b56e748
Reopening log files code moved to a separate function.
Valentin Bartenev <vbart@nginx.com>
parents:
4984
diff
changeset
|
1496 buffer->pos = buffer->start; |
a0599b56e748
Reopening log files code moved to a separate function.
Valentin Bartenev <vbart@nginx.com>
parents:
4984
diff
changeset
|
1497 buffer->last = buffer->start + size; |
a0599b56e748
Reopening log files code moved to a separate function.
Valentin Bartenev <vbart@nginx.com>
parents:
4984
diff
changeset
|
1498 |
4986
3efc49b156d9
Access log: the "flush" parameter of the "access_log" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4985
diff
changeset
|
1499 if (flush) { |
3efc49b156d9
Access log: the "flush" parameter of the "access_log" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4985
diff
changeset
|
1500 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
|
1501 if (buffer->event == NULL) { |
3efc49b156d9
Access log: the "flush" parameter of the "access_log" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4985
diff
changeset
|
1502 return NGX_CONF_ERROR; |
3efc49b156d9
Access log: the "flush" parameter of the "access_log" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4985
diff
changeset
|
1503 } |
3efc49b156d9
Access log: the "flush" parameter of the "access_log" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4985
diff
changeset
|
1504 |
3efc49b156d9
Access log: the "flush" parameter of the "access_log" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4985
diff
changeset
|
1505 buffer->event->data = log->file; |
3efc49b156d9
Access log: the "flush" parameter of the "access_log" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4985
diff
changeset
|
1506 buffer->event->handler = ngx_http_log_flush_handler; |
3efc49b156d9
Access log: the "flush" parameter of the "access_log" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4985
diff
changeset
|
1507 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
|
1508 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
|
1509 |
3efc49b156d9
Access log: the "flush" parameter of the "access_log" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4985
diff
changeset
|
1510 buffer->flush = flush; |
3efc49b156d9
Access log: the "flush" parameter of the "access_log" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4985
diff
changeset
|
1511 } |
3efc49b156d9
Access log: the "flush" parameter of the "access_log" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4985
diff
changeset
|
1512 |
4988
3849bb380605
Access log: the "gzip" parameter of the "access_log" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4986
diff
changeset
|
1513 buffer->gzip = gzip; |
3849bb380605
Access log: the "gzip" parameter of the "access_log" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4986
diff
changeset
|
1514 |
4985
a0599b56e748
Reopening log files code moved to a separate function.
Valentin Bartenev <vbart@nginx.com>
parents:
4984
diff
changeset
|
1515 log->file->flush = ngx_http_log_flush; |
a0599b56e748
Reopening log files code moved to a separate function.
Valentin Bartenev <vbart@nginx.com>
parents:
4984
diff
changeset
|
1516 log->file->data = buffer; |
571 | 1517 } |
1518 | |
1519 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
|
1520 } |
176
c0552e5ab567
nginx-0.0.1-2003-11-09-23:03:38 import; separate building
Igor Sysoev <igor@sysoev.ru>
parents:
119
diff
changeset
|
1521 |
c0552e5ab567
nginx-0.0.1-2003-11-09-23:03:38 import; separate building
Igor Sysoev <igor@sysoev.ru>
parents:
119
diff
changeset
|
1522 |
497 | 1523 static char * |
1524 ngx_http_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
|
1525 { |
c0552e5ab567
nginx-0.0.1-2003-11-09-23:03:38 import; separate building
Igor Sysoev <igor@sysoev.ru>
parents:
119
diff
changeset
|
1526 ngx_http_log_main_conf_t *lmcf = conf; |
c0552e5ab567
nginx-0.0.1-2003-11-09-23:03:38 import; separate building
Igor Sysoev <igor@sysoev.ru>
parents:
119
diff
changeset
|
1527 |
573 | 1528 ngx_str_t *value; |
1529 ngx_uint_t i; | |
1530 ngx_http_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
|
1531 |
c0552e5ab567
nginx-0.0.1-2003-11-09-23:03:38 import; separate building
Igor Sysoev <igor@sysoev.ru>
parents:
119
diff
changeset
|
1532 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
|
1533 |
c0552e5ab567
nginx-0.0.1-2003-11-09-23:03:38 import; separate building
Igor Sysoev <igor@sysoev.ru>
parents:
119
diff
changeset
|
1534 fmt = lmcf->formats.elts; |
573 | 1535 for (i = 0; i < lmcf->formats.nelts; i++) { |
1536 if (fmt[i].name.len == value[1].len | |
1537 && 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
|
1538 { |
2036 | 1539 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, |
1540 "duplicate \"log_format\" name \"%V\"", | |
1541 &value[1]); | |
1542 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
|
1543 } |
c0552e5ab567
nginx-0.0.1-2003-11-09-23:03:38 import; separate building
Igor Sysoev <igor@sysoev.ru>
parents:
119
diff
changeset
|
1544 } |
c0552e5ab567
nginx-0.0.1-2003-11-09-23:03:38 import; separate building
Igor Sysoev <igor@sysoev.ru>
parents:
119
diff
changeset
|
1545 |
501 | 1546 fmt = ngx_array_push(&lmcf->formats); |
1547 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
|
1548 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
|
1549 } |
c0552e5ab567
nginx-0.0.1-2003-11-09-23:03:38 import; separate building
Igor Sysoev <igor@sysoev.ru>
parents:
119
diff
changeset
|
1550 |
c0552e5ab567
nginx-0.0.1-2003-11-09-23:03:38 import; separate building
Igor Sysoev <igor@sysoev.ru>
parents:
119
diff
changeset
|
1551 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
|
1552 |
2261 | 1553 fmt->flushes = ngx_array_create(cf->pool, 4, sizeof(ngx_int_t)); |
1554 if (fmt->flushes == NULL) { | |
1555 return NGX_CONF_ERROR; | |
1556 } | |
1557 | |
573 | 1558 fmt->ops = ngx_array_create(cf->pool, 16, sizeof(ngx_http_log_op_t)); |
501 | 1559 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
|
1560 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
|
1561 } |
c0552e5ab567
nginx-0.0.1-2003-11-09-23:03:38 import; separate building
Igor Sysoev <igor@sysoev.ru>
parents:
119
diff
changeset
|
1562 |
2261 | 1563 return ngx_http_log_compile_format(cf, fmt->flushes, fmt->ops, cf->args, 2); |
573 | 1564 } |
1565 | |
176
c0552e5ab567
nginx-0.0.1-2003-11-09-23:03:38 import; separate building
Igor Sysoev <igor@sysoev.ru>
parents:
119
diff
changeset
|
1566 |
573 | 1567 static char * |
2261 | 1568 ngx_http_log_compile_format(ngx_conf_t *cf, ngx_array_t *flushes, |
1569 ngx_array_t *ops, ngx_array_t *args, ngx_uint_t s) | |
573 | 1570 { |
880 | 1571 u_char *data, *p, ch; |
1572 size_t i, len; | |
1573 ngx_str_t *value, var; | |
2261 | 1574 ngx_int_t *flush; |
7223
265c29b0b8b8
Access log: support for disabling escaping (ticket #1450).
Vladimir Homutov <vl@nginx.com>
parents:
6948
diff
changeset
|
1575 ngx_uint_t bracket, escape; |
880 | 1576 ngx_http_log_op_t *op; |
1577 ngx_http_log_var_t *v; | |
573 | 1578 |
7223
265c29b0b8b8
Access log: support for disabling escaping (ticket #1450).
Vladimir Homutov <vl@nginx.com>
parents:
6948
diff
changeset
|
1579 escape = NGX_HTTP_LOG_ESCAPE_DEFAULT; |
573 | 1580 value = args->elts; |
1581 | |
6840
0cf4e82e7c48
Access log: support for json escaping.
Valentin Bartenev <vbart@nginx.com>
parents:
6626
diff
changeset
|
1582 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:
6626
diff
changeset
|
1583 data = value[s].data + 7; |
0cf4e82e7c48
Access log: support for json escaping.
Valentin Bartenev <vbart@nginx.com>
parents:
6626
diff
changeset
|
1584 |
0cf4e82e7c48
Access log: support for json escaping.
Valentin Bartenev <vbart@nginx.com>
parents:
6626
diff
changeset
|
1585 if (ngx_strcmp(data, "json") == 0) { |
7223
265c29b0b8b8
Access log: support for disabling escaping (ticket #1450).
Vladimir Homutov <vl@nginx.com>
parents:
6948
diff
changeset
|
1586 escape = NGX_HTTP_LOG_ESCAPE_JSON; |
265c29b0b8b8
Access log: support for disabling escaping (ticket #1450).
Vladimir Homutov <vl@nginx.com>
parents:
6948
diff
changeset
|
1587 |
265c29b0b8b8
Access log: support for disabling escaping (ticket #1450).
Vladimir Homutov <vl@nginx.com>
parents:
6948
diff
changeset
|
1588 } else if (ngx_strcmp(data, "none") == 0) { |
265c29b0b8b8
Access log: support for disabling escaping (ticket #1450).
Vladimir Homutov <vl@nginx.com>
parents:
6948
diff
changeset
|
1589 escape = NGX_HTTP_LOG_ESCAPE_NONE; |
6840
0cf4e82e7c48
Access log: support for json escaping.
Valentin Bartenev <vbart@nginx.com>
parents:
6626
diff
changeset
|
1590 |
0cf4e82e7c48
Access log: support for json escaping.
Valentin Bartenev <vbart@nginx.com>
parents:
6626
diff
changeset
|
1591 } else if (ngx_strcmp(data, "default") != 0) { |
0cf4e82e7c48
Access log: support for json escaping.
Valentin Bartenev <vbart@nginx.com>
parents:
6626
diff
changeset
|
1592 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, |
0cf4e82e7c48
Access log: support for json escaping.
Valentin Bartenev <vbart@nginx.com>
parents:
6626
diff
changeset
|
1593 "unknown log format escaping \"%s\"", data); |
0cf4e82e7c48
Access log: support for json escaping.
Valentin Bartenev <vbart@nginx.com>
parents:
6626
diff
changeset
|
1594 return NGX_CONF_ERROR; |
0cf4e82e7c48
Access log: support for json escaping.
Valentin Bartenev <vbart@nginx.com>
parents:
6626
diff
changeset
|
1595 } |
0cf4e82e7c48
Access log: support for json escaping.
Valentin Bartenev <vbart@nginx.com>
parents:
6626
diff
changeset
|
1596 |
0cf4e82e7c48
Access log: support for json escaping.
Valentin Bartenev <vbart@nginx.com>
parents:
6626
diff
changeset
|
1597 s++; |
0cf4e82e7c48
Access log: support for json escaping.
Valentin Bartenev <vbart@nginx.com>
parents:
6626
diff
changeset
|
1598 } |
0cf4e82e7c48
Access log: support for json escaping.
Valentin Bartenev <vbart@nginx.com>
parents:
6626
diff
changeset
|
1599 |
573 | 1600 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
|
1601 |
c0552e5ab567
nginx-0.0.1-2003-11-09-23:03:38 import; separate building
Igor Sysoev <igor@sysoev.ru>
parents:
119
diff
changeset
|
1602 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
|
1603 |
c0552e5ab567
nginx-0.0.1-2003-11-09-23:03:38 import; separate building
Igor Sysoev <igor@sysoev.ru>
parents:
119
diff
changeset
|
1604 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
|
1605 |
573 | 1606 op = ngx_array_push(ops); |
501 | 1607 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
|
1608 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
|
1609 } |
c0552e5ab567
nginx-0.0.1-2003-11-09-23:03:38 import; separate building
Igor Sysoev <igor@sysoev.ru>
parents:
119
diff
changeset
|
1610 |
c0552e5ab567
nginx-0.0.1-2003-11-09-23:03:38 import; separate building
Igor Sysoev <igor@sysoev.ru>
parents:
119
diff
changeset
|
1611 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
|
1612 |
880 | 1613 if (value[s].data[i] == '$') { |
569 | 1614 |
1615 if (++i == value[s].len) { | |
1616 goto invalid; | |
1617 } | |
1618 | |
1619 if (value[s].data[i] == '{') { | |
1620 bracket = 1; | |
1621 | |
1622 if (++i == value[s].len) { | |
1623 goto invalid; | |
1624 } | |
1625 | |
1626 var.data = &value[s].data[i]; | |
1627 | |
1628 } else { | |
1629 bracket = 0; | |
1630 var.data = &value[s].data[i]; | |
1631 } | |
1632 | |
1633 for (var.len = 0; i < value[s].len; i++, var.len++) { | |
1634 ch = value[s].data[i]; | |
1635 | |
1636 if (ch == '}' && bracket) { | |
1637 i++; | |
1638 bracket = 0; | |
1639 break; | |
1640 } | |
1641 | |
1642 if ((ch >= 'A' && ch <= 'Z') | |
1643 || (ch >= 'a' && ch <= 'z') | |
1644 || (ch >= '0' && ch <= '9') | |
1645 || ch == '_') | |
1646 { | |
1647 continue; | |
1648 } | |
1649 | |
176
c0552e5ab567
nginx-0.0.1-2003-11-09-23:03:38 import; separate building
Igor Sysoev <igor@sysoev.ru>
parents:
119
diff
changeset
|
1650 break; |
c0552e5ab567
nginx-0.0.1-2003-11-09-23:03:38 import; separate building
Igor Sysoev <igor@sysoev.ru>
parents:
119
diff
changeset
|
1651 } |
c0552e5ab567
nginx-0.0.1-2003-11-09-23:03:38 import; separate building
Igor Sysoev <igor@sysoev.ru>
parents:
119
diff
changeset
|
1652 |
569 | 1653 if (bracket) { |
1654 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, | |
1655 "the closing bracket in \"%V\" " | |
1656 "variable is missing", &var); | |
1657 return NGX_CONF_ERROR; | |
1658 } | |
1659 | |
1660 if (var.len == 0) { | |
1661 goto invalid; | |
1662 } | |
1663 | |
573 | 1664 for (v = ngx_http_log_vars; v->name.len; v++) { |
1665 | |
1666 if (v->name.len == var.len | |
1667 && ngx_strncmp(v->name.data, var.data, var.len) == 0) | |
1668 { | |
1669 op->len = v->len; | |
1670 op->getlen = NULL; | |
1671 op->run = v->run; | |
1672 op->data = 0; | |
1673 | |
1674 goto found; | |
1675 } | |
1676 } | |
1677 | |
7223
265c29b0b8b8
Access log: support for disabling escaping (ticket #1450).
Vladimir Homutov <vl@nginx.com>
parents:
6948
diff
changeset
|
1678 if (ngx_http_log_variable_compile(cf, op, &var, escape) |
6840
0cf4e82e7c48
Access log: support for json escaping.
Valentin Bartenev <vbart@nginx.com>
parents:
6626
diff
changeset
|
1679 != NGX_OK) |
0cf4e82e7c48
Access log: support for json escaping.
Valentin Bartenev <vbart@nginx.com>
parents:
6626
diff
changeset
|
1680 { |
569 | 1681 return NGX_CONF_ERROR; |
1682 } | |
1683 | |
2261 | 1684 if (flushes) { |
1685 | |
1686 flush = ngx_array_push(flushes); | |
1687 if (flush == NULL) { | |
1688 return NGX_CONF_ERROR; | |
1689 } | |
1690 | |
1691 *flush = op->data; /* variable index */ | |
1692 } | |
1693 | |
573 | 1694 found: |
1695 | |
1696 continue; | |
1697 } | |
1698 | |
1699 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
|
1700 |
880 | 1701 while (i < value[s].len && value[s].data[i] != '$') { |
573 | 1702 i++; |
1703 } | |
176
c0552e5ab567
nginx-0.0.1-2003-11-09-23:03:38 import; separate building
Igor Sysoev <igor@sysoev.ru>
parents:
119
diff
changeset
|
1704 |
573 | 1705 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
|
1706 |
573 | 1707 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
|
1708 |
573 | 1709 op->len = len; |
1710 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
|
1711 |
573 | 1712 if (len <= sizeof(uintptr_t)) { |
1713 op->run = ngx_http_log_copy_short; | |
1714 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
|
1715 |
573 | 1716 while (len--) { |
1717 op->data <<= 8; | |
1718 op->data |= data[len]; | |
1719 } | |
1720 | |
1721 } else { | |
1722 op->run = ngx_http_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
|
1723 |
2049 | 1724 p = ngx_pnalloc(cf->pool, len); |
573 | 1725 if (p == NULL) { |
1726 return NGX_CONF_ERROR; | |
1727 } | |
176
c0552e5ab567
nginx-0.0.1-2003-11-09-23:03:38 import; separate building
Igor Sysoev <igor@sysoev.ru>
parents:
119
diff
changeset
|
1728 |
573 | 1729 ngx_memcpy(p, data, len); |
1730 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
|
1731 } |
c0552e5ab567
nginx-0.0.1-2003-11-09-23:03:38 import; separate building
Igor Sysoev <igor@sysoev.ru>
parents:
119
diff
changeset
|
1732 } |
c0552e5ab567
nginx-0.0.1-2003-11-09-23:03:38 import; separate building
Igor Sysoev <igor@sysoev.ru>
parents:
119
diff
changeset
|
1733 } |
c0552e5ab567
nginx-0.0.1-2003-11-09-23:03:38 import; separate building
Igor Sysoev <igor@sysoev.ru>
parents:
119
diff
changeset
|
1734 } |
c0552e5ab567
nginx-0.0.1-2003-11-09-23:03:38 import; separate building
Igor Sysoev <igor@sysoev.ru>
parents:
119
diff
changeset
|
1735 |
569 | 1736 return NGX_CONF_OK; |
1737 | |
1738 invalid: | |
1739 | |
1740 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, "invalid parameter \"%s\"", data); | |
1741 | |
1742 return NGX_CONF_ERROR; | |
1743 } | |
1744 | |
176
c0552e5ab567
nginx-0.0.1-2003-11-09-23:03:38 import; separate building
Igor Sysoev <igor@sysoev.ru>
parents:
119
diff
changeset
|
1745 |
2072 | 1746 static char * |
1747 ngx_http_log_open_file_cache(ngx_conf_t *cf, ngx_command_t *cmd, void *conf) | |
1748 { | |
1749 ngx_http_log_loc_conf_t *llcf = conf; | |
1750 | |
1751 time_t inactive, valid; | |
1752 ngx_str_t *value, s; | |
1753 ngx_int_t max, min_uses; | |
1754 ngx_uint_t i; | |
1755 | |
1756 if (llcf->open_file_cache != NGX_CONF_UNSET_PTR) { | |
1757 return "is duplicate"; | |
1758 } | |
1759 | |
1760 value = cf->args->elts; | |
1761 | |
1762 max = 0; | |
1763 inactive = 10; | |
1764 valid = 60; | |
1765 min_uses = 1; | |
1766 | |
1767 for (i = 1; i < cf->args->nelts; i++) { | |
1768 | |
1769 if (ngx_strncmp(value[i].data, "max=", 4) == 0) { | |
1770 | |
1771 max = ngx_atoi(value[i].data + 4, value[i].len - 4); | |
1772 if (max == NGX_ERROR) { | |
1773 goto failed; | |
1774 } | |
1775 | |
1776 continue; | |
1777 } | |
1778 | |
1779 if (ngx_strncmp(value[i].data, "inactive=", 9) == 0) { | |
1780 | |
1781 s.len = value[i].len - 9; | |
1782 s.data = value[i].data + 9; | |
1783 | |
1784 inactive = ngx_parse_time(&s, 1); | |
4474 | 1785 if (inactive == (time_t) NGX_ERROR) { |
2072 | 1786 goto failed; |
1787 } | |
1788 | |
1789 continue; | |
1790 } | |
1791 | |
1792 if (ngx_strncmp(value[i].data, "min_uses=", 9) == 0) { | |
1793 | |
1794 min_uses = ngx_atoi(value[i].data + 9, value[i].len - 9); | |
1795 if (min_uses == NGX_ERROR) { | |
1796 goto failed; | |
1797 } | |
1798 | |
1799 continue; | |
1800 } | |
1801 | |
1802 if (ngx_strncmp(value[i].data, "valid=", 6) == 0) { | |
1803 | |
1804 s.len = value[i].len - 6; | |
1805 s.data = value[i].data + 6; | |
1806 | |
1807 valid = ngx_parse_time(&s, 1); | |
4474 | 1808 if (valid == (time_t) NGX_ERROR) { |
2072 | 1809 goto failed; |
1810 } | |
1811 | |
1812 continue; | |
1813 } | |
1814 | |
1815 if (ngx_strcmp(value[i].data, "off") == 0) { | |
1816 | |
1817 llcf->open_file_cache = NULL; | |
1818 | |
1819 continue; | |
1820 } | |
1821 | |
1822 failed: | |
1823 | |
1824 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, | |
1825 "invalid \"open_log_file_cache\" parameter \"%V\"", | |
1826 &value[i]); | |
1827 return NGX_CONF_ERROR; | |
1828 } | |
1829 | |
1830 if (llcf->open_file_cache == NULL) { | |
1831 return NGX_CONF_OK; | |
1832 } | |
1833 | |
1834 if (max == 0) { | |
1835 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, | |
1836 "\"open_log_file_cache\" must have \"max\" parameter"); | |
1837 return NGX_CONF_ERROR; | |
1838 } | |
1839 | |
1840 llcf->open_file_cache = ngx_open_file_cache_init(cf->pool, max, inactive); | |
1841 | |
1842 if (llcf->open_file_cache) { | |
1843 | |
1844 llcf->open_file_cache_valid = valid; | |
1845 llcf->open_file_cache_min_uses = min_uses; | |
1846 | |
1847 return NGX_CONF_OK; | |
1848 } | |
1849 | |
1850 return NGX_CONF_ERROR; | |
1851 } | |
1852 | |
1853 | |
569 | 1854 static ngx_int_t |
573 | 1855 ngx_http_log_init(ngx_conf_t *cf) |
569 | 1856 { |
573 | 1857 ngx_str_t *value; |
1858 ngx_array_t a; | |
581 | 1859 ngx_http_handler_pt *h; |
573 | 1860 ngx_http_log_fmt_t *fmt; |
1861 ngx_http_log_main_conf_t *lmcf; | |
569 | 1862 ngx_http_core_main_conf_t *cmcf; |
1863 | |
573 | 1864 lmcf = ngx_http_conf_get_module_main_conf(cf, ngx_http_log_module); |
1865 | |
1866 if (lmcf->combined_used) { | |
1867 if (ngx_array_init(&a, cf->pool, 1, sizeof(ngx_str_t)) != NGX_OK) { | |
1868 return NGX_ERROR; | |
1869 } | |
1870 | |
1871 value = ngx_array_push(&a); | |
1872 if (value == NULL) { | |
1873 return NGX_ERROR; | |
1874 } | |
1875 | |
1876 *value = ngx_http_combined_fmt; | |
1877 fmt = lmcf->formats.elts; | |
1878 | |
2261 | 1879 if (ngx_http_log_compile_format(cf, NULL, fmt->ops, &a, 0) |
573 | 1880 != NGX_CONF_OK) |
1881 { | |
1882 return NGX_ERROR; | |
1883 } | |
1884 } | |
1885 | |
1886 cmcf = ngx_http_conf_get_module_main_conf(cf, ngx_http_core_module); | |
569 | 1887 |
581 | 1888 h = ngx_array_push(&cmcf->phases[NGX_HTTP_LOG_PHASE].handlers); |
1889 if (h == NULL) { | |
1890 return NGX_ERROR; | |
1891 } | |
1892 | |
1893 *h = ngx_http_log_handler; | |
569 | 1894 |
1895 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
|
1896 } |