37 | 37 |
ngx_array_t formats; /* array of ngx_http_log_fmt_t */
|
38 | 38 |
ngx_uint_t combined_used; /* unsigned combined_used:1 */
|
39 | 39 |
} ngx_http_log_main_conf_t;
|
|
40 |
|
|
41 |
|
|
42 |
typedef struct {
|
|
43 |
u_char *start;
|
|
44 |
u_char *pos;
|
|
45 |
u_char *last;
|
|
46 |
} ngx_http_log_buf_t;
|
40 | 47 |
|
41 | 48 |
|
42 | 49 |
typedef struct {
|
|
76 | 83 |
u_char *buf, size_t len);
|
77 | 84 |
static ssize_t ngx_http_log_script_write(ngx_http_request_t *r,
|
78 | 85 |
ngx_http_log_script_t *script, u_char **name, u_char *buf, size_t len);
|
|
86 |
|
|
87 |
static void ngx_http_log_flush(ngx_open_file_t *file, ngx_log_t *log);
|
79 | 88 |
|
80 | 89 |
static u_char *ngx_http_log_pipe(ngx_http_request_t *r, u_char *buf,
|
81 | 90 |
ngx_http_log_op_t *op);
|
|
215 | 224 |
size_t len;
|
216 | 225 |
ngx_uint_t i, l;
|
217 | 226 |
ngx_http_log_t *log;
|
218 | |
ngx_open_file_t *file;
|
219 | 227 |
ngx_http_log_op_t *op;
|
|
228 |
ngx_http_log_buf_t *buffer;
|
220 | 229 |
ngx_http_log_loc_conf_t *lcf;
|
221 | 230 |
|
222 | 231 |
ngx_log_debug0(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
|
|
257 | 266 |
|
258 | 267 |
len += NGX_LINEFEED_SIZE;
|
259 | 268 |
|
260 | |
file = log[l].file;
|
261 | |
|
262 | |
if (file && file->buffer) {
|
263 | |
|
264 | |
if (len > (size_t) (file->last - file->pos)) {
|
265 | |
|
266 | |
ngx_http_log_write(r, &log[l], file->buffer,
|
267 | |
file->pos - file->buffer);
|
268 | |
|
269 | |
file->pos = file->buffer;
|
|
269 |
buffer = log[l].file ? log[l].file->data : NULL;
|
|
270 |
|
|
271 |
if (buffer) {
|
|
272 |
|
|
273 |
if (len > (size_t) (buffer->last - buffer->pos)) {
|
|
274 |
|
|
275 |
ngx_http_log_write(r, &log[l], buffer->start,
|
|
276 |
buffer->pos - buffer->start);
|
|
277 |
|
|
278 |
buffer->pos = buffer->start;
|
270 | 279 |
}
|
271 | 280 |
|
272 | |
if (len <= (size_t) (file->last - file->pos)) {
|
273 | |
|
274 | |
p = file->pos;
|
|
281 |
if (len <= (size_t) (buffer->last - buffer->pos)) {
|
|
282 |
|
|
283 |
p = buffer->pos;
|
275 | 284 |
|
276 | 285 |
for (i = 0; i < log[l].format->ops->nelts; i++) {
|
277 | 286 |
p = op[i].run(r, p, &op[i]);
|
|
279 | 288 |
|
280 | 289 |
ngx_linefeed(p);
|
281 | 290 |
|
282 | |
file->pos = p;
|
|
291 |
buffer->pos = p;
|
283 | 292 |
|
284 | 293 |
continue;
|
285 | 294 |
}
|
|
464 | 473 |
}
|
465 | 474 |
|
466 | 475 |
|
|
476 |
static void
|
|
477 |
ngx_http_log_flush(ngx_open_file_t *file, ngx_log_t *log)
|
|
478 |
{
|
|
479 |
size_t len;
|
|
480 |
ssize_t n;
|
|
481 |
ngx_http_log_buf_t *buffer;
|
|
482 |
|
|
483 |
buffer = file->data;
|
|
484 |
|
|
485 |
len = buffer->pos - buffer->start;
|
|
486 |
|
|
487 |
if (len == 0) {
|
|
488 |
return;
|
|
489 |
}
|
|
490 |
|
|
491 |
n = ngx_write_fd(file->fd, buffer->start, len);
|
|
492 |
|
|
493 |
if (n == -1) {
|
|
494 |
ngx_log_error(NGX_LOG_ALERT, log, ngx_errno,
|
|
495 |
ngx_write_fd_n " to \"%s\" failed",
|
|
496 |
file->name.data);
|
|
497 |
|
|
498 |
} else if ((size_t) n != len) {
|
|
499 |
ngx_log_error(NGX_LOG_ALERT, log, 0,
|
|
500 |
ngx_write_fd_n " to \"%s\" was incomplete: %z of %uz",
|
|
501 |
file->name.data, n, len);
|
|
502 |
}
|
|
503 |
|
|
504 |
buffer->pos = buffer->start;
|
|
505 |
}
|
|
506 |
|
|
507 |
|
467 | 508 |
static u_char *
|
468 | 509 |
ngx_http_log_copy_short(ngx_http_request_t *r, u_char *buf,
|
469 | 510 |
ngx_http_log_op_t *op)
|
|
847 | 888 |
{
|
848 | 889 |
ngx_http_log_loc_conf_t *llcf = conf;
|
849 | 890 |
|
850 | |
ssize_t buf;
|
|
891 |
ssize_t size;
|
851 | 892 |
ngx_uint_t i, n;
|
852 | 893 |
ngx_str_t *value, name;
|
853 | 894 |
ngx_http_log_t *log;
|
|
895 |
ngx_http_log_buf_t *buffer;
|
854 | 896 |
ngx_http_log_fmt_t *fmt;
|
855 | 897 |
ngx_http_log_main_conf_t *lmcf;
|
856 | 898 |
ngx_http_script_compile_t sc;
|
|
961 | 1003 |
name.len = value[3].len - 7;
|
962 | 1004 |
name.data = value[3].data + 7;
|
963 | 1005 |
|
964 | |
buf = ngx_parse_size(&name);
|
965 | |
|
966 | |
if (buf == NGX_ERROR) {
|
|
1006 |
size = ngx_parse_size(&name);
|
|
1007 |
|
|
1008 |
if (size == NGX_ERROR) {
|
967 | 1009 |
ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
|
968 | 1010 |
"invalid buffer value \"%V\"", &name);
|
969 | 1011 |
return NGX_CONF_ERROR;
|
970 | 1012 |
}
|
971 | 1013 |
|
972 | |
if (log->file->buffer) {
|
973 | |
if (log->file->last - log->file->pos != buf) {
|
|
1014 |
if (log->file->data) {
|
|
1015 |
buffer = log->file->data;
|
|
1016 |
|
|
1017 |
if (buffer->last - buffer->start != size) {
|
974 | 1018 |
ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
|
975 | 1019 |
"access_log \"%V\" already defined "
|
976 | 1020 |
"with different buffer size", &value[1]);
|
|
980 | 1024 |
return NGX_CONF_OK;
|
981 | 1025 |
}
|
982 | 1026 |
|
983 | |
log->file->buffer = ngx_palloc(cf->pool, buf);
|
984 | |
if (log->file->buffer == NULL) {
|
|
1027 |
buffer = ngx_pcalloc(cf->pool, sizeof(ngx_http_log_buf_t));
|
|
1028 |
if (buffer == NULL) {
|
985 | 1029 |
return NGX_CONF_ERROR;
|
986 | 1030 |
}
|
987 | 1031 |
|
988 | |
log->file->pos = log->file->buffer;
|
989 | |
log->file->last = log->file->buffer + buf;
|
|
1032 |
buffer->start = ngx_pnalloc(cf->pool, size);
|
|
1033 |
if (buffer->start == NULL) {
|
|
1034 |
return NGX_CONF_ERROR;
|
|
1035 |
}
|
|
1036 |
|
|
1037 |
buffer->pos = buffer->start;
|
|
1038 |
buffer->last = buffer->start + size;
|
|
1039 |
|
|
1040 |
log->file->flush = ngx_http_log_flush;
|
|
1041 |
log->file->data = buffer;
|
990 | 1042 |
}
|
991 | 1043 |
|
992 | 1044 |
return NGX_CONF_OK;
|