aboutsummaryrefslogtreecommitdiff
path: root/src/http/modules/ngx_http_log_module.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/http/modules/ngx_http_log_module.c')
-rw-r--r--src/http/modules/ngx_http_log_module.c45
1 files changed, 33 insertions, 12 deletions
diff --git a/src/http/modules/ngx_http_log_module.c b/src/http/modules/ngx_http_log_module.c
index 775279c88..80bf22180 100644
--- a/src/http/modules/ngx_http_log_module.c
+++ b/src/http/modules/ngx_http_log_module.c
@@ -28,6 +28,7 @@ struct ngx_http_log_op_s {
typedef struct {
ngx_str_t name;
+ ngx_array_t *flushes;
ngx_array_t *ops; /* array of ngx_http_log_op_t */
} ngx_http_log_fmt_t;
@@ -49,7 +50,7 @@ typedef struct {
ngx_http_log_script_t *script;
time_t disk_full_time;
time_t error_log_time;
- ngx_array_t *ops; /* array of ngx_http_log_op_t */
+ ngx_http_log_fmt_t *format;
} ngx_http_log_t;
@@ -113,7 +114,7 @@ static char *ngx_http_log_set_log(ngx_conf_t *cf, ngx_command_t *cmd,
static char *ngx_http_log_set_format(ngx_conf_t *cf, ngx_command_t *cmd,
void *conf);
static char *ngx_http_log_compile_format(ngx_conf_t *cf,
- ngx_array_t *ops, ngx_array_t *args, ngx_uint_t s);
+ ngx_array_t *flushes, ngx_array_t *ops, ngx_array_t *args, ngx_uint_t s);
static char *ngx_http_log_open_file_cache(ngx_conf_t *cf, ngx_command_t *cmd,
void *conf);
static ngx_int_t ngx_http_log_init(ngx_conf_t *cf);
@@ -242,9 +243,11 @@ ngx_http_log_handler(ngx_http_request_t *r)
continue;
}
+ ngx_http_script_flush_no_cacheable_variables(r, log[l].format->flushes);
+
len = 0;
- op = log[l].ops->elts;
- for (i = 0; i < log[l].ops->nelts; i++) {
+ op = log[l].format->ops->elts;
+ for (i = 0; i < log[l].format->ops->nelts; i++) {
if (op[i].len == 0) {
len += op[i].getlen(r, op[i].data);
@@ -271,7 +274,7 @@ ngx_http_log_handler(ngx_http_request_t *r)
p = file->pos;
- for (i = 0; i < log[l].ops->nelts; i++) {
+ for (i = 0; i < log[l].format->ops->nelts; i++) {
p = op[i].run(r, p, &op[i]);
}
@@ -290,7 +293,7 @@ ngx_http_log_handler(ngx_http_request_t *r)
p = line;
- for (i = 0; i < log[l].ops->nelts; i++) {
+ for (i = 0; i < log[l].format->ops->nelts; i++) {
p = op[i].run(r, p, &op[i]);
}
@@ -726,6 +729,8 @@ ngx_http_log_create_main_conf(ngx_conf_t *cf)
fmt->name.len = sizeof("combined") - 1;
fmt->name.data = (u_char *) "combined";
+ fmt->flushes = NULL;
+
fmt->ops = ngx_array_create(cf->pool, 16, sizeof(ngx_http_log_op_t));
if (fmt->ops == NULL) {
return NGX_CONF_ERROR;
@@ -806,7 +811,7 @@ ngx_http_log_merge_loc_conf(ngx_conf_t *cf, void *parent, void *child)
fmt = lmcf->formats.elts;
/* the default "combined" format */
- log->ops = fmt[0].ops;
+ log->format = &fmt[0];
lmcf->combined_used = 1;
return NGX_CONF_OK;
@@ -900,7 +905,7 @@ ngx_http_log_set_log(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
if (fmt[i].name.len == name.len
&& ngx_strcasecmp(fmt[i].name.data, name.data) == 0)
{
- log->ops = fmt[i].ops;
+ log->format = &fmt[i];
goto buffer;
}
}
@@ -985,22 +990,28 @@ ngx_http_log_set_format(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
fmt->name = value[1];
+ fmt->flushes = ngx_array_create(cf->pool, 4, sizeof(ngx_int_t));
+ if (fmt->flushes == NULL) {
+ return NGX_CONF_ERROR;
+ }
+
fmt->ops = ngx_array_create(cf->pool, 16, sizeof(ngx_http_log_op_t));
if (fmt->ops == NULL) {
return NGX_CONF_ERROR;
}
- return ngx_http_log_compile_format(cf, fmt->ops, cf->args, 2);
+ return ngx_http_log_compile_format(cf, fmt->flushes, fmt->ops, cf->args, 2);
}
static char *
-ngx_http_log_compile_format(ngx_conf_t *cf, ngx_array_t *ops,
- ngx_array_t *args, ngx_uint_t s)
+ngx_http_log_compile_format(ngx_conf_t *cf, ngx_array_t *flushes,
+ ngx_array_t *ops, ngx_array_t *args, ngx_uint_t s)
{
u_char *data, *p, ch;
size_t i, len;
ngx_str_t *value, var;
+ ngx_int_t *flush;
ngx_uint_t bracket;
ngx_http_log_op_t *op;
ngx_http_log_var_t *v;
@@ -1114,6 +1125,16 @@ ngx_http_log_compile_format(ngx_conf_t *cf, ngx_array_t *ops,
return NGX_CONF_ERROR;
}
+ if (flushes) {
+
+ flush = ngx_array_push(flushes);
+ if (flush == NULL) {
+ return NGX_CONF_ERROR;
+ }
+
+ *flush = op->data; /* variable index */
+ }
+
found:
continue;
@@ -1299,7 +1320,7 @@ ngx_http_log_init(ngx_conf_t *cf)
*value = ngx_http_combined_fmt;
fmt = lmcf->formats.elts;
- if (ngx_http_log_compile_format(cf, fmt->ops, &a, 0)
+ if (ngx_http_log_compile_format(cf, NULL, fmt->ops, &a, 0)
!= NGX_CONF_OK)
{
return NGX_ERROR;