Mercurial > hg > nginx
comparison src/http/modules/ngx_http_log_module.c @ 5653:cb308813b453
Access log: the "if" parameter of the "access_log" directive.
The parameter value specifies a condition under which the request is logged.
author | Sergey Kandaurov <pluknet@nginx.com> |
---|---|
date | Tue, 15 Apr 2014 21:32:56 +0400 |
parents | 7094d6da2806 |
children | 777202558122 |
comparison
equal
deleted
inserted
replaced
5652:b6240baead00 | 5653:cb308813b453 |
---|---|
65 ngx_open_file_t *file; | 65 ngx_open_file_t *file; |
66 ngx_http_log_script_t *script; | 66 ngx_http_log_script_t *script; |
67 time_t disk_full_time; | 67 time_t disk_full_time; |
68 time_t error_log_time; | 68 time_t error_log_time; |
69 ngx_http_log_fmt_t *format; | 69 ngx_http_log_fmt_t *format; |
70 ngx_http_complex_value_t *filter; | |
70 } ngx_http_log_t; | 71 } ngx_http_log_t; |
71 | 72 |
72 | 73 |
73 typedef struct { | 74 typedef struct { |
74 ngx_array_t *logs; /* array of ngx_http_log_t */ | 75 ngx_array_t *logs; /* array of ngx_http_log_t */ |
238 static ngx_int_t | 239 static ngx_int_t |
239 ngx_http_log_handler(ngx_http_request_t *r) | 240 ngx_http_log_handler(ngx_http_request_t *r) |
240 { | 241 { |
241 u_char *line, *p; | 242 u_char *line, *p; |
242 size_t len; | 243 size_t len; |
244 ngx_str_t val; | |
243 ngx_uint_t i, l; | 245 ngx_uint_t i, l; |
244 ngx_http_log_t *log; | 246 ngx_http_log_t *log; |
245 ngx_http_log_op_t *op; | 247 ngx_http_log_op_t *op; |
246 ngx_http_log_buf_t *buffer; | 248 ngx_http_log_buf_t *buffer; |
247 ngx_http_log_loc_conf_t *lcf; | 249 ngx_http_log_loc_conf_t *lcf; |
255 return NGX_OK; | 257 return NGX_OK; |
256 } | 258 } |
257 | 259 |
258 log = lcf->logs->elts; | 260 log = lcf->logs->elts; |
259 for (l = 0; l < lcf->logs->nelts; l++) { | 261 for (l = 0; l < lcf->logs->nelts; l++) { |
262 | |
263 if (log[l].filter) { | |
264 if (ngx_http_complex_value(r, log[l].filter, &val) != NGX_OK) { | |
265 return NGX_ERROR; | |
266 } | |
267 | |
268 if (val.len == 0 || (val.len == 1 && val.data[0] == '0')) { | |
269 continue; | |
270 } | |
271 } | |
260 | 272 |
261 if (ngx_time() == log[l].disk_full_time) { | 273 if (ngx_time() == log[l].disk_full_time) { |
262 | 274 |
263 /* | 275 /* |
264 * on FreeBSD writing to a full filesystem with enabled softupdates | 276 * on FreeBSD writing to a full filesystem with enabled softupdates |
1083 static char * | 1095 static char * |
1084 ngx_http_log_set_log(ngx_conf_t *cf, ngx_command_t *cmd, void *conf) | 1096 ngx_http_log_set_log(ngx_conf_t *cf, ngx_command_t *cmd, void *conf) |
1085 { | 1097 { |
1086 ngx_http_log_loc_conf_t *llcf = conf; | 1098 ngx_http_log_loc_conf_t *llcf = conf; |
1087 | 1099 |
1088 ssize_t size; | 1100 ssize_t size; |
1089 ngx_int_t gzip; | 1101 ngx_int_t gzip; |
1090 ngx_uint_t i, n; | 1102 ngx_uint_t i, n; |
1091 ngx_msec_t flush; | 1103 ngx_msec_t flush; |
1092 ngx_str_t *value, name, s; | 1104 ngx_str_t *value, name, s, filter; |
1093 ngx_http_log_t *log; | 1105 ngx_http_log_t *log; |
1094 ngx_http_log_buf_t *buffer; | 1106 ngx_http_log_buf_t *buffer; |
1095 ngx_http_log_fmt_t *fmt; | 1107 ngx_http_log_fmt_t *fmt; |
1096 ngx_http_log_main_conf_t *lmcf; | 1108 ngx_http_log_main_conf_t *lmcf; |
1097 ngx_http_script_compile_t sc; | 1109 ngx_http_script_compile_t sc; |
1110 ngx_http_compile_complex_value_t ccv; | |
1098 | 1111 |
1099 value = cf->args->elts; | 1112 value = cf->args->elts; |
1100 | 1113 |
1101 if (ngx_strcmp(value[1].data, "off") == 0) { | 1114 if (ngx_strcmp(value[1].data, "off") == 0) { |
1102 llcf->off = 1; | 1115 llcf->off = 1; |
1187 } | 1200 } |
1188 | 1201 |
1189 size = 0; | 1202 size = 0; |
1190 flush = 0; | 1203 flush = 0; |
1191 gzip = 0; | 1204 gzip = 0; |
1205 filter.len = 0; | |
1192 | 1206 |
1193 for (i = 3; i < cf->args->nelts; i++) { | 1207 for (i = 3; i < cf->args->nelts; i++) { |
1194 | 1208 |
1195 if (ngx_strncmp(value[i].data, "buffer=", 7) == 0) { | 1209 if (ngx_strncmp(value[i].data, "buffer=", 7) == 0) { |
1196 s.len = value[i].len - 7; | 1210 s.len = value[i].len - 7; |
1251 #else | 1265 #else |
1252 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, | 1266 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, |
1253 "nginx was built without zlib support"); | 1267 "nginx was built without zlib support"); |
1254 return NGX_CONF_ERROR; | 1268 return NGX_CONF_ERROR; |
1255 #endif | 1269 #endif |
1270 } | |
1271 | |
1272 if (ngx_strncmp(value[i].data, "if=", 3) == 0) { | |
1273 filter.len = value[i].len - 3; | |
1274 filter.data = value[i].data + 3; | |
1275 continue; | |
1256 } | 1276 } |
1257 | 1277 |
1258 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, | 1278 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, |
1259 "invalid parameter \"%V\"", &value[i]); | 1279 "invalid parameter \"%V\"", &value[i]); |
1260 return NGX_CONF_ERROR; | 1280 return NGX_CONF_ERROR; |
1322 | 1342 |
1323 log->file->flush = ngx_http_log_flush; | 1343 log->file->flush = ngx_http_log_flush; |
1324 log->file->data = buffer; | 1344 log->file->data = buffer; |
1325 } | 1345 } |
1326 | 1346 |
1347 if (filter.len) { | |
1348 log->filter = ngx_palloc(cf->pool, sizeof(ngx_http_complex_value_t)); | |
1349 if (log->filter == NULL) { | |
1350 return NGX_CONF_ERROR; | |
1351 } | |
1352 | |
1353 ngx_memzero(&ccv, sizeof(ngx_http_compile_complex_value_t)); | |
1354 | |
1355 ccv.cf = cf; | |
1356 ccv.value = &filter; | |
1357 ccv.complex_value = log->filter; | |
1358 | |
1359 if (ngx_http_compile_complex_value(&ccv) != NGX_OK) { | |
1360 return NGX_CONF_ERROR; | |
1361 } | |
1362 } | |
1363 | |
1327 return NGX_CONF_OK; | 1364 return NGX_CONF_OK; |
1328 } | 1365 } |
1329 | 1366 |
1330 | 1367 |
1331 static char * | 1368 static char * |