Mercurial > hg > nginx
annotate src/core/ngx_log.c @ 9322:d6f75dd66761 default tip
Mp4: added and updated sanity checks for "end" handling.
When handling incorrect data in ngx_http_mp4_crop_stsc_data(),
trak->end_chunk_samples might end up being arbitrary large, leading
to reading before the buffer in ngx_http_mp4_update_stsz_atom(). Fix
is to check that trak->end_chunk_samples corresponds to a memory within
the stsz atom data. For consistency, trak->start_chunk_samples
is checked similarly.
Similarly, trak->end_chunk might end up being smaller than trak->start_chunk,
leading to reading memory after the buffer in ngx_http_mp4_update_stco_atom()
and ngx_http_mp4_update_co64_atom(). Corresponding checks are updated
to explicitly test (trak->end_chunk - trak->start_chunk) instead of just
checking trak->end_chunk and assuming it is larger than trak->start_chunk.
This is generally in line with existing checks of
(trak->end_sample - trak->start_sample) in ngx_http_mp4_update_stsz_atom(),
where trak->end_sample might also become smaller than trak->start_sample
when handling incorrect data in ngx_http_mp4_crop_stts_data().
author | Maxim Dounin <mdounin@mdounin.ru> |
---|---|
date | Sun, 25 Aug 2024 06:35:40 +0300 |
parents | 2706b60dc225 |
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:
440
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:
440
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:
443
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:
440
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:
440
diff
changeset
|
6 |
0
4eff17414a43
nginx-0.0.1-2002-08-06-20:39:45 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
7 |
4eff17414a43
nginx-0.0.1-2002-08-06-20:39:45 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
8 #include <ngx_config.h> |
92
19cc647ecd91
nginx-0.0.1-2003-05-20-19:37:55 import
Igor Sysoev <igor@sysoev.ru>
parents:
83
diff
changeset
|
9 #include <ngx_core.h> |
0
4eff17414a43
nginx-0.0.1-2002-08-06-20:39:45 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
10 |
4eff17414a43
nginx-0.0.1-2002-08-06-20:39:45 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
11 |
9299
2706b60dc225
Core: error logging rate limiting.
Maxim Dounin <mdounin@mdounin.ru>
parents:
9298
diff
changeset
|
12 static ngx_int_t ngx_log_check_rate(ngx_log_t *log, ngx_uint_t level); |
2785
d478379e51ac
*) refactor error_log processing: listen socket log might inherit built-in
Igor Sysoev <igor@sysoev.ru>
parents:
2773
diff
changeset
|
13 static char *ngx_error_log(ngx_conf_t *cf, ngx_command_t *cmd, void *conf); |
9299
2706b60dc225
Core: error logging rate limiting.
Maxim Dounin <mdounin@mdounin.ru>
parents:
9298
diff
changeset
|
14 static char *ngx_log_set_params(ngx_conf_t *cf, ngx_log_t *log); |
5254
7ecaa9e4bf1b
Core: support several "error_log" directives.
Vladimir Homutov <vl@nginx.com>
parents:
5250
diff
changeset
|
15 static void ngx_log_insert(ngx_log_t *log, ngx_log_t *new_log); |
100
7ebc8b7fb816
nginx-0.0.1-2003-06-03-19:42:58 import
Igor Sysoev <igor@sysoev.ru>
parents:
93
diff
changeset
|
16 |
7ebc8b7fb816
nginx-0.0.1-2003-06-03-19:42:58 import
Igor Sysoev <igor@sysoev.ru>
parents:
93
diff
changeset
|
17 |
6033
8e66a83d16ae
Core: added cyclic memory buffer support for error_log.
Valentin Bartenev <vbart@nginx.com>
parents:
6000
diff
changeset
|
18 #if (NGX_DEBUG) |
8e66a83d16ae
Core: added cyclic memory buffer support for error_log.
Valentin Bartenev <vbart@nginx.com>
parents:
6000
diff
changeset
|
19 |
8e66a83d16ae
Core: added cyclic memory buffer support for error_log.
Valentin Bartenev <vbart@nginx.com>
parents:
6000
diff
changeset
|
20 static void ngx_log_memory_writer(ngx_log_t *log, ngx_uint_t level, |
8e66a83d16ae
Core: added cyclic memory buffer support for error_log.
Valentin Bartenev <vbart@nginx.com>
parents:
6000
diff
changeset
|
21 u_char *buf, size_t len); |
8e66a83d16ae
Core: added cyclic memory buffer support for error_log.
Valentin Bartenev <vbart@nginx.com>
parents:
6000
diff
changeset
|
22 static void ngx_log_memory_cleanup(void *data); |
8e66a83d16ae
Core: added cyclic memory buffer support for error_log.
Valentin Bartenev <vbart@nginx.com>
parents:
6000
diff
changeset
|
23 |
8e66a83d16ae
Core: added cyclic memory buffer support for error_log.
Valentin Bartenev <vbart@nginx.com>
parents:
6000
diff
changeset
|
24 |
8e66a83d16ae
Core: added cyclic memory buffer support for error_log.
Valentin Bartenev <vbart@nginx.com>
parents:
6000
diff
changeset
|
25 typedef struct { |
8e66a83d16ae
Core: added cyclic memory buffer support for error_log.
Valentin Bartenev <vbart@nginx.com>
parents:
6000
diff
changeset
|
26 u_char *start; |
8e66a83d16ae
Core: added cyclic memory buffer support for error_log.
Valentin Bartenev <vbart@nginx.com>
parents:
6000
diff
changeset
|
27 u_char *end; |
8e66a83d16ae
Core: added cyclic memory buffer support for error_log.
Valentin Bartenev <vbart@nginx.com>
parents:
6000
diff
changeset
|
28 u_char *pos; |
8e66a83d16ae
Core: added cyclic memory buffer support for error_log.
Valentin Bartenev <vbart@nginx.com>
parents:
6000
diff
changeset
|
29 ngx_atomic_t written; |
8e66a83d16ae
Core: added cyclic memory buffer support for error_log.
Valentin Bartenev <vbart@nginx.com>
parents:
6000
diff
changeset
|
30 } ngx_log_memory_buf_t; |
8e66a83d16ae
Core: added cyclic memory buffer support for error_log.
Valentin Bartenev <vbart@nginx.com>
parents:
6000
diff
changeset
|
31 |
8e66a83d16ae
Core: added cyclic memory buffer support for error_log.
Valentin Bartenev <vbart@nginx.com>
parents:
6000
diff
changeset
|
32 #endif |
8e66a83d16ae
Core: added cyclic memory buffer support for error_log.
Valentin Bartenev <vbart@nginx.com>
parents:
6000
diff
changeset
|
33 |
8e66a83d16ae
Core: added cyclic memory buffer support for error_log.
Valentin Bartenev <vbart@nginx.com>
parents:
6000
diff
changeset
|
34 |
100
7ebc8b7fb816
nginx-0.0.1-2003-06-03-19:42:58 import
Igor Sysoev <igor@sysoev.ru>
parents:
93
diff
changeset
|
35 static ngx_command_t ngx_errlog_commands[] = { |
7ebc8b7fb816
nginx-0.0.1-2003-06-03-19:42:58 import
Igor Sysoev <igor@sysoev.ru>
parents:
93
diff
changeset
|
36 |
6474 | 37 { ngx_string("error_log"), |
38 NGX_MAIN_CONF|NGX_CONF_1MORE, | |
39 ngx_error_log, | |
40 0, | |
41 0, | |
42 NULL }, | |
100
7ebc8b7fb816
nginx-0.0.1-2003-06-03-19:42:58 import
Igor Sysoev <igor@sysoev.ru>
parents:
93
diff
changeset
|
43 |
6474 | 44 ngx_null_command |
100
7ebc8b7fb816
nginx-0.0.1-2003-06-03-19:42:58 import
Igor Sysoev <igor@sysoev.ru>
parents:
93
diff
changeset
|
45 }; |
7ebc8b7fb816
nginx-0.0.1-2003-06-03-19:42:58 import
Igor Sysoev <igor@sysoev.ru>
parents:
93
diff
changeset
|
46 |
7ebc8b7fb816
nginx-0.0.1-2003-06-03-19:42:58 import
Igor Sysoev <igor@sysoev.ru>
parents:
93
diff
changeset
|
47 |
311
11ff50a35d6d
nginx-0.0.3-2004-04-12-20:38:09 import
Igor Sysoev <igor@sysoev.ru>
parents:
290
diff
changeset
|
48 static ngx_core_module_t ngx_errlog_module_ctx = { |
11ff50a35d6d
nginx-0.0.3-2004-04-12-20:38:09 import
Igor Sysoev <igor@sysoev.ru>
parents:
290
diff
changeset
|
49 ngx_string("errlog"), |
577 | 50 NULL, |
311
11ff50a35d6d
nginx-0.0.3-2004-04-12-20:38:09 import
Igor Sysoev <igor@sysoev.ru>
parents:
290
diff
changeset
|
51 NULL |
11ff50a35d6d
nginx-0.0.3-2004-04-12-20:38:09 import
Igor Sysoev <igor@sysoev.ru>
parents:
290
diff
changeset
|
52 }; |
11ff50a35d6d
nginx-0.0.3-2004-04-12-20:38:09 import
Igor Sysoev <igor@sysoev.ru>
parents:
290
diff
changeset
|
53 |
11ff50a35d6d
nginx-0.0.3-2004-04-12-20:38:09 import
Igor Sysoev <igor@sysoev.ru>
parents:
290
diff
changeset
|
54 |
100
7ebc8b7fb816
nginx-0.0.1-2003-06-03-19:42:58 import
Igor Sysoev <igor@sysoev.ru>
parents:
93
diff
changeset
|
55 ngx_module_t ngx_errlog_module = { |
509 | 56 NGX_MODULE_V1, |
311
11ff50a35d6d
nginx-0.0.3-2004-04-12-20:38:09 import
Igor Sysoev <igor@sysoev.ru>
parents:
290
diff
changeset
|
57 &ngx_errlog_module_ctx, /* module context */ |
100
7ebc8b7fb816
nginx-0.0.1-2003-06-03-19:42:58 import
Igor Sysoev <igor@sysoev.ru>
parents:
93
diff
changeset
|
58 ngx_errlog_commands, /* module directives */ |
7ebc8b7fb816
nginx-0.0.1-2003-06-03-19:42:58 import
Igor Sysoev <igor@sysoev.ru>
parents:
93
diff
changeset
|
59 NGX_CORE_MODULE, /* module type */ |
541 | 60 NULL, /* init master */ |
116
571bcbff82c5
nginx-0.0.1-2003-07-11-08:50:59 import
Igor Sysoev <igor@sysoev.ru>
parents:
115
diff
changeset
|
61 NULL, /* init module */ |
541 | 62 NULL, /* init process */ |
63 NULL, /* init thread */ | |
64 NULL, /* exit thread */ | |
65 NULL, /* exit process */ | |
66 NULL, /* exit master */ | |
67 NGX_MODULE_V1_PADDING | |
100
7ebc8b7fb816
nginx-0.0.1-2003-06-03-19:42:58 import
Igor Sysoev <igor@sysoev.ru>
parents:
93
diff
changeset
|
68 }; |
7ebc8b7fb816
nginx-0.0.1-2003-06-03-19:42:58 import
Igor Sysoev <igor@sysoev.ru>
parents:
93
diff
changeset
|
69 |
7ebc8b7fb816
nginx-0.0.1-2003-06-03-19:42:58 import
Igor Sysoev <igor@sysoev.ru>
parents:
93
diff
changeset
|
70 |
415
3c56e834be46
nginx-0.0.10-2004-09-05-23:54:02 import
Igor Sysoev <igor@sysoev.ru>
parents:
379
diff
changeset
|
71 static ngx_log_t ngx_log; |
2743
d8316f307b6a
issue start up errors and warning on both stderr and error_log
Igor Sysoev <igor@sysoev.ru>
parents:
2742
diff
changeset
|
72 static ngx_open_file_t ngx_log_file; |
d8316f307b6a
issue start up errors and warning on both stderr and error_log
Igor Sysoev <igor@sysoev.ru>
parents:
2742
diff
changeset
|
73 ngx_uint_t ngx_use_stderr = 1; |
100
7ebc8b7fb816
nginx-0.0.1-2003-06-03-19:42:58 import
Igor Sysoev <igor@sysoev.ru>
parents:
93
diff
changeset
|
74 |
7ebc8b7fb816
nginx-0.0.1-2003-06-03-19:42:58 import
Igor Sysoev <igor@sysoev.ru>
parents:
93
diff
changeset
|
75 |
2741
cda3738a85bd
use ngx_str_t for error levels
Igor Sysoev <igor@sysoev.ru>
parents:
2737
diff
changeset
|
76 static ngx_str_t err_levels[] = { |
2785
d478379e51ac
*) refactor error_log processing: listen socket log might inherit built-in
Igor Sysoev <igor@sysoev.ru>
parents:
2773
diff
changeset
|
77 ngx_null_string, |
2741
cda3738a85bd
use ngx_str_t for error levels
Igor Sysoev <igor@sysoev.ru>
parents:
2737
diff
changeset
|
78 ngx_string("emerg"), |
cda3738a85bd
use ngx_str_t for error levels
Igor Sysoev <igor@sysoev.ru>
parents:
2737
diff
changeset
|
79 ngx_string("alert"), |
cda3738a85bd
use ngx_str_t for error levels
Igor Sysoev <igor@sysoev.ru>
parents:
2737
diff
changeset
|
80 ngx_string("crit"), |
cda3738a85bd
use ngx_str_t for error levels
Igor Sysoev <igor@sysoev.ru>
parents:
2737
diff
changeset
|
81 ngx_string("error"), |
cda3738a85bd
use ngx_str_t for error levels
Igor Sysoev <igor@sysoev.ru>
parents:
2737
diff
changeset
|
82 ngx_string("warn"), |
2742
e138f820b5dc
style fix: remove trailing spaces introduced in the previous commit
Igor Sysoev <igor@sysoev.ru>
parents:
2741
diff
changeset
|
83 ngx_string("notice"), |
e138f820b5dc
style fix: remove trailing spaces introduced in the previous commit
Igor Sysoev <igor@sysoev.ru>
parents:
2741
diff
changeset
|
84 ngx_string("info"), |
2741
cda3738a85bd
use ngx_str_t for error levels
Igor Sysoev <igor@sysoev.ru>
parents:
2737
diff
changeset
|
85 ngx_string("debug") |
0
4eff17414a43
nginx-0.0.1-2002-08-06-20:39:45 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
86 }; |
4eff17414a43
nginx-0.0.1-2002-08-06-20:39:45 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
87 |
208
0b67be7d4489
nginx-0.0.1-2003-12-08-23:48:12 import
Igor Sysoev <igor@sysoev.ru>
parents:
207
diff
changeset
|
88 static const char *debug_levels[] = { |
417
0526206251f6
nginx-0.0.10-2004-09-07-19:29:22 import
Igor Sysoev <igor@sysoev.ru>
parents:
415
diff
changeset
|
89 "debug_core", "debug_alloc", "debug_mutex", "debug_event", |
6484
4b420f9c4c5d
Removed the prototype mysql module.
Ruslan Ermilov <ru@nginx.com>
parents:
6474
diff
changeset
|
90 "debug_http", "debug_mail", "debug_stream" |
208
0b67be7d4489
nginx-0.0.1-2003-12-08-23:48:12 import
Igor Sysoev <igor@sysoev.ru>
parents:
207
diff
changeset
|
91 }; |
0b67be7d4489
nginx-0.0.1-2003-12-08-23:48:12 import
Igor Sysoev <igor@sysoev.ru>
parents:
207
diff
changeset
|
92 |
0b67be7d4489
nginx-0.0.1-2003-12-08-23:48:12 import
Igor Sysoev <igor@sysoev.ru>
parents:
207
diff
changeset
|
93 |
455 | 94 #if (NGX_HAVE_VARIADIC_MACROS) |
503 | 95 |
96 void | |
97 ngx_log_error_core(ngx_uint_t level, ngx_log_t *log, ngx_err_t err, | |
98 const char *fmt, ...) | |
99 | |
0
4eff17414a43
nginx-0.0.1-2002-08-06-20:39:45 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
100 #else |
503 | 101 |
102 void | |
103 ngx_log_error_core(ngx_uint_t level, ngx_log_t *log, ngx_err_t err, | |
104 const char *fmt, va_list args) | |
105 | |
0
4eff17414a43
nginx-0.0.1-2002-08-06-20:39:45 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
106 #endif |
4eff17414a43
nginx-0.0.1-2002-08-06-20:39:45 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
107 { |
455 | 108 #if (NGX_HAVE_VARIADIC_MACROS) |
5254
7ecaa9e4bf1b
Core: support several "error_log" directives.
Vladimir Homutov <vl@nginx.com>
parents:
5250
diff
changeset
|
109 va_list args; |
0
4eff17414a43
nginx-0.0.1-2002-08-06-20:39:45 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
110 #endif |
5254
7ecaa9e4bf1b
Core: support several "error_log" directives.
Vladimir Homutov <vl@nginx.com>
parents:
5250
diff
changeset
|
111 u_char *p, *last, *msg; |
5962
727177743c3c
Core: added disk_full_time checks to error log.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5771
diff
changeset
|
112 ssize_t n; |
727177743c3c
Core: added disk_full_time checks to error log.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5771
diff
changeset
|
113 ngx_uint_t wrote_stderr, debug_connection; |
5254
7ecaa9e4bf1b
Core: support several "error_log" directives.
Vladimir Homutov <vl@nginx.com>
parents:
5250
diff
changeset
|
114 u_char errstr[NGX_MAX_ERROR_STR]; |
119
cd54bcbaf3b5
nginx-0.0.1-2003-07-21-01:15:59 import
Igor Sysoev <igor@sysoev.ru>
parents:
116
diff
changeset
|
115 |
461 | 116 last = errstr + NGX_MAX_ERROR_STR; |
117 | |
6000
93fee708f168
Log: use ngx_cpymem() in a couple of places, no functional changes.
Valentin Bartenev <vbart@nginx.com>
parents:
5962
diff
changeset
|
118 p = ngx_cpymem(errstr, ngx_cached_err_log_time.data, |
93fee708f168
Log: use ngx_cpymem() in a couple of places, no functional changes.
Valentin Bartenev <vbart@nginx.com>
parents:
5962
diff
changeset
|
119 ngx_cached_err_log_time.len); |
236
86e473b5641e
nginx-0.0.1-2004-01-22-09:47:28 import
Igor Sysoev <igor@sysoev.ru>
parents:
235
diff
changeset
|
120 |
2764
d4a717592877
use ngx_vslprintf(), ngx_slprintf()
Igor Sysoev <igor@sysoev.ru>
parents:
2758
diff
changeset
|
121 p = ngx_slprintf(p, last, " [%V] ", &err_levels[level]); |
0
4eff17414a43
nginx-0.0.1-2002-08-06-20:39:45 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
122 |
36
c14d7232b11f
nginx-0.0.1-2002-12-23-09:29:22 import
Igor Sysoev <igor@sysoev.ru>
parents:
28
diff
changeset
|
123 /* pid#tid */ |
2764
d4a717592877
use ngx_vslprintf(), ngx_slprintf()
Igor Sysoev <igor@sysoev.ru>
parents:
2758
diff
changeset
|
124 p = ngx_slprintf(p, last, "%P#" NGX_TID_T_FMT ": ", |
933
1ce231663322
ngx_sprintf() has implicit limit of 65536 bytes so on Linux/ppc64
Igor Sysoev <igor@sysoev.ru>
parents:
860
diff
changeset
|
125 ngx_log_pid, ngx_log_tid); |
0
4eff17414a43
nginx-0.0.1-2002-08-06-20:39:45 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
126 |
483 | 127 if (log->connection) { |
2764
d4a717592877
use ngx_vslprintf(), ngx_slprintf()
Igor Sysoev <igor@sysoev.ru>
parents:
2758
diff
changeset
|
128 p = ngx_slprintf(p, last, "*%uA ", log->connection); |
483 | 129 } |
130 | |
2743
d8316f307b6a
issue start up errors and warning on both stderr and error_log
Igor Sysoev <igor@sysoev.ru>
parents:
2742
diff
changeset
|
131 msg = p; |
d8316f307b6a
issue start up errors and warning on both stderr and error_log
Igor Sysoev <igor@sysoev.ru>
parents:
2742
diff
changeset
|
132 |
455 | 133 #if (NGX_HAVE_VARIADIC_MACROS) |
191
71ce40b3c37b
nginx-0.0.1-2003-11-19-19:26:41 import
Igor Sysoev <igor@sysoev.ru>
parents:
186
diff
changeset
|
134 |
0
4eff17414a43
nginx-0.0.1-2002-08-06-20:39:45 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
135 va_start(args, fmt); |
2764
d4a717592877
use ngx_vslprintf(), ngx_slprintf()
Igor Sysoev <igor@sysoev.ru>
parents:
2758
diff
changeset
|
136 p = ngx_vslprintf(p, last, fmt, args); |
0
4eff17414a43
nginx-0.0.1-2002-08-06-20:39:45 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
137 va_end(args); |
191
71ce40b3c37b
nginx-0.0.1-2003-11-19-19:26:41 import
Igor Sysoev <igor@sysoev.ru>
parents:
186
diff
changeset
|
138 |
0
4eff17414a43
nginx-0.0.1-2002-08-06-20:39:45 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
139 #else |
191
71ce40b3c37b
nginx-0.0.1-2003-11-19-19:26:41 import
Igor Sysoev <igor@sysoev.ru>
parents:
186
diff
changeset
|
140 |
2764
d4a717592877
use ngx_vslprintf(), ngx_slprintf()
Igor Sysoev <igor@sysoev.ru>
parents:
2758
diff
changeset
|
141 p = ngx_vslprintf(p, last, fmt, args); |
191
71ce40b3c37b
nginx-0.0.1-2003-11-19-19:26:41 import
Igor Sysoev <igor@sysoev.ru>
parents:
186
diff
changeset
|
142 |
0
4eff17414a43
nginx-0.0.1-2002-08-06-20:39:45 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
143 #endif |
4eff17414a43
nginx-0.0.1-2002-08-06-20:39:45 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
144 |
6
669801705ab1
nginx-0.0.1-2002-08-26-19:18:19 import
Igor Sysoev <igor@sysoev.ru>
parents:
1
diff
changeset
|
145 if (err) { |
2765 | 146 p = ngx_log_errno(p, last, err); |
6
669801705ab1
nginx-0.0.1-2002-08-26-19:18:19 import
Igor Sysoev <igor@sysoev.ru>
parents:
1
diff
changeset
|
147 } |
669801705ab1
nginx-0.0.1-2002-08-26-19:18:19 import
Igor Sysoev <igor@sysoev.ru>
parents:
1
diff
changeset
|
148 |
36
c14d7232b11f
nginx-0.0.1-2002-12-23-09:29:22 import
Igor Sysoev <igor@sysoev.ru>
parents:
28
diff
changeset
|
149 if (level != NGX_LOG_DEBUG && log->handler) { |
483 | 150 p = log->handler(log, p, last - p); |
36
c14d7232b11f
nginx-0.0.1-2002-12-23-09:29:22 import
Igor Sysoev <igor@sysoev.ru>
parents:
28
diff
changeset
|
151 } |
6
669801705ab1
nginx-0.0.1-2002-08-26-19:18:19 import
Igor Sysoev <igor@sysoev.ru>
parents:
1
diff
changeset
|
152 |
571 | 153 if (p > last - NGX_LINEFEED_SIZE) { |
154 p = last - NGX_LINEFEED_SIZE; | |
461 | 155 } |
156 | |
571 | 157 ngx_linefeed(p); |
467 | 158 |
5254
7ecaa9e4bf1b
Core: support several "error_log" directives.
Vladimir Homutov <vl@nginx.com>
parents:
5250
diff
changeset
|
159 wrote_stderr = 0; |
7ecaa9e4bf1b
Core: support several "error_log" directives.
Vladimir Homutov <vl@nginx.com>
parents:
5250
diff
changeset
|
160 debug_connection = (log->log_level & NGX_LOG_DEBUG_CONNECTION) != 0; |
7ecaa9e4bf1b
Core: support several "error_log" directives.
Vladimir Homutov <vl@nginx.com>
parents:
5250
diff
changeset
|
161 |
7ecaa9e4bf1b
Core: support several "error_log" directives.
Vladimir Homutov <vl@nginx.com>
parents:
5250
diff
changeset
|
162 while (log) { |
7ecaa9e4bf1b
Core: support several "error_log" directives.
Vladimir Homutov <vl@nginx.com>
parents:
5250
diff
changeset
|
163 |
7ecaa9e4bf1b
Core: support several "error_log" directives.
Vladimir Homutov <vl@nginx.com>
parents:
5250
diff
changeset
|
164 if (log->log_level < level && !debug_connection) { |
7ecaa9e4bf1b
Core: support several "error_log" directives.
Vladimir Homutov <vl@nginx.com>
parents:
5250
diff
changeset
|
165 break; |
7ecaa9e4bf1b
Core: support several "error_log" directives.
Vladimir Homutov <vl@nginx.com>
parents:
5250
diff
changeset
|
166 } |
7ecaa9e4bf1b
Core: support several "error_log" directives.
Vladimir Homutov <vl@nginx.com>
parents:
5250
diff
changeset
|
167 |
9299
2706b60dc225
Core: error logging rate limiting.
Maxim Dounin <mdounin@mdounin.ru>
parents:
9298
diff
changeset
|
168 if (log->limit && !debug_connection) { |
2706b60dc225
Core: error logging rate limiting.
Maxim Dounin <mdounin@mdounin.ru>
parents:
9298
diff
changeset
|
169 if (ngx_log_check_rate(log, level) == NGX_BUSY) { |
2706b60dc225
Core: error logging rate limiting.
Maxim Dounin <mdounin@mdounin.ru>
parents:
9298
diff
changeset
|
170 goto next; |
2706b60dc225
Core: error logging rate limiting.
Maxim Dounin <mdounin@mdounin.ru>
parents:
9298
diff
changeset
|
171 } |
2706b60dc225
Core: error logging rate limiting.
Maxim Dounin <mdounin@mdounin.ru>
parents:
9298
diff
changeset
|
172 } |
2706b60dc225
Core: error logging rate limiting.
Maxim Dounin <mdounin@mdounin.ru>
parents:
9298
diff
changeset
|
173 |
5702
777202558122
Added syslog support for error_log and access_log directives.
Vladimir Homutov <vl@nginx.com>
parents:
5260
diff
changeset
|
174 if (log->writer) { |
777202558122
Added syslog support for error_log and access_log directives.
Vladimir Homutov <vl@nginx.com>
parents:
5260
diff
changeset
|
175 log->writer(log, level, errstr, p - errstr); |
5962
727177743c3c
Core: added disk_full_time checks to error log.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5771
diff
changeset
|
176 goto next; |
5702
777202558122
Added syslog support for error_log and access_log directives.
Vladimir Homutov <vl@nginx.com>
parents:
5260
diff
changeset
|
177 } |
777202558122
Added syslog support for error_log and access_log directives.
Vladimir Homutov <vl@nginx.com>
parents:
5260
diff
changeset
|
178 |
9296
af5b47569cb2
Core: fixed ENOSPC handling for error logs.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7744
diff
changeset
|
179 if (ngx_time() == log->file->disk_full_time) { |
5962
727177743c3c
Core: added disk_full_time checks to error log.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5771
diff
changeset
|
180 |
727177743c3c
Core: added disk_full_time checks to error log.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5771
diff
changeset
|
181 /* |
727177743c3c
Core: added disk_full_time checks to error log.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5771
diff
changeset
|
182 * on FreeBSD writing to a full filesystem with enabled softupdates |
727177743c3c
Core: added disk_full_time checks to error log.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5771
diff
changeset
|
183 * may block process for much longer time than writing to non-full |
727177743c3c
Core: added disk_full_time checks to error log.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5771
diff
changeset
|
184 * filesystem, so we skip writing to a log for one second |
727177743c3c
Core: added disk_full_time checks to error log.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5771
diff
changeset
|
185 */ |
727177743c3c
Core: added disk_full_time checks to error log.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5771
diff
changeset
|
186 |
727177743c3c
Core: added disk_full_time checks to error log.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5771
diff
changeset
|
187 goto next; |
727177743c3c
Core: added disk_full_time checks to error log.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5771
diff
changeset
|
188 } |
727177743c3c
Core: added disk_full_time checks to error log.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5771
diff
changeset
|
189 |
727177743c3c
Core: added disk_full_time checks to error log.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5771
diff
changeset
|
190 n = ngx_write_fd(log->file->fd, errstr, p - errstr); |
727177743c3c
Core: added disk_full_time checks to error log.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5771
diff
changeset
|
191 |
727177743c3c
Core: added disk_full_time checks to error log.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5771
diff
changeset
|
192 if (n == -1 && ngx_errno == NGX_ENOSPC) { |
9296
af5b47569cb2
Core: fixed ENOSPC handling for error logs.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7744
diff
changeset
|
193 log->file->disk_full_time = ngx_time(); |
5962
727177743c3c
Core: added disk_full_time checks to error log.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5771
diff
changeset
|
194 } |
5254
7ecaa9e4bf1b
Core: support several "error_log" directives.
Vladimir Homutov <vl@nginx.com>
parents:
5250
diff
changeset
|
195 |
7ecaa9e4bf1b
Core: support several "error_log" directives.
Vladimir Homutov <vl@nginx.com>
parents:
5250
diff
changeset
|
196 if (log->file->fd == ngx_stderr) { |
7ecaa9e4bf1b
Core: support several "error_log" directives.
Vladimir Homutov <vl@nginx.com>
parents:
5250
diff
changeset
|
197 wrote_stderr = 1; |
7ecaa9e4bf1b
Core: support several "error_log" directives.
Vladimir Homutov <vl@nginx.com>
parents:
5250
diff
changeset
|
198 } |
7ecaa9e4bf1b
Core: support several "error_log" directives.
Vladimir Homutov <vl@nginx.com>
parents:
5250
diff
changeset
|
199 |
5962
727177743c3c
Core: added disk_full_time checks to error log.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5771
diff
changeset
|
200 next: |
727177743c3c
Core: added disk_full_time checks to error log.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5771
diff
changeset
|
201 |
5254
7ecaa9e4bf1b
Core: support several "error_log" directives.
Vladimir Homutov <vl@nginx.com>
parents:
5250
diff
changeset
|
202 log = log->next; |
7ecaa9e4bf1b
Core: support several "error_log" directives.
Vladimir Homutov <vl@nginx.com>
parents:
5250
diff
changeset
|
203 } |
2743
d8316f307b6a
issue start up errors and warning on both stderr and error_log
Igor Sysoev <igor@sysoev.ru>
parents:
2742
diff
changeset
|
204 |
d8316f307b6a
issue start up errors and warning on both stderr and error_log
Igor Sysoev <igor@sysoev.ru>
parents:
2742
diff
changeset
|
205 if (!ngx_use_stderr |
d8316f307b6a
issue start up errors and warning on both stderr and error_log
Igor Sysoev <igor@sysoev.ru>
parents:
2742
diff
changeset
|
206 || level > NGX_LOG_WARN |
5254
7ecaa9e4bf1b
Core: support several "error_log" directives.
Vladimir Homutov <vl@nginx.com>
parents:
5250
diff
changeset
|
207 || wrote_stderr) |
2743
d8316f307b6a
issue start up errors and warning on both stderr and error_log
Igor Sysoev <igor@sysoev.ru>
parents:
2742
diff
changeset
|
208 { |
d8316f307b6a
issue start up errors and warning on both stderr and error_log
Igor Sysoev <igor@sysoev.ru>
parents:
2742
diff
changeset
|
209 return; |
d8316f307b6a
issue start up errors and warning on both stderr and error_log
Igor Sysoev <igor@sysoev.ru>
parents:
2742
diff
changeset
|
210 } |
d8316f307b6a
issue start up errors and warning on both stderr and error_log
Igor Sysoev <igor@sysoev.ru>
parents:
2742
diff
changeset
|
211 |
3822
75ffcfc700f3
remove semicolon, because it is already in "nginx: " prefix
Igor Sysoev <igor@sysoev.ru>
parents:
3799
diff
changeset
|
212 msg -= (7 + err_levels[level].len + 3); |
2743
d8316f307b6a
issue start up errors and warning on both stderr and error_log
Igor Sysoev <igor@sysoev.ru>
parents:
2742
diff
changeset
|
213 |
3822
75ffcfc700f3
remove semicolon, because it is already in "nginx: " prefix
Igor Sysoev <igor@sysoev.ru>
parents:
3799
diff
changeset
|
214 (void) ngx_sprintf(msg, "nginx: [%V] ", &err_levels[level]); |
2743
d8316f307b6a
issue start up errors and warning on both stderr and error_log
Igor Sysoev <igor@sysoev.ru>
parents:
2742
diff
changeset
|
215 |
2769
9d986c4e796f
introduce ngx_write_console() to support OEM code pages
Igor Sysoev <igor@sysoev.ru>
parents:
2765
diff
changeset
|
216 (void) ngx_write_console(ngx_stderr, msg, p - msg); |
0
4eff17414a43
nginx-0.0.1-2002-08-06-20:39:45 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
217 } |
4eff17414a43
nginx-0.0.1-2002-08-06-20:39:45 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
218 |
92
19cc647ecd91
nginx-0.0.1-2003-05-20-19:37:55 import
Igor Sysoev <igor@sysoev.ru>
parents:
83
diff
changeset
|
219 |
455 | 220 #if !(NGX_HAVE_VARIADIC_MACROS) |
0
4eff17414a43
nginx-0.0.1-2002-08-06-20:39:45 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
221 |
503 | 222 void ngx_cdecl |
223 ngx_log_error(ngx_uint_t level, ngx_log_t *log, ngx_err_t err, | |
224 const char *fmt, ...) | |
0
4eff17414a43
nginx-0.0.1-2002-08-06-20:39:45 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
225 { |
461 | 226 va_list args; |
0
4eff17414a43
nginx-0.0.1-2002-08-06-20:39:45 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
227 |
4eff17414a43
nginx-0.0.1-2002-08-06-20:39:45 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
228 if (log->log_level >= level) { |
4eff17414a43
nginx-0.0.1-2002-08-06-20:39:45 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
229 va_start(args, fmt); |
4eff17414a43
nginx-0.0.1-2002-08-06-20:39:45 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
230 ngx_log_error_core(level, log, err, fmt, args); |
4eff17414a43
nginx-0.0.1-2002-08-06-20:39:45 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
231 va_end(args); |
4eff17414a43
nginx-0.0.1-2002-08-06-20:39:45 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
232 } |
4eff17414a43
nginx-0.0.1-2002-08-06-20:39:45 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
233 } |
4eff17414a43
nginx-0.0.1-2002-08-06-20:39:45 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
234 |
92
19cc647ecd91
nginx-0.0.1-2003-05-20-19:37:55 import
Igor Sysoev <igor@sysoev.ru>
parents:
83
diff
changeset
|
235 |
503 | 236 void ngx_cdecl |
237 ngx_log_debug_core(ngx_log_t *log, ngx_err_t err, const char *fmt, ...) | |
0
4eff17414a43
nginx-0.0.1-2002-08-06-20:39:45 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
238 { |
461 | 239 va_list args; |
0
4eff17414a43
nginx-0.0.1-2002-08-06-20:39:45 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
240 |
4eff17414a43
nginx-0.0.1-2002-08-06-20:39:45 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
241 va_start(args, fmt); |
201
267ea1d98683
nginx-0.0.1-2003-11-30-23:03:18 import
Igor Sysoev <igor@sysoev.ru>
parents:
195
diff
changeset
|
242 ngx_log_error_core(NGX_LOG_DEBUG, log, err, fmt, args); |
0
4eff17414a43
nginx-0.0.1-2002-08-06-20:39:45 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
243 va_end(args); |
4eff17414a43
nginx-0.0.1-2002-08-06-20:39:45 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
244 } |
4eff17414a43
nginx-0.0.1-2002-08-06-20:39:45 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
245 |
4eff17414a43
nginx-0.0.1-2002-08-06-20:39:45 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
246 #endif |
92
19cc647ecd91
nginx-0.0.1-2003-05-20-19:37:55 import
Igor Sysoev <igor@sysoev.ru>
parents:
83
diff
changeset
|
247 |
19cc647ecd91
nginx-0.0.1-2003-05-20-19:37:55 import
Igor Sysoev <igor@sysoev.ru>
parents:
83
diff
changeset
|
248 |
2752
2d82d3cfbfa0
change ngx_log_abort() interface
Igor Sysoev <igor@sysoev.ru>
parents:
2750
diff
changeset
|
249 void ngx_cdecl |
2d82d3cfbfa0
change ngx_log_abort() interface
Igor Sysoev <igor@sysoev.ru>
parents:
2750
diff
changeset
|
250 ngx_log_abort(ngx_err_t err, const char *fmt, ...) |
860
201d017ea470
slab allocator in shared memory
Igor Sysoev <igor@sysoev.ru>
parents:
639
diff
changeset
|
251 { |
2752
2d82d3cfbfa0
change ngx_log_abort() interface
Igor Sysoev <igor@sysoev.ru>
parents:
2750
diff
changeset
|
252 u_char *p; |
2d82d3cfbfa0
change ngx_log_abort() interface
Igor Sysoev <igor@sysoev.ru>
parents:
2750
diff
changeset
|
253 va_list args; |
2d82d3cfbfa0
change ngx_log_abort() interface
Igor Sysoev <igor@sysoev.ru>
parents:
2750
diff
changeset
|
254 u_char errstr[NGX_MAX_CONF_ERRSTR]; |
2d82d3cfbfa0
change ngx_log_abort() interface
Igor Sysoev <igor@sysoev.ru>
parents:
2750
diff
changeset
|
255 |
2d82d3cfbfa0
change ngx_log_abort() interface
Igor Sysoev <igor@sysoev.ru>
parents:
2750
diff
changeset
|
256 va_start(args, fmt); |
2d82d3cfbfa0
change ngx_log_abort() interface
Igor Sysoev <igor@sysoev.ru>
parents:
2750
diff
changeset
|
257 p = ngx_vsnprintf(errstr, sizeof(errstr) - 1, fmt, args); |
2d82d3cfbfa0
change ngx_log_abort() interface
Igor Sysoev <igor@sysoev.ru>
parents:
2750
diff
changeset
|
258 va_end(args); |
2d82d3cfbfa0
change ngx_log_abort() interface
Igor Sysoev <igor@sysoev.ru>
parents:
2750
diff
changeset
|
259 |
2d82d3cfbfa0
change ngx_log_abort() interface
Igor Sysoev <igor@sysoev.ru>
parents:
2750
diff
changeset
|
260 ngx_log_error(NGX_LOG_ALERT, ngx_cycle->log, err, |
2d82d3cfbfa0
change ngx_log_abort() interface
Igor Sysoev <igor@sysoev.ru>
parents:
2750
diff
changeset
|
261 "%*s", p - errstr, errstr); |
860
201d017ea470
slab allocator in shared memory
Igor Sysoev <igor@sysoev.ru>
parents:
639
diff
changeset
|
262 } |
201d017ea470
slab allocator in shared memory
Igor Sysoev <igor@sysoev.ru>
parents:
639
diff
changeset
|
263 |
201d017ea470
slab allocator in shared memory
Igor Sysoev <igor@sysoev.ru>
parents:
639
diff
changeset
|
264 |
2722 | 265 void ngx_cdecl |
2743
d8316f307b6a
issue start up errors and warning on both stderr and error_log
Igor Sysoev <igor@sysoev.ru>
parents:
2742
diff
changeset
|
266 ngx_log_stderr(ngx_err_t err, const char *fmt, ...) |
2722 | 267 { |
2743
d8316f307b6a
issue start up errors and warning on both stderr and error_log
Igor Sysoev <igor@sysoev.ru>
parents:
2742
diff
changeset
|
268 u_char *p, *last; |
2722 | 269 va_list args; |
270 u_char errstr[NGX_MAX_ERROR_STR]; | |
271 | |
2764
d4a717592877
use ngx_vslprintf(), ngx_slprintf()
Igor Sysoev <igor@sysoev.ru>
parents:
2758
diff
changeset
|
272 last = errstr + NGX_MAX_ERROR_STR; |
3799
188007bf58c3
add "nginx: " prefix when logging to the stderr
Igor Sysoev <igor@sysoev.ru>
parents:
3787
diff
changeset
|
273 |
6000
93fee708f168
Log: use ngx_cpymem() in a couple of places, no functional changes.
Valentin Bartenev <vbart@nginx.com>
parents:
5962
diff
changeset
|
274 p = ngx_cpymem(errstr, "nginx: ", 7); |
2764
d4a717592877
use ngx_vslprintf(), ngx_slprintf()
Igor Sysoev <igor@sysoev.ru>
parents:
2758
diff
changeset
|
275 |
2722 | 276 va_start(args, fmt); |
3799
188007bf58c3
add "nginx: " prefix when logging to the stderr
Igor Sysoev <igor@sysoev.ru>
parents:
3787
diff
changeset
|
277 p = ngx_vslprintf(p, last, fmt, args); |
2722 | 278 va_end(args); |
279 | |
2765 | 280 if (err) { |
281 p = ngx_log_errno(p, last, err); | |
2722 | 282 } |
283 | |
2765 | 284 if (p > last - NGX_LINEFEED_SIZE) { |
285 p = last - NGX_LINEFEED_SIZE; | |
2732 | 286 } |
287 | |
2743
d8316f307b6a
issue start up errors and warning on both stderr and error_log
Igor Sysoev <igor@sysoev.ru>
parents:
2742
diff
changeset
|
288 ngx_linefeed(p); |
2732 | 289 |
2769
9d986c4e796f
introduce ngx_write_console() to support OEM code pages
Igor Sysoev <igor@sysoev.ru>
parents:
2765
diff
changeset
|
290 (void) ngx_write_console(ngx_stderr, errstr, p - errstr); |
2722 | 291 } |
292 | |
293 | |
2765 | 294 u_char * |
295 ngx_log_errno(u_char *buf, u_char *last, ngx_err_t err) | |
296 { | |
297 if (buf > last - 50) { | |
298 | |
299 /* leave a space for an error code */ | |
300 | |
301 buf = last - 50; | |
302 *buf++ = '.'; | |
303 *buf++ = '.'; | |
304 *buf++ = '.'; | |
305 } | |
306 | |
307 #if (NGX_WIN32) | |
308 buf = ngx_slprintf(buf, last, ((unsigned) err < 0x80000000) | |
309 ? " (%d: " : " (%Xd: ", err); | |
310 #else | |
311 buf = ngx_slprintf(buf, last, " (%d: ", err); | |
312 #endif | |
313 | |
3787
e294f37401c0
use copied strerror() messages and autoconfigured sys_nerr value
Igor Sysoev <igor@sysoev.ru>
parents:
3516
diff
changeset
|
314 buf = ngx_strerror(err, buf, last - buf); |
2765 | 315 |
316 if (buf < last) { | |
317 *buf++ = ')'; | |
318 } | |
319 | |
320 return buf; | |
321 } | |
322 | |
323 | |
9299
2706b60dc225
Core: error logging rate limiting.
Maxim Dounin <mdounin@mdounin.ru>
parents:
9298
diff
changeset
|
324 static ngx_int_t |
2706b60dc225
Core: error logging rate limiting.
Maxim Dounin <mdounin@mdounin.ru>
parents:
9298
diff
changeset
|
325 ngx_log_check_rate(ngx_log_t *log, ngx_uint_t level) |
2706b60dc225
Core: error logging rate limiting.
Maxim Dounin <mdounin@mdounin.ru>
parents:
9298
diff
changeset
|
326 { |
2706b60dc225
Core: error logging rate limiting.
Maxim Dounin <mdounin@mdounin.ru>
parents:
9298
diff
changeset
|
327 ngx_log_t temp_log; |
2706b60dc225
Core: error logging rate limiting.
Maxim Dounin <mdounin@mdounin.ru>
parents:
9298
diff
changeset
|
328 ngx_int_t excess, changed, burst; |
2706b60dc225
Core: error logging rate limiting.
Maxim Dounin <mdounin@mdounin.ru>
parents:
9298
diff
changeset
|
329 ngx_atomic_int_t ms; |
2706b60dc225
Core: error logging rate limiting.
Maxim Dounin <mdounin@mdounin.ru>
parents:
9298
diff
changeset
|
330 ngx_atomic_uint_t now, last; |
2706b60dc225
Core: error logging rate limiting.
Maxim Dounin <mdounin@mdounin.ru>
parents:
9298
diff
changeset
|
331 |
2706b60dc225
Core: error logging rate limiting.
Maxim Dounin <mdounin@mdounin.ru>
parents:
9298
diff
changeset
|
332 now = ngx_current_msec; |
2706b60dc225
Core: error logging rate limiting.
Maxim Dounin <mdounin@mdounin.ru>
parents:
9298
diff
changeset
|
333 |
2706b60dc225
Core: error logging rate limiting.
Maxim Dounin <mdounin@mdounin.ru>
parents:
9298
diff
changeset
|
334 last = log->limit->last; |
2706b60dc225
Core: error logging rate limiting.
Maxim Dounin <mdounin@mdounin.ru>
parents:
9298
diff
changeset
|
335 excess = log->limit->excess; |
2706b60dc225
Core: error logging rate limiting.
Maxim Dounin <mdounin@mdounin.ru>
parents:
9298
diff
changeset
|
336 |
2706b60dc225
Core: error logging rate limiting.
Maxim Dounin <mdounin@mdounin.ru>
parents:
9298
diff
changeset
|
337 ms = (ngx_atomic_int_t) (now - last); |
2706b60dc225
Core: error logging rate limiting.
Maxim Dounin <mdounin@mdounin.ru>
parents:
9298
diff
changeset
|
338 |
2706b60dc225
Core: error logging rate limiting.
Maxim Dounin <mdounin@mdounin.ru>
parents:
9298
diff
changeset
|
339 if (ms < -60000) { |
2706b60dc225
Core: error logging rate limiting.
Maxim Dounin <mdounin@mdounin.ru>
parents:
9298
diff
changeset
|
340 ms = 1; |
2706b60dc225
Core: error logging rate limiting.
Maxim Dounin <mdounin@mdounin.ru>
parents:
9298
diff
changeset
|
341 |
2706b60dc225
Core: error logging rate limiting.
Maxim Dounin <mdounin@mdounin.ru>
parents:
9298
diff
changeset
|
342 } else if (ms < 0) { |
2706b60dc225
Core: error logging rate limiting.
Maxim Dounin <mdounin@mdounin.ru>
parents:
9298
diff
changeset
|
343 ms = 0; |
2706b60dc225
Core: error logging rate limiting.
Maxim Dounin <mdounin@mdounin.ru>
parents:
9298
diff
changeset
|
344 } |
2706b60dc225
Core: error logging rate limiting.
Maxim Dounin <mdounin@mdounin.ru>
parents:
9298
diff
changeset
|
345 |
2706b60dc225
Core: error logging rate limiting.
Maxim Dounin <mdounin@mdounin.ru>
parents:
9298
diff
changeset
|
346 changed = excess - log->limit->rate * ms / 1000 + 1000; |
2706b60dc225
Core: error logging rate limiting.
Maxim Dounin <mdounin@mdounin.ru>
parents:
9298
diff
changeset
|
347 |
2706b60dc225
Core: error logging rate limiting.
Maxim Dounin <mdounin@mdounin.ru>
parents:
9298
diff
changeset
|
348 if (changed < 0) { |
2706b60dc225
Core: error logging rate limiting.
Maxim Dounin <mdounin@mdounin.ru>
parents:
9298
diff
changeset
|
349 changed = 0; |
2706b60dc225
Core: error logging rate limiting.
Maxim Dounin <mdounin@mdounin.ru>
parents:
9298
diff
changeset
|
350 } |
2706b60dc225
Core: error logging rate limiting.
Maxim Dounin <mdounin@mdounin.ru>
parents:
9298
diff
changeset
|
351 |
2706b60dc225
Core: error logging rate limiting.
Maxim Dounin <mdounin@mdounin.ru>
parents:
9298
diff
changeset
|
352 burst = (log->log_level - level + 1) * log->limit->rate; |
2706b60dc225
Core: error logging rate limiting.
Maxim Dounin <mdounin@mdounin.ru>
parents:
9298
diff
changeset
|
353 |
2706b60dc225
Core: error logging rate limiting.
Maxim Dounin <mdounin@mdounin.ru>
parents:
9298
diff
changeset
|
354 if (changed > burst) { |
2706b60dc225
Core: error logging rate limiting.
Maxim Dounin <mdounin@mdounin.ru>
parents:
9298
diff
changeset
|
355 if (excess <= burst) { |
2706b60dc225
Core: error logging rate limiting.
Maxim Dounin <mdounin@mdounin.ru>
parents:
9298
diff
changeset
|
356 |
2706b60dc225
Core: error logging rate limiting.
Maxim Dounin <mdounin@mdounin.ru>
parents:
9298
diff
changeset
|
357 ngx_atomic_fetch_add(&log->limit->excess, 1000); |
2706b60dc225
Core: error logging rate limiting.
Maxim Dounin <mdounin@mdounin.ru>
parents:
9298
diff
changeset
|
358 |
2706b60dc225
Core: error logging rate limiting.
Maxim Dounin <mdounin@mdounin.ru>
parents:
9298
diff
changeset
|
359 /* log message to this log only */ |
2706b60dc225
Core: error logging rate limiting.
Maxim Dounin <mdounin@mdounin.ru>
parents:
9298
diff
changeset
|
360 |
2706b60dc225
Core: error logging rate limiting.
Maxim Dounin <mdounin@mdounin.ru>
parents:
9298
diff
changeset
|
361 temp_log = *log; |
2706b60dc225
Core: error logging rate limiting.
Maxim Dounin <mdounin@mdounin.ru>
parents:
9298
diff
changeset
|
362 temp_log.connection = 0; |
2706b60dc225
Core: error logging rate limiting.
Maxim Dounin <mdounin@mdounin.ru>
parents:
9298
diff
changeset
|
363 temp_log.handler = NULL; |
2706b60dc225
Core: error logging rate limiting.
Maxim Dounin <mdounin@mdounin.ru>
parents:
9298
diff
changeset
|
364 temp_log.limit = NULL; |
2706b60dc225
Core: error logging rate limiting.
Maxim Dounin <mdounin@mdounin.ru>
parents:
9298
diff
changeset
|
365 temp_log.next = NULL; |
2706b60dc225
Core: error logging rate limiting.
Maxim Dounin <mdounin@mdounin.ru>
parents:
9298
diff
changeset
|
366 |
2706b60dc225
Core: error logging rate limiting.
Maxim Dounin <mdounin@mdounin.ru>
parents:
9298
diff
changeset
|
367 ngx_log_error(level, &temp_log, 0, |
2706b60dc225
Core: error logging rate limiting.
Maxim Dounin <mdounin@mdounin.ru>
parents:
9298
diff
changeset
|
368 "too many log messages, limiting"); |
2706b60dc225
Core: error logging rate limiting.
Maxim Dounin <mdounin@mdounin.ru>
parents:
9298
diff
changeset
|
369 } |
2706b60dc225
Core: error logging rate limiting.
Maxim Dounin <mdounin@mdounin.ru>
parents:
9298
diff
changeset
|
370 |
2706b60dc225
Core: error logging rate limiting.
Maxim Dounin <mdounin@mdounin.ru>
parents:
9298
diff
changeset
|
371 return NGX_BUSY; |
2706b60dc225
Core: error logging rate limiting.
Maxim Dounin <mdounin@mdounin.ru>
parents:
9298
diff
changeset
|
372 } |
2706b60dc225
Core: error logging rate limiting.
Maxim Dounin <mdounin@mdounin.ru>
parents:
9298
diff
changeset
|
373 |
2706b60dc225
Core: error logging rate limiting.
Maxim Dounin <mdounin@mdounin.ru>
parents:
9298
diff
changeset
|
374 if (ms > 0 |
2706b60dc225
Core: error logging rate limiting.
Maxim Dounin <mdounin@mdounin.ru>
parents:
9298
diff
changeset
|
375 && ngx_atomic_cmp_set(&log->limit->last, last, now)) |
2706b60dc225
Core: error logging rate limiting.
Maxim Dounin <mdounin@mdounin.ru>
parents:
9298
diff
changeset
|
376 { |
2706b60dc225
Core: error logging rate limiting.
Maxim Dounin <mdounin@mdounin.ru>
parents:
9298
diff
changeset
|
377 ngx_atomic_fetch_add(&log->limit->excess, changed - excess); |
2706b60dc225
Core: error logging rate limiting.
Maxim Dounin <mdounin@mdounin.ru>
parents:
9298
diff
changeset
|
378 |
2706b60dc225
Core: error logging rate limiting.
Maxim Dounin <mdounin@mdounin.ru>
parents:
9298
diff
changeset
|
379 } else { |
2706b60dc225
Core: error logging rate limiting.
Maxim Dounin <mdounin@mdounin.ru>
parents:
9298
diff
changeset
|
380 ngx_atomic_fetch_add(&log->limit->excess, 1000); |
2706b60dc225
Core: error logging rate limiting.
Maxim Dounin <mdounin@mdounin.ru>
parents:
9298
diff
changeset
|
381 } |
2706b60dc225
Core: error logging rate limiting.
Maxim Dounin <mdounin@mdounin.ru>
parents:
9298
diff
changeset
|
382 |
2706b60dc225
Core: error logging rate limiting.
Maxim Dounin <mdounin@mdounin.ru>
parents:
9298
diff
changeset
|
383 return NGX_OK; |
2706b60dc225
Core: error logging rate limiting.
Maxim Dounin <mdounin@mdounin.ru>
parents:
9298
diff
changeset
|
384 } |
2706b60dc225
Core: error logging rate limiting.
Maxim Dounin <mdounin@mdounin.ru>
parents:
9298
diff
changeset
|
385 |
2706b60dc225
Core: error logging rate limiting.
Maxim Dounin <mdounin@mdounin.ru>
parents:
9298
diff
changeset
|
386 |
503 | 387 ngx_log_t * |
7744
f18db38a9826
Core: "-e" command line option.
Igor Ippolitov <iippolitov@nginx.com>
parents:
6484
diff
changeset
|
388 ngx_log_init(u_char *prefix, u_char *error_log) |
100
7ebc8b7fb816
nginx-0.0.1-2003-06-03-19:42:58 import
Igor Sysoev <igor@sysoev.ru>
parents:
93
diff
changeset
|
389 { |
2758 | 390 u_char *p, *name; |
391 size_t nlen, plen; | |
392 | |
2743
d8316f307b6a
issue start up errors and warning on both stderr and error_log
Igor Sysoev <igor@sysoev.ru>
parents:
2742
diff
changeset
|
393 ngx_log.file = &ngx_log_file; |
461 | 394 ngx_log.log_level = NGX_LOG_NOTICE; |
105
00bee6e7b485
nginx-0.0.1-2003-06-15-22:32:13 import
Igor Sysoev <igor@sysoev.ru>
parents:
103
diff
changeset
|
395 |
7744
f18db38a9826
Core: "-e" command line option.
Igor Ippolitov <iippolitov@nginx.com>
parents:
6484
diff
changeset
|
396 if (error_log == NULL) { |
f18db38a9826
Core: "-e" command line option.
Igor Ippolitov <iippolitov@nginx.com>
parents:
6484
diff
changeset
|
397 error_log = (u_char *) NGX_ERROR_LOG_PATH; |
f18db38a9826
Core: "-e" command line option.
Igor Ippolitov <iippolitov@nginx.com>
parents:
6484
diff
changeset
|
398 } |
2758 | 399 |
7744
f18db38a9826
Core: "-e" command line option.
Igor Ippolitov <iippolitov@nginx.com>
parents:
6484
diff
changeset
|
400 name = error_log; |
2758 | 401 nlen = ngx_strlen(name); |
402 | |
403 if (nlen == 0) { | |
2743
d8316f307b6a
issue start up errors and warning on both stderr and error_log
Igor Sysoev <igor@sysoev.ru>
parents:
2742
diff
changeset
|
404 ngx_log_file.fd = ngx_stderr; |
d8316f307b6a
issue start up errors and warning on both stderr and error_log
Igor Sysoev <igor@sysoev.ru>
parents:
2742
diff
changeset
|
405 return &ngx_log; |
d8316f307b6a
issue start up errors and warning on both stderr and error_log
Igor Sysoev <igor@sysoev.ru>
parents:
2742
diff
changeset
|
406 } |
d8316f307b6a
issue start up errors and warning on both stderr and error_log
Igor Sysoev <igor@sysoev.ru>
parents:
2742
diff
changeset
|
407 |
2758 | 408 p = NULL; |
409 | |
410 #if (NGX_WIN32) | |
411 if (name[1] != ':') { | |
412 #else | |
413 if (name[0] != '/') { | |
414 #endif | |
415 | |
416 if (prefix) { | |
417 plen = ngx_strlen(prefix); | |
418 | |
2773
7a44b1932741
fix building by BCC if NGX_PREFIX is defined
Igor Sysoev <igor@sysoev.ru>
parents:
2769
diff
changeset
|
419 } else { |
2758 | 420 #ifdef NGX_PREFIX |
421 prefix = (u_char *) NGX_PREFIX; | |
422 plen = ngx_strlen(prefix); | |
2773
7a44b1932741
fix building by BCC if NGX_PREFIX is defined
Igor Sysoev <igor@sysoev.ru>
parents:
2769
diff
changeset
|
423 #else |
7a44b1932741
fix building by BCC if NGX_PREFIX is defined
Igor Sysoev <igor@sysoev.ru>
parents:
2769
diff
changeset
|
424 plen = 0; |
2758 | 425 #endif |
426 } | |
427 | |
428 if (plen) { | |
429 name = malloc(plen + nlen + 2); | |
430 if (name == NULL) { | |
431 return NULL; | |
432 } | |
433 | |
434 p = ngx_cpymem(name, prefix, plen); | |
435 | |
436 if (!ngx_path_separator(*(p - 1))) { | |
437 *p++ = '/'; | |
438 } | |
439 | |
7744
f18db38a9826
Core: "-e" command line option.
Igor Ippolitov <iippolitov@nginx.com>
parents:
6484
diff
changeset
|
440 ngx_cpystrn(p, error_log, nlen + 1); |
2758 | 441 |
442 p = name; | |
443 } | |
444 } | |
445 | |
446 ngx_log_file.fd = ngx_open_file(name, NGX_FILE_APPEND, | |
2743
d8316f307b6a
issue start up errors and warning on both stderr and error_log
Igor Sysoev <igor@sysoev.ru>
parents:
2742
diff
changeset
|
447 NGX_FILE_CREATE_OR_OPEN, |
d8316f307b6a
issue start up errors and warning on both stderr and error_log
Igor Sysoev <igor@sysoev.ru>
parents:
2742
diff
changeset
|
448 NGX_FILE_DEFAULT_ACCESS); |
d8316f307b6a
issue start up errors and warning on both stderr and error_log
Igor Sysoev <igor@sysoev.ru>
parents:
2742
diff
changeset
|
449 |
d8316f307b6a
issue start up errors and warning on both stderr and error_log
Igor Sysoev <igor@sysoev.ru>
parents:
2742
diff
changeset
|
450 if (ngx_log_file.fd == NGX_INVALID_FILE) { |
d8316f307b6a
issue start up errors and warning on both stderr and error_log
Igor Sysoev <igor@sysoev.ru>
parents:
2742
diff
changeset
|
451 ngx_log_stderr(ngx_errno, |
3871
8ccd6ed1d4bb
remove semicolon, because it is already in "nginx: " prefix
Igor Sysoev <igor@sysoev.ru>
parents:
3822
diff
changeset
|
452 "[alert] could not open error log file: " |
2758 | 453 ngx_open_file_n " \"%s\" failed", name); |
461 | 454 #if (NGX_WIN32) |
2743
d8316f307b6a
issue start up errors and warning on both stderr and error_log
Igor Sysoev <igor@sysoev.ru>
parents:
2742
diff
changeset
|
455 ngx_event_log(ngx_errno, |
d8316f307b6a
issue start up errors and warning on both stderr and error_log
Igor Sysoev <igor@sysoev.ru>
parents:
2742
diff
changeset
|
456 "could not open error log file: " |
2758 | 457 ngx_open_file_n " \"%s\" failed", name); |
2743
d8316f307b6a
issue start up errors and warning on both stderr and error_log
Igor Sysoev <igor@sysoev.ru>
parents:
2742
diff
changeset
|
458 #endif |
100
7ebc8b7fb816
nginx-0.0.1-2003-06-03-19:42:58 import
Igor Sysoev <igor@sysoev.ru>
parents:
93
diff
changeset
|
459 |
2758 | 460 ngx_log_file.fd = ngx_stderr; |
461 } | |
462 | |
463 if (p) { | |
464 ngx_free(p); | |
461 | 465 } |
207
6e0fef527732
nginx-0.0.1-2003-12-05-20:07:27 import
Igor Sysoev <igor@sysoev.ru>
parents:
201
diff
changeset
|
466 |
448
241dc8092a33
nginx-0.1.0-2004-10-01-19:53:53 import
Igor Sysoev <igor@sysoev.ru>
parents:
445
diff
changeset
|
467 return &ngx_log; |
241dc8092a33
nginx-0.1.0-2004-10-01-19:53:53 import
Igor Sysoev <igor@sysoev.ru>
parents:
445
diff
changeset
|
468 } |
241dc8092a33
nginx-0.1.0-2004-10-01-19:53:53 import
Igor Sysoev <igor@sysoev.ru>
parents:
445
diff
changeset
|
469 |
241dc8092a33
nginx-0.1.0-2004-10-01-19:53:53 import
Igor Sysoev <igor@sysoev.ru>
parents:
445
diff
changeset
|
470 |
5260
e088695737c3
Core: consolidated log-related code.
Vladimir Homutov <vl@nginx.com>
parents:
5254
diff
changeset
|
471 ngx_int_t |
e088695737c3
Core: consolidated log-related code.
Vladimir Homutov <vl@nginx.com>
parents:
5254
diff
changeset
|
472 ngx_log_open_default(ngx_cycle_t *cycle) |
e088695737c3
Core: consolidated log-related code.
Vladimir Homutov <vl@nginx.com>
parents:
5254
diff
changeset
|
473 { |
7744
f18db38a9826
Core: "-e" command line option.
Igor Ippolitov <iippolitov@nginx.com>
parents:
6484
diff
changeset
|
474 ngx_log_t *log; |
5260
e088695737c3
Core: consolidated log-related code.
Vladimir Homutov <vl@nginx.com>
parents:
5254
diff
changeset
|
475 |
5702
777202558122
Added syslog support for error_log and access_log directives.
Vladimir Homutov <vl@nginx.com>
parents:
5260
diff
changeset
|
476 if (ngx_log_get_file_log(&cycle->new_log) != NULL) { |
777202558122
Added syslog support for error_log and access_log directives.
Vladimir Homutov <vl@nginx.com>
parents:
5260
diff
changeset
|
477 return NGX_OK; |
777202558122
Added syslog support for error_log and access_log directives.
Vladimir Homutov <vl@nginx.com>
parents:
5260
diff
changeset
|
478 } |
777202558122
Added syslog support for error_log and access_log directives.
Vladimir Homutov <vl@nginx.com>
parents:
5260
diff
changeset
|
479 |
777202558122
Added syslog support for error_log and access_log directives.
Vladimir Homutov <vl@nginx.com>
parents:
5260
diff
changeset
|
480 if (cycle->new_log.log_level != 0) { |
777202558122
Added syslog support for error_log and access_log directives.
Vladimir Homutov <vl@nginx.com>
parents:
5260
diff
changeset
|
481 /* there are some error logs, but no files */ |
777202558122
Added syslog support for error_log and access_log directives.
Vladimir Homutov <vl@nginx.com>
parents:
5260
diff
changeset
|
482 |
777202558122
Added syslog support for error_log and access_log directives.
Vladimir Homutov <vl@nginx.com>
parents:
5260
diff
changeset
|
483 log = ngx_pcalloc(cycle->pool, sizeof(ngx_log_t)); |
777202558122
Added syslog support for error_log and access_log directives.
Vladimir Homutov <vl@nginx.com>
parents:
5260
diff
changeset
|
484 if (log == NULL) { |
5260
e088695737c3
Core: consolidated log-related code.
Vladimir Homutov <vl@nginx.com>
parents:
5254
diff
changeset
|
485 return NGX_ERROR; |
e088695737c3
Core: consolidated log-related code.
Vladimir Homutov <vl@nginx.com>
parents:
5254
diff
changeset
|
486 } |
e088695737c3
Core: consolidated log-related code.
Vladimir Homutov <vl@nginx.com>
parents:
5254
diff
changeset
|
487 |
5702
777202558122
Added syslog support for error_log and access_log directives.
Vladimir Homutov <vl@nginx.com>
parents:
5260
diff
changeset
|
488 } else { |
777202558122
Added syslog support for error_log and access_log directives.
Vladimir Homutov <vl@nginx.com>
parents:
5260
diff
changeset
|
489 /* no error logs at all */ |
777202558122
Added syslog support for error_log and access_log directives.
Vladimir Homutov <vl@nginx.com>
parents:
5260
diff
changeset
|
490 log = &cycle->new_log; |
777202558122
Added syslog support for error_log and access_log directives.
Vladimir Homutov <vl@nginx.com>
parents:
5260
diff
changeset
|
491 } |
777202558122
Added syslog support for error_log and access_log directives.
Vladimir Homutov <vl@nginx.com>
parents:
5260
diff
changeset
|
492 |
5771
c3b08217f2a2
Core: fixed default log initialization.
Vladimir Homutov <vl@nginx.com>
parents:
5702
diff
changeset
|
493 log->log_level = NGX_LOG_ERR; |
c3b08217f2a2
Core: fixed default log initialization.
Vladimir Homutov <vl@nginx.com>
parents:
5702
diff
changeset
|
494 |
7744
f18db38a9826
Core: "-e" command line option.
Igor Ippolitov <iippolitov@nginx.com>
parents:
6484
diff
changeset
|
495 log->file = ngx_conf_open_file(cycle, &cycle->error_log); |
5702
777202558122
Added syslog support for error_log and access_log directives.
Vladimir Homutov <vl@nginx.com>
parents:
5260
diff
changeset
|
496 if (log->file == NULL) { |
777202558122
Added syslog support for error_log and access_log directives.
Vladimir Homutov <vl@nginx.com>
parents:
5260
diff
changeset
|
497 return NGX_ERROR; |
5260
e088695737c3
Core: consolidated log-related code.
Vladimir Homutov <vl@nginx.com>
parents:
5254
diff
changeset
|
498 } |
e088695737c3
Core: consolidated log-related code.
Vladimir Homutov <vl@nginx.com>
parents:
5254
diff
changeset
|
499 |
5771
c3b08217f2a2
Core: fixed default log initialization.
Vladimir Homutov <vl@nginx.com>
parents:
5702
diff
changeset
|
500 if (log != &cycle->new_log) { |
c3b08217f2a2
Core: fixed default log initialization.
Vladimir Homutov <vl@nginx.com>
parents:
5702
diff
changeset
|
501 ngx_log_insert(&cycle->new_log, log); |
c3b08217f2a2
Core: fixed default log initialization.
Vladimir Homutov <vl@nginx.com>
parents:
5702
diff
changeset
|
502 } |
c3b08217f2a2
Core: fixed default log initialization.
Vladimir Homutov <vl@nginx.com>
parents:
5702
diff
changeset
|
503 |
5260
e088695737c3
Core: consolidated log-related code.
Vladimir Homutov <vl@nginx.com>
parents:
5254
diff
changeset
|
504 return NGX_OK; |
e088695737c3
Core: consolidated log-related code.
Vladimir Homutov <vl@nginx.com>
parents:
5254
diff
changeset
|
505 } |
e088695737c3
Core: consolidated log-related code.
Vladimir Homutov <vl@nginx.com>
parents:
5254
diff
changeset
|
506 |
e088695737c3
Core: consolidated log-related code.
Vladimir Homutov <vl@nginx.com>
parents:
5254
diff
changeset
|
507 |
e088695737c3
Core: consolidated log-related code.
Vladimir Homutov <vl@nginx.com>
parents:
5254
diff
changeset
|
508 ngx_int_t |
e088695737c3
Core: consolidated log-related code.
Vladimir Homutov <vl@nginx.com>
parents:
5254
diff
changeset
|
509 ngx_log_redirect_stderr(ngx_cycle_t *cycle) |
e088695737c3
Core: consolidated log-related code.
Vladimir Homutov <vl@nginx.com>
parents:
5254
diff
changeset
|
510 { |
e088695737c3
Core: consolidated log-related code.
Vladimir Homutov <vl@nginx.com>
parents:
5254
diff
changeset
|
511 ngx_fd_t fd; |
e088695737c3
Core: consolidated log-related code.
Vladimir Homutov <vl@nginx.com>
parents:
5254
diff
changeset
|
512 |
e088695737c3
Core: consolidated log-related code.
Vladimir Homutov <vl@nginx.com>
parents:
5254
diff
changeset
|
513 if (cycle->log_use_stderr) { |
e088695737c3
Core: consolidated log-related code.
Vladimir Homutov <vl@nginx.com>
parents:
5254
diff
changeset
|
514 return NGX_OK; |
e088695737c3
Core: consolidated log-related code.
Vladimir Homutov <vl@nginx.com>
parents:
5254
diff
changeset
|
515 } |
e088695737c3
Core: consolidated log-related code.
Vladimir Homutov <vl@nginx.com>
parents:
5254
diff
changeset
|
516 |
5702
777202558122
Added syslog support for error_log and access_log directives.
Vladimir Homutov <vl@nginx.com>
parents:
5260
diff
changeset
|
517 /* file log always exists when we are called */ |
777202558122
Added syslog support for error_log and access_log directives.
Vladimir Homutov <vl@nginx.com>
parents:
5260
diff
changeset
|
518 fd = ngx_log_get_file_log(cycle->log)->file->fd; |
5260
e088695737c3
Core: consolidated log-related code.
Vladimir Homutov <vl@nginx.com>
parents:
5254
diff
changeset
|
519 |
e088695737c3
Core: consolidated log-related code.
Vladimir Homutov <vl@nginx.com>
parents:
5254
diff
changeset
|
520 if (fd != ngx_stderr) { |
e088695737c3
Core: consolidated log-related code.
Vladimir Homutov <vl@nginx.com>
parents:
5254
diff
changeset
|
521 if (ngx_set_stderr(fd) == NGX_FILE_ERROR) { |
e088695737c3
Core: consolidated log-related code.
Vladimir Homutov <vl@nginx.com>
parents:
5254
diff
changeset
|
522 ngx_log_error(NGX_LOG_ALERT, cycle->log, ngx_errno, |
e088695737c3
Core: consolidated log-related code.
Vladimir Homutov <vl@nginx.com>
parents:
5254
diff
changeset
|
523 ngx_set_stderr_n " failed"); |
e088695737c3
Core: consolidated log-related code.
Vladimir Homutov <vl@nginx.com>
parents:
5254
diff
changeset
|
524 |
e088695737c3
Core: consolidated log-related code.
Vladimir Homutov <vl@nginx.com>
parents:
5254
diff
changeset
|
525 return NGX_ERROR; |
e088695737c3
Core: consolidated log-related code.
Vladimir Homutov <vl@nginx.com>
parents:
5254
diff
changeset
|
526 } |
e088695737c3
Core: consolidated log-related code.
Vladimir Homutov <vl@nginx.com>
parents:
5254
diff
changeset
|
527 } |
e088695737c3
Core: consolidated log-related code.
Vladimir Homutov <vl@nginx.com>
parents:
5254
diff
changeset
|
528 |
e088695737c3
Core: consolidated log-related code.
Vladimir Homutov <vl@nginx.com>
parents:
5254
diff
changeset
|
529 return NGX_OK; |
e088695737c3
Core: consolidated log-related code.
Vladimir Homutov <vl@nginx.com>
parents:
5254
diff
changeset
|
530 } |
e088695737c3
Core: consolidated log-related code.
Vladimir Homutov <vl@nginx.com>
parents:
5254
diff
changeset
|
531 |
e088695737c3
Core: consolidated log-related code.
Vladimir Homutov <vl@nginx.com>
parents:
5254
diff
changeset
|
532 |
5702
777202558122
Added syslog support for error_log and access_log directives.
Vladimir Homutov <vl@nginx.com>
parents:
5260
diff
changeset
|
533 ngx_log_t * |
777202558122
Added syslog support for error_log and access_log directives.
Vladimir Homutov <vl@nginx.com>
parents:
5260
diff
changeset
|
534 ngx_log_get_file_log(ngx_log_t *head) |
777202558122
Added syslog support for error_log and access_log directives.
Vladimir Homutov <vl@nginx.com>
parents:
5260
diff
changeset
|
535 { |
777202558122
Added syslog support for error_log and access_log directives.
Vladimir Homutov <vl@nginx.com>
parents:
5260
diff
changeset
|
536 ngx_log_t *log; |
777202558122
Added syslog support for error_log and access_log directives.
Vladimir Homutov <vl@nginx.com>
parents:
5260
diff
changeset
|
537 |
777202558122
Added syslog support for error_log and access_log directives.
Vladimir Homutov <vl@nginx.com>
parents:
5260
diff
changeset
|
538 for (log = head; log; log = log->next) { |
777202558122
Added syslog support for error_log and access_log directives.
Vladimir Homutov <vl@nginx.com>
parents:
5260
diff
changeset
|
539 if (log->file != NULL) { |
777202558122
Added syslog support for error_log and access_log directives.
Vladimir Homutov <vl@nginx.com>
parents:
5260
diff
changeset
|
540 return log; |
777202558122
Added syslog support for error_log and access_log directives.
Vladimir Homutov <vl@nginx.com>
parents:
5260
diff
changeset
|
541 } |
777202558122
Added syslog support for error_log and access_log directives.
Vladimir Homutov <vl@nginx.com>
parents:
5260
diff
changeset
|
542 } |
777202558122
Added syslog support for error_log and access_log directives.
Vladimir Homutov <vl@nginx.com>
parents:
5260
diff
changeset
|
543 |
777202558122
Added syslog support for error_log and access_log directives.
Vladimir Homutov <vl@nginx.com>
parents:
5260
diff
changeset
|
544 return NULL; |
777202558122
Added syslog support for error_log and access_log directives.
Vladimir Homutov <vl@nginx.com>
parents:
5260
diff
changeset
|
545 } |
777202558122
Added syslog support for error_log and access_log directives.
Vladimir Homutov <vl@nginx.com>
parents:
5260
diff
changeset
|
546 |
777202558122
Added syslog support for error_log and access_log directives.
Vladimir Homutov <vl@nginx.com>
parents:
5260
diff
changeset
|
547 |
5254
7ecaa9e4bf1b
Core: support several "error_log" directives.
Vladimir Homutov <vl@nginx.com>
parents:
5250
diff
changeset
|
548 static char * |
2785
d478379e51ac
*) refactor error_log processing: listen socket log might inherit built-in
Igor Sysoev <igor@sysoev.ru>
parents:
2773
diff
changeset
|
549 ngx_error_log(ngx_conf_t *cf, ngx_command_t *cmd, void *conf) |
317
1308b98496a2
nginx-0.0.3-2004-04-15-19:34:36 import
Igor Sysoev <igor@sysoev.ru>
parents:
311
diff
changeset
|
550 { |
5254
7ecaa9e4bf1b
Core: support several "error_log" directives.
Vladimir Homutov <vl@nginx.com>
parents:
5250
diff
changeset
|
551 ngx_log_t *dummy; |
7ecaa9e4bf1b
Core: support several "error_log" directives.
Vladimir Homutov <vl@nginx.com>
parents:
5250
diff
changeset
|
552 |
7ecaa9e4bf1b
Core: support several "error_log" directives.
Vladimir Homutov <vl@nginx.com>
parents:
5250
diff
changeset
|
553 dummy = &cf->cycle->new_log; |
7ecaa9e4bf1b
Core: support several "error_log" directives.
Vladimir Homutov <vl@nginx.com>
parents:
5250
diff
changeset
|
554 |
7ecaa9e4bf1b
Core: support several "error_log" directives.
Vladimir Homutov <vl@nginx.com>
parents:
5250
diff
changeset
|
555 return ngx_log_set_log(cf, &dummy); |
7ecaa9e4bf1b
Core: support several "error_log" directives.
Vladimir Homutov <vl@nginx.com>
parents:
5250
diff
changeset
|
556 } |
7ecaa9e4bf1b
Core: support several "error_log" directives.
Vladimir Homutov <vl@nginx.com>
parents:
5250
diff
changeset
|
557 |
7ecaa9e4bf1b
Core: support several "error_log" directives.
Vladimir Homutov <vl@nginx.com>
parents:
5250
diff
changeset
|
558 |
7ecaa9e4bf1b
Core: support several "error_log" directives.
Vladimir Homutov <vl@nginx.com>
parents:
5250
diff
changeset
|
559 char * |
7ecaa9e4bf1b
Core: support several "error_log" directives.
Vladimir Homutov <vl@nginx.com>
parents:
5250
diff
changeset
|
560 ngx_log_set_log(ngx_conf_t *cf, ngx_log_t **head) |
7ecaa9e4bf1b
Core: support several "error_log" directives.
Vladimir Homutov <vl@nginx.com>
parents:
5250
diff
changeset
|
561 { |
5702
777202558122
Added syslog support for error_log and access_log directives.
Vladimir Homutov <vl@nginx.com>
parents:
5260
diff
changeset
|
562 ngx_log_t *new_log; |
777202558122
Added syslog support for error_log and access_log directives.
Vladimir Homutov <vl@nginx.com>
parents:
5260
diff
changeset
|
563 ngx_str_t *value, name; |
777202558122
Added syslog support for error_log and access_log directives.
Vladimir Homutov <vl@nginx.com>
parents:
5260
diff
changeset
|
564 ngx_syslog_peer_t *peer; |
2785
d478379e51ac
*) refactor error_log processing: listen socket log might inherit built-in
Igor Sysoev <igor@sysoev.ru>
parents:
2773
diff
changeset
|
565 |
5254
7ecaa9e4bf1b
Core: support several "error_log" directives.
Vladimir Homutov <vl@nginx.com>
parents:
5250
diff
changeset
|
566 if (*head != NULL && (*head)->log_level == 0) { |
7ecaa9e4bf1b
Core: support several "error_log" directives.
Vladimir Homutov <vl@nginx.com>
parents:
5250
diff
changeset
|
567 new_log = *head; |
7ecaa9e4bf1b
Core: support several "error_log" directives.
Vladimir Homutov <vl@nginx.com>
parents:
5250
diff
changeset
|
568 |
7ecaa9e4bf1b
Core: support several "error_log" directives.
Vladimir Homutov <vl@nginx.com>
parents:
5250
diff
changeset
|
569 } else { |
7ecaa9e4bf1b
Core: support several "error_log" directives.
Vladimir Homutov <vl@nginx.com>
parents:
5250
diff
changeset
|
570 |
7ecaa9e4bf1b
Core: support several "error_log" directives.
Vladimir Homutov <vl@nginx.com>
parents:
5250
diff
changeset
|
571 new_log = ngx_pcalloc(cf->pool, sizeof(ngx_log_t)); |
7ecaa9e4bf1b
Core: support several "error_log" directives.
Vladimir Homutov <vl@nginx.com>
parents:
5250
diff
changeset
|
572 if (new_log == NULL) { |
7ecaa9e4bf1b
Core: support several "error_log" directives.
Vladimir Homutov <vl@nginx.com>
parents:
5250
diff
changeset
|
573 return NGX_CONF_ERROR; |
7ecaa9e4bf1b
Core: support several "error_log" directives.
Vladimir Homutov <vl@nginx.com>
parents:
5250
diff
changeset
|
574 } |
7ecaa9e4bf1b
Core: support several "error_log" directives.
Vladimir Homutov <vl@nginx.com>
parents:
5250
diff
changeset
|
575 |
7ecaa9e4bf1b
Core: support several "error_log" directives.
Vladimir Homutov <vl@nginx.com>
parents:
5250
diff
changeset
|
576 if (*head == NULL) { |
7ecaa9e4bf1b
Core: support several "error_log" directives.
Vladimir Homutov <vl@nginx.com>
parents:
5250
diff
changeset
|
577 *head = new_log; |
7ecaa9e4bf1b
Core: support several "error_log" directives.
Vladimir Homutov <vl@nginx.com>
parents:
5250
diff
changeset
|
578 } |
2785
d478379e51ac
*) refactor error_log processing: listen socket log might inherit built-in
Igor Sysoev <igor@sysoev.ru>
parents:
2773
diff
changeset
|
579 } |
317
1308b98496a2
nginx-0.0.3-2004-04-15-19:34:36 import
Igor Sysoev <igor@sysoev.ru>
parents:
311
diff
changeset
|
580 |
1308b98496a2
nginx-0.0.3-2004-04-15-19:34:36 import
Igor Sysoev <igor@sysoev.ru>
parents:
311
diff
changeset
|
581 value = cf->args->elts; |
1308b98496a2
nginx-0.0.3-2004-04-15-19:34:36 import
Igor Sysoev <igor@sysoev.ru>
parents:
311
diff
changeset
|
582 |
2785
d478379e51ac
*) refactor error_log processing: listen socket log might inherit built-in
Igor Sysoev <igor@sysoev.ru>
parents:
2773
diff
changeset
|
583 if (ngx_strcmp(value[1].data, "stderr") == 0) { |
3516
dd1570b6f237
ngx_str_set() and ngx_str_null()
Igor Sysoev <igor@sysoev.ru>
parents:
2785
diff
changeset
|
584 ngx_str_null(&name); |
5240
d8af1005e886
Core: fixed handling of "stderr" in error_log.
Vladimir Homutov <vl@nginx.com>
parents:
4412
diff
changeset
|
585 cf->cycle->log_use_stderr = 1; |
317
1308b98496a2
nginx-0.0.3-2004-04-15-19:34:36 import
Igor Sysoev <igor@sysoev.ru>
parents:
311
diff
changeset
|
586 |
5702
777202558122
Added syslog support for error_log and access_log directives.
Vladimir Homutov <vl@nginx.com>
parents:
5260
diff
changeset
|
587 new_log->file = ngx_conf_open_file(cf->cycle, &name); |
777202558122
Added syslog support for error_log and access_log directives.
Vladimir Homutov <vl@nginx.com>
parents:
5260
diff
changeset
|
588 if (new_log->file == NULL) { |
777202558122
Added syslog support for error_log and access_log directives.
Vladimir Homutov <vl@nginx.com>
parents:
5260
diff
changeset
|
589 return NGX_CONF_ERROR; |
777202558122
Added syslog support for error_log and access_log directives.
Vladimir Homutov <vl@nginx.com>
parents:
5260
diff
changeset
|
590 } |
777202558122
Added syslog support for error_log and access_log directives.
Vladimir Homutov <vl@nginx.com>
parents:
5260
diff
changeset
|
591 |
6474 | 592 } else if (ngx_strncmp(value[1].data, "memory:", 7) == 0) { |
6033
8e66a83d16ae
Core: added cyclic memory buffer support for error_log.
Valentin Bartenev <vbart@nginx.com>
parents:
6000
diff
changeset
|
593 |
8e66a83d16ae
Core: added cyclic memory buffer support for error_log.
Valentin Bartenev <vbart@nginx.com>
parents:
6000
diff
changeset
|
594 #if (NGX_DEBUG) |
8e66a83d16ae
Core: added cyclic memory buffer support for error_log.
Valentin Bartenev <vbart@nginx.com>
parents:
6000
diff
changeset
|
595 size_t size, needed; |
8e66a83d16ae
Core: added cyclic memory buffer support for error_log.
Valentin Bartenev <vbart@nginx.com>
parents:
6000
diff
changeset
|
596 ngx_pool_cleanup_t *cln; |
8e66a83d16ae
Core: added cyclic memory buffer support for error_log.
Valentin Bartenev <vbart@nginx.com>
parents:
6000
diff
changeset
|
597 ngx_log_memory_buf_t *buf; |
8e66a83d16ae
Core: added cyclic memory buffer support for error_log.
Valentin Bartenev <vbart@nginx.com>
parents:
6000
diff
changeset
|
598 |
8e66a83d16ae
Core: added cyclic memory buffer support for error_log.
Valentin Bartenev <vbart@nginx.com>
parents:
6000
diff
changeset
|
599 value[1].len -= 7; |
8e66a83d16ae
Core: added cyclic memory buffer support for error_log.
Valentin Bartenev <vbart@nginx.com>
parents:
6000
diff
changeset
|
600 value[1].data += 7; |
8e66a83d16ae
Core: added cyclic memory buffer support for error_log.
Valentin Bartenev <vbart@nginx.com>
parents:
6000
diff
changeset
|
601 |
8e66a83d16ae
Core: added cyclic memory buffer support for error_log.
Valentin Bartenev <vbart@nginx.com>
parents:
6000
diff
changeset
|
602 needed = sizeof("MEMLOG :" NGX_LINEFEED) |
8e66a83d16ae
Core: added cyclic memory buffer support for error_log.
Valentin Bartenev <vbart@nginx.com>
parents:
6000
diff
changeset
|
603 + cf->conf_file->file.name.len |
8e66a83d16ae
Core: added cyclic memory buffer support for error_log.
Valentin Bartenev <vbart@nginx.com>
parents:
6000
diff
changeset
|
604 + NGX_SIZE_T_LEN |
8e66a83d16ae
Core: added cyclic memory buffer support for error_log.
Valentin Bartenev <vbart@nginx.com>
parents:
6000
diff
changeset
|
605 + NGX_INT_T_LEN |
8e66a83d16ae
Core: added cyclic memory buffer support for error_log.
Valentin Bartenev <vbart@nginx.com>
parents:
6000
diff
changeset
|
606 + NGX_MAX_ERROR_STR; |
8e66a83d16ae
Core: added cyclic memory buffer support for error_log.
Valentin Bartenev <vbart@nginx.com>
parents:
6000
diff
changeset
|
607 |
8e66a83d16ae
Core: added cyclic memory buffer support for error_log.
Valentin Bartenev <vbart@nginx.com>
parents:
6000
diff
changeset
|
608 size = ngx_parse_size(&value[1]); |
8e66a83d16ae
Core: added cyclic memory buffer support for error_log.
Valentin Bartenev <vbart@nginx.com>
parents:
6000
diff
changeset
|
609 |
8e66a83d16ae
Core: added cyclic memory buffer support for error_log.
Valentin Bartenev <vbart@nginx.com>
parents:
6000
diff
changeset
|
610 if (size == (size_t) NGX_ERROR || size < needed) { |
8e66a83d16ae
Core: added cyclic memory buffer support for error_log.
Valentin Bartenev <vbart@nginx.com>
parents:
6000
diff
changeset
|
611 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, |
8e66a83d16ae
Core: added cyclic memory buffer support for error_log.
Valentin Bartenev <vbart@nginx.com>
parents:
6000
diff
changeset
|
612 "invalid buffer size \"%V\"", &value[1]); |
8e66a83d16ae
Core: added cyclic memory buffer support for error_log.
Valentin Bartenev <vbart@nginx.com>
parents:
6000
diff
changeset
|
613 return NGX_CONF_ERROR; |
8e66a83d16ae
Core: added cyclic memory buffer support for error_log.
Valentin Bartenev <vbart@nginx.com>
parents:
6000
diff
changeset
|
614 } |
8e66a83d16ae
Core: added cyclic memory buffer support for error_log.
Valentin Bartenev <vbart@nginx.com>
parents:
6000
diff
changeset
|
615 |
6149
2c21bfe3da89
Core: properly initialized written bytes counter in memory log.
Valentin Bartenev <vbart@nginx.com>
parents:
6115
diff
changeset
|
616 buf = ngx_pcalloc(cf->pool, sizeof(ngx_log_memory_buf_t)); |
6033
8e66a83d16ae
Core: added cyclic memory buffer support for error_log.
Valentin Bartenev <vbart@nginx.com>
parents:
6000
diff
changeset
|
617 if (buf == NULL) { |
8e66a83d16ae
Core: added cyclic memory buffer support for error_log.
Valentin Bartenev <vbart@nginx.com>
parents:
6000
diff
changeset
|
618 return NGX_CONF_ERROR; |
8e66a83d16ae
Core: added cyclic memory buffer support for error_log.
Valentin Bartenev <vbart@nginx.com>
parents:
6000
diff
changeset
|
619 } |
8e66a83d16ae
Core: added cyclic memory buffer support for error_log.
Valentin Bartenev <vbart@nginx.com>
parents:
6000
diff
changeset
|
620 |
8e66a83d16ae
Core: added cyclic memory buffer support for error_log.
Valentin Bartenev <vbart@nginx.com>
parents:
6000
diff
changeset
|
621 buf->start = ngx_pnalloc(cf->pool, size); |
8e66a83d16ae
Core: added cyclic memory buffer support for error_log.
Valentin Bartenev <vbart@nginx.com>
parents:
6000
diff
changeset
|
622 if (buf->start == NULL) { |
8e66a83d16ae
Core: added cyclic memory buffer support for error_log.
Valentin Bartenev <vbart@nginx.com>
parents:
6000
diff
changeset
|
623 return NGX_CONF_ERROR; |
8e66a83d16ae
Core: added cyclic memory buffer support for error_log.
Valentin Bartenev <vbart@nginx.com>
parents:
6000
diff
changeset
|
624 } |
8e66a83d16ae
Core: added cyclic memory buffer support for error_log.
Valentin Bartenev <vbart@nginx.com>
parents:
6000
diff
changeset
|
625 |
8e66a83d16ae
Core: added cyclic memory buffer support for error_log.
Valentin Bartenev <vbart@nginx.com>
parents:
6000
diff
changeset
|
626 buf->end = buf->start + size; |
8e66a83d16ae
Core: added cyclic memory buffer support for error_log.
Valentin Bartenev <vbart@nginx.com>
parents:
6000
diff
changeset
|
627 |
8e66a83d16ae
Core: added cyclic memory buffer support for error_log.
Valentin Bartenev <vbart@nginx.com>
parents:
6000
diff
changeset
|
628 buf->pos = ngx_slprintf(buf->start, buf->end, "MEMLOG %uz %V:%ui%N", |
8e66a83d16ae
Core: added cyclic memory buffer support for error_log.
Valentin Bartenev <vbart@nginx.com>
parents:
6000
diff
changeset
|
629 size, &cf->conf_file->file.name, |
8e66a83d16ae
Core: added cyclic memory buffer support for error_log.
Valentin Bartenev <vbart@nginx.com>
parents:
6000
diff
changeset
|
630 cf->conf_file->line); |
8e66a83d16ae
Core: added cyclic memory buffer support for error_log.
Valentin Bartenev <vbart@nginx.com>
parents:
6000
diff
changeset
|
631 |
8e66a83d16ae
Core: added cyclic memory buffer support for error_log.
Valentin Bartenev <vbart@nginx.com>
parents:
6000
diff
changeset
|
632 ngx_memset(buf->pos, ' ', buf->end - buf->pos); |
8e66a83d16ae
Core: added cyclic memory buffer support for error_log.
Valentin Bartenev <vbart@nginx.com>
parents:
6000
diff
changeset
|
633 |
8e66a83d16ae
Core: added cyclic memory buffer support for error_log.
Valentin Bartenev <vbart@nginx.com>
parents:
6000
diff
changeset
|
634 cln = ngx_pool_cleanup_add(cf->pool, 0); |
8e66a83d16ae
Core: added cyclic memory buffer support for error_log.
Valentin Bartenev <vbart@nginx.com>
parents:
6000
diff
changeset
|
635 if (cln == NULL) { |
8e66a83d16ae
Core: added cyclic memory buffer support for error_log.
Valentin Bartenev <vbart@nginx.com>
parents:
6000
diff
changeset
|
636 return NGX_CONF_ERROR; |
8e66a83d16ae
Core: added cyclic memory buffer support for error_log.
Valentin Bartenev <vbart@nginx.com>
parents:
6000
diff
changeset
|
637 } |
8e66a83d16ae
Core: added cyclic memory buffer support for error_log.
Valentin Bartenev <vbart@nginx.com>
parents:
6000
diff
changeset
|
638 |
8e66a83d16ae
Core: added cyclic memory buffer support for error_log.
Valentin Bartenev <vbart@nginx.com>
parents:
6000
diff
changeset
|
639 cln->data = new_log; |
8e66a83d16ae
Core: added cyclic memory buffer support for error_log.
Valentin Bartenev <vbart@nginx.com>
parents:
6000
diff
changeset
|
640 cln->handler = ngx_log_memory_cleanup; |
8e66a83d16ae
Core: added cyclic memory buffer support for error_log.
Valentin Bartenev <vbart@nginx.com>
parents:
6000
diff
changeset
|
641 |
8e66a83d16ae
Core: added cyclic memory buffer support for error_log.
Valentin Bartenev <vbart@nginx.com>
parents:
6000
diff
changeset
|
642 new_log->writer = ngx_log_memory_writer; |
8e66a83d16ae
Core: added cyclic memory buffer support for error_log.
Valentin Bartenev <vbart@nginx.com>
parents:
6000
diff
changeset
|
643 new_log->wdata = buf; |
8e66a83d16ae
Core: added cyclic memory buffer support for error_log.
Valentin Bartenev <vbart@nginx.com>
parents:
6000
diff
changeset
|
644 |
8e66a83d16ae
Core: added cyclic memory buffer support for error_log.
Valentin Bartenev <vbart@nginx.com>
parents:
6000
diff
changeset
|
645 #else |
8e66a83d16ae
Core: added cyclic memory buffer support for error_log.
Valentin Bartenev <vbart@nginx.com>
parents:
6000
diff
changeset
|
646 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, |
8e66a83d16ae
Core: added cyclic memory buffer support for error_log.
Valentin Bartenev <vbart@nginx.com>
parents:
6000
diff
changeset
|
647 "nginx was built without debug support"); |
8e66a83d16ae
Core: added cyclic memory buffer support for error_log.
Valentin Bartenev <vbart@nginx.com>
parents:
6000
diff
changeset
|
648 return NGX_CONF_ERROR; |
8e66a83d16ae
Core: added cyclic memory buffer support for error_log.
Valentin Bartenev <vbart@nginx.com>
parents:
6000
diff
changeset
|
649 #endif |
5702
777202558122
Added syslog support for error_log and access_log directives.
Vladimir Homutov <vl@nginx.com>
parents:
5260
diff
changeset
|
650 |
6474 | 651 } else if (ngx_strncmp(value[1].data, "syslog:", 7) == 0) { |
5702
777202558122
Added syslog support for error_log and access_log directives.
Vladimir Homutov <vl@nginx.com>
parents:
5260
diff
changeset
|
652 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:
5260
diff
changeset
|
653 if (peer == NULL) { |
777202558122
Added syslog support for error_log and access_log directives.
Vladimir Homutov <vl@nginx.com>
parents:
5260
diff
changeset
|
654 return NGX_CONF_ERROR; |
777202558122
Added syslog support for error_log and access_log directives.
Vladimir Homutov <vl@nginx.com>
parents:
5260
diff
changeset
|
655 } |
445
f26432a1935a
nginx-0.1.0-2004-09-30-10:38:49 import
Igor Sysoev <igor@sysoev.ru>
parents:
444
diff
changeset
|
656 |
5702
777202558122
Added syslog support for error_log and access_log directives.
Vladimir Homutov <vl@nginx.com>
parents:
5260
diff
changeset
|
657 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:
5260
diff
changeset
|
658 return NGX_CONF_ERROR; |
777202558122
Added syslog support for error_log and access_log directives.
Vladimir Homutov <vl@nginx.com>
parents:
5260
diff
changeset
|
659 } |
777202558122
Added syslog support for error_log and access_log directives.
Vladimir Homutov <vl@nginx.com>
parents:
5260
diff
changeset
|
660 |
777202558122
Added syslog support for error_log and access_log directives.
Vladimir Homutov <vl@nginx.com>
parents:
5260
diff
changeset
|
661 new_log->writer = ngx_syslog_writer; |
777202558122
Added syslog support for error_log and access_log directives.
Vladimir Homutov <vl@nginx.com>
parents:
5260
diff
changeset
|
662 new_log->wdata = peer; |
777202558122
Added syslog support for error_log and access_log directives.
Vladimir Homutov <vl@nginx.com>
parents:
5260
diff
changeset
|
663 |
777202558122
Added syslog support for error_log and access_log directives.
Vladimir Homutov <vl@nginx.com>
parents:
5260
diff
changeset
|
664 } else { |
777202558122
Added syslog support for error_log and access_log directives.
Vladimir Homutov <vl@nginx.com>
parents:
5260
diff
changeset
|
665 new_log->file = ngx_conf_open_file(cf->cycle, &value[1]); |
777202558122
Added syslog support for error_log and access_log directives.
Vladimir Homutov <vl@nginx.com>
parents:
5260
diff
changeset
|
666 if (new_log->file == NULL) { |
777202558122
Added syslog support for error_log and access_log directives.
Vladimir Homutov <vl@nginx.com>
parents:
5260
diff
changeset
|
667 return NGX_CONF_ERROR; |
777202558122
Added syslog support for error_log and access_log directives.
Vladimir Homutov <vl@nginx.com>
parents:
5260
diff
changeset
|
668 } |
5254
7ecaa9e4bf1b
Core: support several "error_log" directives.
Vladimir Homutov <vl@nginx.com>
parents:
5250
diff
changeset
|
669 } |
7ecaa9e4bf1b
Core: support several "error_log" directives.
Vladimir Homutov <vl@nginx.com>
parents:
5250
diff
changeset
|
670 |
9299
2706b60dc225
Core: error logging rate limiting.
Maxim Dounin <mdounin@mdounin.ru>
parents:
9298
diff
changeset
|
671 if (ngx_log_set_params(cf, new_log) != NGX_CONF_OK) { |
5254
7ecaa9e4bf1b
Core: support several "error_log" directives.
Vladimir Homutov <vl@nginx.com>
parents:
5250
diff
changeset
|
672 return NGX_CONF_ERROR; |
7ecaa9e4bf1b
Core: support several "error_log" directives.
Vladimir Homutov <vl@nginx.com>
parents:
5250
diff
changeset
|
673 } |
7ecaa9e4bf1b
Core: support several "error_log" directives.
Vladimir Homutov <vl@nginx.com>
parents:
5250
diff
changeset
|
674 |
7ecaa9e4bf1b
Core: support several "error_log" directives.
Vladimir Homutov <vl@nginx.com>
parents:
5250
diff
changeset
|
675 if (*head != new_log) { |
7ecaa9e4bf1b
Core: support several "error_log" directives.
Vladimir Homutov <vl@nginx.com>
parents:
5250
diff
changeset
|
676 ngx_log_insert(*head, new_log); |
317
1308b98496a2
nginx-0.0.3-2004-04-15-19:34:36 import
Igor Sysoev <igor@sysoev.ru>
parents:
311
diff
changeset
|
677 } |
1308b98496a2
nginx-0.0.3-2004-04-15-19:34:36 import
Igor Sysoev <igor@sysoev.ru>
parents:
311
diff
changeset
|
678 |
5254
7ecaa9e4bf1b
Core: support several "error_log" directives.
Vladimir Homutov <vl@nginx.com>
parents:
5250
diff
changeset
|
679 return NGX_CONF_OK; |
7ecaa9e4bf1b
Core: support several "error_log" directives.
Vladimir Homutov <vl@nginx.com>
parents:
5250
diff
changeset
|
680 } |
7ecaa9e4bf1b
Core: support several "error_log" directives.
Vladimir Homutov <vl@nginx.com>
parents:
5250
diff
changeset
|
681 |
7ecaa9e4bf1b
Core: support several "error_log" directives.
Vladimir Homutov <vl@nginx.com>
parents:
5250
diff
changeset
|
682 |
9297
e1f15d47d102
Core: moved ngx_log_set_levels() to a proper position.
Maxim Dounin <mdounin@mdounin.ru>
parents:
9296
diff
changeset
|
683 static char * |
9299
2706b60dc225
Core: error logging rate limiting.
Maxim Dounin <mdounin@mdounin.ru>
parents:
9298
diff
changeset
|
684 ngx_log_set_params(ngx_conf_t *cf, ngx_log_t *log) |
9297
e1f15d47d102
Core: moved ngx_log_set_levels() to a proper position.
Maxim Dounin <mdounin@mdounin.ru>
parents:
9296
diff
changeset
|
685 { |
9299
2706b60dc225
Core: error logging rate limiting.
Maxim Dounin <mdounin@mdounin.ru>
parents:
9298
diff
changeset
|
686 size_t len; |
2706b60dc225
Core: error logging rate limiting.
Maxim Dounin <mdounin@mdounin.ru>
parents:
9298
diff
changeset
|
687 ngx_int_t rate; |
9298
14770557be17
Core: simplified log levels matching.
Maxim Dounin <mdounin@mdounin.ru>
parents:
9297
diff
changeset
|
688 ngx_uint_t i, n, d; |
9297
e1f15d47d102
Core: moved ngx_log_set_levels() to a proper position.
Maxim Dounin <mdounin@mdounin.ru>
parents:
9296
diff
changeset
|
689 ngx_str_t *value; |
e1f15d47d102
Core: moved ngx_log_set_levels() to a proper position.
Maxim Dounin <mdounin@mdounin.ru>
parents:
9296
diff
changeset
|
690 |
e1f15d47d102
Core: moved ngx_log_set_levels() to a proper position.
Maxim Dounin <mdounin@mdounin.ru>
parents:
9296
diff
changeset
|
691 value = cf->args->elts; |
e1f15d47d102
Core: moved ngx_log_set_levels() to a proper position.
Maxim Dounin <mdounin@mdounin.ru>
parents:
9296
diff
changeset
|
692 |
9299
2706b60dc225
Core: error logging rate limiting.
Maxim Dounin <mdounin@mdounin.ru>
parents:
9298
diff
changeset
|
693 rate = 1000; |
2706b60dc225
Core: error logging rate limiting.
Maxim Dounin <mdounin@mdounin.ru>
parents:
9298
diff
changeset
|
694 |
9297
e1f15d47d102
Core: moved ngx_log_set_levels() to a proper position.
Maxim Dounin <mdounin@mdounin.ru>
parents:
9296
diff
changeset
|
695 for (i = 2; i < cf->args->nelts; i++) { |
e1f15d47d102
Core: moved ngx_log_set_levels() to a proper position.
Maxim Dounin <mdounin@mdounin.ru>
parents:
9296
diff
changeset
|
696 |
e1f15d47d102
Core: moved ngx_log_set_levels() to a proper position.
Maxim Dounin <mdounin@mdounin.ru>
parents:
9296
diff
changeset
|
697 for (n = 1; n <= NGX_LOG_DEBUG; n++) { |
e1f15d47d102
Core: moved ngx_log_set_levels() to a proper position.
Maxim Dounin <mdounin@mdounin.ru>
parents:
9296
diff
changeset
|
698 if (ngx_strcmp(value[i].data, err_levels[n].data) == 0) { |
e1f15d47d102
Core: moved ngx_log_set_levels() to a proper position.
Maxim Dounin <mdounin@mdounin.ru>
parents:
9296
diff
changeset
|
699 |
e1f15d47d102
Core: moved ngx_log_set_levels() to a proper position.
Maxim Dounin <mdounin@mdounin.ru>
parents:
9296
diff
changeset
|
700 if (log->log_level != 0) { |
e1f15d47d102
Core: moved ngx_log_set_levels() to a proper position.
Maxim Dounin <mdounin@mdounin.ru>
parents:
9296
diff
changeset
|
701 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, |
e1f15d47d102
Core: moved ngx_log_set_levels() to a proper position.
Maxim Dounin <mdounin@mdounin.ru>
parents:
9296
diff
changeset
|
702 "duplicate log level \"%V\"", |
e1f15d47d102
Core: moved ngx_log_set_levels() to a proper position.
Maxim Dounin <mdounin@mdounin.ru>
parents:
9296
diff
changeset
|
703 &value[i]); |
e1f15d47d102
Core: moved ngx_log_set_levels() to a proper position.
Maxim Dounin <mdounin@mdounin.ru>
parents:
9296
diff
changeset
|
704 return NGX_CONF_ERROR; |
e1f15d47d102
Core: moved ngx_log_set_levels() to a proper position.
Maxim Dounin <mdounin@mdounin.ru>
parents:
9296
diff
changeset
|
705 } |
e1f15d47d102
Core: moved ngx_log_set_levels() to a proper position.
Maxim Dounin <mdounin@mdounin.ru>
parents:
9296
diff
changeset
|
706 |
e1f15d47d102
Core: moved ngx_log_set_levels() to a proper position.
Maxim Dounin <mdounin@mdounin.ru>
parents:
9296
diff
changeset
|
707 log->log_level = n; |
9298
14770557be17
Core: simplified log levels matching.
Maxim Dounin <mdounin@mdounin.ru>
parents:
9297
diff
changeset
|
708 goto next; |
9297
e1f15d47d102
Core: moved ngx_log_set_levels() to a proper position.
Maxim Dounin <mdounin@mdounin.ru>
parents:
9296
diff
changeset
|
709 } |
e1f15d47d102
Core: moved ngx_log_set_levels() to a proper position.
Maxim Dounin <mdounin@mdounin.ru>
parents:
9296
diff
changeset
|
710 } |
e1f15d47d102
Core: moved ngx_log_set_levels() to a proper position.
Maxim Dounin <mdounin@mdounin.ru>
parents:
9296
diff
changeset
|
711 |
e1f15d47d102
Core: moved ngx_log_set_levels() to a proper position.
Maxim Dounin <mdounin@mdounin.ru>
parents:
9296
diff
changeset
|
712 for (n = 0, d = NGX_LOG_DEBUG_FIRST; d <= NGX_LOG_DEBUG_LAST; d <<= 1) { |
e1f15d47d102
Core: moved ngx_log_set_levels() to a proper position.
Maxim Dounin <mdounin@mdounin.ru>
parents:
9296
diff
changeset
|
713 if (ngx_strcmp(value[i].data, debug_levels[n++]) == 0) { |
e1f15d47d102
Core: moved ngx_log_set_levels() to a proper position.
Maxim Dounin <mdounin@mdounin.ru>
parents:
9296
diff
changeset
|
714 if (log->log_level & ~NGX_LOG_DEBUG_ALL) { |
e1f15d47d102
Core: moved ngx_log_set_levels() to a proper position.
Maxim Dounin <mdounin@mdounin.ru>
parents:
9296
diff
changeset
|
715 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, |
e1f15d47d102
Core: moved ngx_log_set_levels() to a proper position.
Maxim Dounin <mdounin@mdounin.ru>
parents:
9296
diff
changeset
|
716 "invalid log level \"%V\"", |
e1f15d47d102
Core: moved ngx_log_set_levels() to a proper position.
Maxim Dounin <mdounin@mdounin.ru>
parents:
9296
diff
changeset
|
717 &value[i]); |
e1f15d47d102
Core: moved ngx_log_set_levels() to a proper position.
Maxim Dounin <mdounin@mdounin.ru>
parents:
9296
diff
changeset
|
718 return NGX_CONF_ERROR; |
e1f15d47d102
Core: moved ngx_log_set_levels() to a proper position.
Maxim Dounin <mdounin@mdounin.ru>
parents:
9296
diff
changeset
|
719 } |
e1f15d47d102
Core: moved ngx_log_set_levels() to a proper position.
Maxim Dounin <mdounin@mdounin.ru>
parents:
9296
diff
changeset
|
720 |
e1f15d47d102
Core: moved ngx_log_set_levels() to a proper position.
Maxim Dounin <mdounin@mdounin.ru>
parents:
9296
diff
changeset
|
721 log->log_level |= d; |
9298
14770557be17
Core: simplified log levels matching.
Maxim Dounin <mdounin@mdounin.ru>
parents:
9297
diff
changeset
|
722 goto next; |
9297
e1f15d47d102
Core: moved ngx_log_set_levels() to a proper position.
Maxim Dounin <mdounin@mdounin.ru>
parents:
9296
diff
changeset
|
723 } |
e1f15d47d102
Core: moved ngx_log_set_levels() to a proper position.
Maxim Dounin <mdounin@mdounin.ru>
parents:
9296
diff
changeset
|
724 } |
e1f15d47d102
Core: moved ngx_log_set_levels() to a proper position.
Maxim Dounin <mdounin@mdounin.ru>
parents:
9296
diff
changeset
|
725 |
9299
2706b60dc225
Core: error logging rate limiting.
Maxim Dounin <mdounin@mdounin.ru>
parents:
9298
diff
changeset
|
726 if (ngx_strncmp(value[i].data, "rate=", 5) == 0) { |
2706b60dc225
Core: error logging rate limiting.
Maxim Dounin <mdounin@mdounin.ru>
parents:
9298
diff
changeset
|
727 |
2706b60dc225
Core: error logging rate limiting.
Maxim Dounin <mdounin@mdounin.ru>
parents:
9298
diff
changeset
|
728 len = value[i].len; |
2706b60dc225
Core: error logging rate limiting.
Maxim Dounin <mdounin@mdounin.ru>
parents:
9298
diff
changeset
|
729 |
2706b60dc225
Core: error logging rate limiting.
Maxim Dounin <mdounin@mdounin.ru>
parents:
9298
diff
changeset
|
730 if (ngx_strncmp(value[i].data + len - 3, "m/s", 3) == 0) { |
2706b60dc225
Core: error logging rate limiting.
Maxim Dounin <mdounin@mdounin.ru>
parents:
9298
diff
changeset
|
731 len -= 3; |
2706b60dc225
Core: error logging rate limiting.
Maxim Dounin <mdounin@mdounin.ru>
parents:
9298
diff
changeset
|
732 } |
2706b60dc225
Core: error logging rate limiting.
Maxim Dounin <mdounin@mdounin.ru>
parents:
9298
diff
changeset
|
733 |
2706b60dc225
Core: error logging rate limiting.
Maxim Dounin <mdounin@mdounin.ru>
parents:
9298
diff
changeset
|
734 rate = ngx_atoi(value[i].data + 5, len - 5); |
2706b60dc225
Core: error logging rate limiting.
Maxim Dounin <mdounin@mdounin.ru>
parents:
9298
diff
changeset
|
735 if (rate < 0) { |
2706b60dc225
Core: error logging rate limiting.
Maxim Dounin <mdounin@mdounin.ru>
parents:
9298
diff
changeset
|
736 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, |
2706b60dc225
Core: error logging rate limiting.
Maxim Dounin <mdounin@mdounin.ru>
parents:
9298
diff
changeset
|
737 "invalid rate \"%V\"", &value[i]); |
2706b60dc225
Core: error logging rate limiting.
Maxim Dounin <mdounin@mdounin.ru>
parents:
9298
diff
changeset
|
738 return NGX_CONF_ERROR; |
2706b60dc225
Core: error logging rate limiting.
Maxim Dounin <mdounin@mdounin.ru>
parents:
9298
diff
changeset
|
739 } |
2706b60dc225
Core: error logging rate limiting.
Maxim Dounin <mdounin@mdounin.ru>
parents:
9298
diff
changeset
|
740 |
2706b60dc225
Core: error logging rate limiting.
Maxim Dounin <mdounin@mdounin.ru>
parents:
9298
diff
changeset
|
741 continue; |
2706b60dc225
Core: error logging rate limiting.
Maxim Dounin <mdounin@mdounin.ru>
parents:
9298
diff
changeset
|
742 } |
2706b60dc225
Core: error logging rate limiting.
Maxim Dounin <mdounin@mdounin.ru>
parents:
9298
diff
changeset
|
743 |
2706b60dc225
Core: error logging rate limiting.
Maxim Dounin <mdounin@mdounin.ru>
parents:
9298
diff
changeset
|
744 if (log->log_level) { |
2706b60dc225
Core: error logging rate limiting.
Maxim Dounin <mdounin@mdounin.ru>
parents:
9298
diff
changeset
|
745 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, |
2706b60dc225
Core: error logging rate limiting.
Maxim Dounin <mdounin@mdounin.ru>
parents:
9298
diff
changeset
|
746 "invalid parameter \"%V\"", &value[i]); |
2706b60dc225
Core: error logging rate limiting.
Maxim Dounin <mdounin@mdounin.ru>
parents:
9298
diff
changeset
|
747 |
2706b60dc225
Core: error logging rate limiting.
Maxim Dounin <mdounin@mdounin.ru>
parents:
9298
diff
changeset
|
748 } else { |
2706b60dc225
Core: error logging rate limiting.
Maxim Dounin <mdounin@mdounin.ru>
parents:
9298
diff
changeset
|
749 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, |
2706b60dc225
Core: error logging rate limiting.
Maxim Dounin <mdounin@mdounin.ru>
parents:
9298
diff
changeset
|
750 "invalid log level \"%V\"", &value[i]); |
2706b60dc225
Core: error logging rate limiting.
Maxim Dounin <mdounin@mdounin.ru>
parents:
9298
diff
changeset
|
751 } |
2706b60dc225
Core: error logging rate limiting.
Maxim Dounin <mdounin@mdounin.ru>
parents:
9298
diff
changeset
|
752 |
9298
14770557be17
Core: simplified log levels matching.
Maxim Dounin <mdounin@mdounin.ru>
parents:
9297
diff
changeset
|
753 return NGX_CONF_ERROR; |
9297
e1f15d47d102
Core: moved ngx_log_set_levels() to a proper position.
Maxim Dounin <mdounin@mdounin.ru>
parents:
9296
diff
changeset
|
754 |
9298
14770557be17
Core: simplified log levels matching.
Maxim Dounin <mdounin@mdounin.ru>
parents:
9297
diff
changeset
|
755 next: |
14770557be17
Core: simplified log levels matching.
Maxim Dounin <mdounin@mdounin.ru>
parents:
9297
diff
changeset
|
756 |
14770557be17
Core: simplified log levels matching.
Maxim Dounin <mdounin@mdounin.ru>
parents:
9297
diff
changeset
|
757 continue; |
14770557be17
Core: simplified log levels matching.
Maxim Dounin <mdounin@mdounin.ru>
parents:
9297
diff
changeset
|
758 } |
14770557be17
Core: simplified log levels matching.
Maxim Dounin <mdounin@mdounin.ru>
parents:
9297
diff
changeset
|
759 |
14770557be17
Core: simplified log levels matching.
Maxim Dounin <mdounin@mdounin.ru>
parents:
9297
diff
changeset
|
760 if (log->log_level == 0) { |
14770557be17
Core: simplified log levels matching.
Maxim Dounin <mdounin@mdounin.ru>
parents:
9297
diff
changeset
|
761 log->log_level = NGX_LOG_ERR; |
9297
e1f15d47d102
Core: moved ngx_log_set_levels() to a proper position.
Maxim Dounin <mdounin@mdounin.ru>
parents:
9296
diff
changeset
|
762 } |
e1f15d47d102
Core: moved ngx_log_set_levels() to a proper position.
Maxim Dounin <mdounin@mdounin.ru>
parents:
9296
diff
changeset
|
763 |
e1f15d47d102
Core: moved ngx_log_set_levels() to a proper position.
Maxim Dounin <mdounin@mdounin.ru>
parents:
9296
diff
changeset
|
764 if (log->log_level == NGX_LOG_DEBUG) { |
e1f15d47d102
Core: moved ngx_log_set_levels() to a proper position.
Maxim Dounin <mdounin@mdounin.ru>
parents:
9296
diff
changeset
|
765 log->log_level = NGX_LOG_DEBUG_ALL; |
e1f15d47d102
Core: moved ngx_log_set_levels() to a proper position.
Maxim Dounin <mdounin@mdounin.ru>
parents:
9296
diff
changeset
|
766 } |
e1f15d47d102
Core: moved ngx_log_set_levels() to a proper position.
Maxim Dounin <mdounin@mdounin.ru>
parents:
9296
diff
changeset
|
767 |
9299
2706b60dc225
Core: error logging rate limiting.
Maxim Dounin <mdounin@mdounin.ru>
parents:
9298
diff
changeset
|
768 if (rate > 0 |
2706b60dc225
Core: error logging rate limiting.
Maxim Dounin <mdounin@mdounin.ru>
parents:
9298
diff
changeset
|
769 && log->log_level < NGX_LOG_DEBUG) |
2706b60dc225
Core: error logging rate limiting.
Maxim Dounin <mdounin@mdounin.ru>
parents:
9298
diff
changeset
|
770 { |
2706b60dc225
Core: error logging rate limiting.
Maxim Dounin <mdounin@mdounin.ru>
parents:
9298
diff
changeset
|
771 log->limit = ngx_pcalloc(cf->pool, sizeof(ngx_log_limit_t)); |
2706b60dc225
Core: error logging rate limiting.
Maxim Dounin <mdounin@mdounin.ru>
parents:
9298
diff
changeset
|
772 if (log->limit == NULL) { |
2706b60dc225
Core: error logging rate limiting.
Maxim Dounin <mdounin@mdounin.ru>
parents:
9298
diff
changeset
|
773 return NGX_CONF_ERROR; |
2706b60dc225
Core: error logging rate limiting.
Maxim Dounin <mdounin@mdounin.ru>
parents:
9298
diff
changeset
|
774 } |
2706b60dc225
Core: error logging rate limiting.
Maxim Dounin <mdounin@mdounin.ru>
parents:
9298
diff
changeset
|
775 |
2706b60dc225
Core: error logging rate limiting.
Maxim Dounin <mdounin@mdounin.ru>
parents:
9298
diff
changeset
|
776 log->limit->rate = rate * 1000; |
2706b60dc225
Core: error logging rate limiting.
Maxim Dounin <mdounin@mdounin.ru>
parents:
9298
diff
changeset
|
777 } |
2706b60dc225
Core: error logging rate limiting.
Maxim Dounin <mdounin@mdounin.ru>
parents:
9298
diff
changeset
|
778 |
9297
e1f15d47d102
Core: moved ngx_log_set_levels() to a proper position.
Maxim Dounin <mdounin@mdounin.ru>
parents:
9296
diff
changeset
|
779 return NGX_CONF_OK; |
e1f15d47d102
Core: moved ngx_log_set_levels() to a proper position.
Maxim Dounin <mdounin@mdounin.ru>
parents:
9296
diff
changeset
|
780 } |
e1f15d47d102
Core: moved ngx_log_set_levels() to a proper position.
Maxim Dounin <mdounin@mdounin.ru>
parents:
9296
diff
changeset
|
781 |
e1f15d47d102
Core: moved ngx_log_set_levels() to a proper position.
Maxim Dounin <mdounin@mdounin.ru>
parents:
9296
diff
changeset
|
782 |
5254
7ecaa9e4bf1b
Core: support several "error_log" directives.
Vladimir Homutov <vl@nginx.com>
parents:
5250
diff
changeset
|
783 static void |
7ecaa9e4bf1b
Core: support several "error_log" directives.
Vladimir Homutov <vl@nginx.com>
parents:
5250
diff
changeset
|
784 ngx_log_insert(ngx_log_t *log, ngx_log_t *new_log) |
7ecaa9e4bf1b
Core: support several "error_log" directives.
Vladimir Homutov <vl@nginx.com>
parents:
5250
diff
changeset
|
785 { |
7ecaa9e4bf1b
Core: support several "error_log" directives.
Vladimir Homutov <vl@nginx.com>
parents:
5250
diff
changeset
|
786 ngx_log_t tmp; |
7ecaa9e4bf1b
Core: support several "error_log" directives.
Vladimir Homutov <vl@nginx.com>
parents:
5250
diff
changeset
|
787 |
7ecaa9e4bf1b
Core: support several "error_log" directives.
Vladimir Homutov <vl@nginx.com>
parents:
5250
diff
changeset
|
788 if (new_log->log_level > log->log_level) { |
7ecaa9e4bf1b
Core: support several "error_log" directives.
Vladimir Homutov <vl@nginx.com>
parents:
5250
diff
changeset
|
789 |
7ecaa9e4bf1b
Core: support several "error_log" directives.
Vladimir Homutov <vl@nginx.com>
parents:
5250
diff
changeset
|
790 /* |
7ecaa9e4bf1b
Core: support several "error_log" directives.
Vladimir Homutov <vl@nginx.com>
parents:
5250
diff
changeset
|
791 * list head address is permanent, insert new log after |
7ecaa9e4bf1b
Core: support several "error_log" directives.
Vladimir Homutov <vl@nginx.com>
parents:
5250
diff
changeset
|
792 * head and swap its contents with head |
7ecaa9e4bf1b
Core: support several "error_log" directives.
Vladimir Homutov <vl@nginx.com>
parents:
5250
diff
changeset
|
793 */ |
7ecaa9e4bf1b
Core: support several "error_log" directives.
Vladimir Homutov <vl@nginx.com>
parents:
5250
diff
changeset
|
794 |
7ecaa9e4bf1b
Core: support several "error_log" directives.
Vladimir Homutov <vl@nginx.com>
parents:
5250
diff
changeset
|
795 tmp = *log; |
7ecaa9e4bf1b
Core: support several "error_log" directives.
Vladimir Homutov <vl@nginx.com>
parents:
5250
diff
changeset
|
796 *log = *new_log; |
7ecaa9e4bf1b
Core: support several "error_log" directives.
Vladimir Homutov <vl@nginx.com>
parents:
5250
diff
changeset
|
797 *new_log = tmp; |
7ecaa9e4bf1b
Core: support several "error_log" directives.
Vladimir Homutov <vl@nginx.com>
parents:
5250
diff
changeset
|
798 |
7ecaa9e4bf1b
Core: support several "error_log" directives.
Vladimir Homutov <vl@nginx.com>
parents:
5250
diff
changeset
|
799 log->next = new_log; |
7ecaa9e4bf1b
Core: support several "error_log" directives.
Vladimir Homutov <vl@nginx.com>
parents:
5250
diff
changeset
|
800 return; |
2785
d478379e51ac
*) refactor error_log processing: listen socket log might inherit built-in
Igor Sysoev <igor@sysoev.ru>
parents:
2773
diff
changeset
|
801 } |
d478379e51ac
*) refactor error_log processing: listen socket log might inherit built-in
Igor Sysoev <igor@sysoev.ru>
parents:
2773
diff
changeset
|
802 |
5254
7ecaa9e4bf1b
Core: support several "error_log" directives.
Vladimir Homutov <vl@nginx.com>
parents:
5250
diff
changeset
|
803 while (log->next) { |
7ecaa9e4bf1b
Core: support several "error_log" directives.
Vladimir Homutov <vl@nginx.com>
parents:
5250
diff
changeset
|
804 if (new_log->log_level > log->next->log_level) { |
7ecaa9e4bf1b
Core: support several "error_log" directives.
Vladimir Homutov <vl@nginx.com>
parents:
5250
diff
changeset
|
805 new_log->next = log->next; |
7ecaa9e4bf1b
Core: support several "error_log" directives.
Vladimir Homutov <vl@nginx.com>
parents:
5250
diff
changeset
|
806 log->next = new_log; |
7ecaa9e4bf1b
Core: support several "error_log" directives.
Vladimir Homutov <vl@nginx.com>
parents:
5250
diff
changeset
|
807 return; |
7ecaa9e4bf1b
Core: support several "error_log" directives.
Vladimir Homutov <vl@nginx.com>
parents:
5250
diff
changeset
|
808 } |
7ecaa9e4bf1b
Core: support several "error_log" directives.
Vladimir Homutov <vl@nginx.com>
parents:
5250
diff
changeset
|
809 |
7ecaa9e4bf1b
Core: support several "error_log" directives.
Vladimir Homutov <vl@nginx.com>
parents:
5250
diff
changeset
|
810 log = log->next; |
7ecaa9e4bf1b
Core: support several "error_log" directives.
Vladimir Homutov <vl@nginx.com>
parents:
5250
diff
changeset
|
811 } |
7ecaa9e4bf1b
Core: support several "error_log" directives.
Vladimir Homutov <vl@nginx.com>
parents:
5250
diff
changeset
|
812 |
7ecaa9e4bf1b
Core: support several "error_log" directives.
Vladimir Homutov <vl@nginx.com>
parents:
5250
diff
changeset
|
813 log->next = new_log; |
317
1308b98496a2
nginx-0.0.3-2004-04-15-19:34:36 import
Igor Sysoev <igor@sysoev.ru>
parents:
311
diff
changeset
|
814 } |
6033
8e66a83d16ae
Core: added cyclic memory buffer support for error_log.
Valentin Bartenev <vbart@nginx.com>
parents:
6000
diff
changeset
|
815 |
8e66a83d16ae
Core: added cyclic memory buffer support for error_log.
Valentin Bartenev <vbart@nginx.com>
parents:
6000
diff
changeset
|
816 |
8e66a83d16ae
Core: added cyclic memory buffer support for error_log.
Valentin Bartenev <vbart@nginx.com>
parents:
6000
diff
changeset
|
817 #if (NGX_DEBUG) |
8e66a83d16ae
Core: added cyclic memory buffer support for error_log.
Valentin Bartenev <vbart@nginx.com>
parents:
6000
diff
changeset
|
818 |
8e66a83d16ae
Core: added cyclic memory buffer support for error_log.
Valentin Bartenev <vbart@nginx.com>
parents:
6000
diff
changeset
|
819 static void |
8e66a83d16ae
Core: added cyclic memory buffer support for error_log.
Valentin Bartenev <vbart@nginx.com>
parents:
6000
diff
changeset
|
820 ngx_log_memory_writer(ngx_log_t *log, ngx_uint_t level, u_char *buf, |
8e66a83d16ae
Core: added cyclic memory buffer support for error_log.
Valentin Bartenev <vbart@nginx.com>
parents:
6000
diff
changeset
|
821 size_t len) |
8e66a83d16ae
Core: added cyclic memory buffer support for error_log.
Valentin Bartenev <vbart@nginx.com>
parents:
6000
diff
changeset
|
822 { |
8e66a83d16ae
Core: added cyclic memory buffer support for error_log.
Valentin Bartenev <vbart@nginx.com>
parents:
6000
diff
changeset
|
823 u_char *p; |
8e66a83d16ae
Core: added cyclic memory buffer support for error_log.
Valentin Bartenev <vbart@nginx.com>
parents:
6000
diff
changeset
|
824 size_t avail, written; |
8e66a83d16ae
Core: added cyclic memory buffer support for error_log.
Valentin Bartenev <vbart@nginx.com>
parents:
6000
diff
changeset
|
825 ngx_log_memory_buf_t *mem; |
8e66a83d16ae
Core: added cyclic memory buffer support for error_log.
Valentin Bartenev <vbart@nginx.com>
parents:
6000
diff
changeset
|
826 |
8e66a83d16ae
Core: added cyclic memory buffer support for error_log.
Valentin Bartenev <vbart@nginx.com>
parents:
6000
diff
changeset
|
827 mem = log->wdata; |
8e66a83d16ae
Core: added cyclic memory buffer support for error_log.
Valentin Bartenev <vbart@nginx.com>
parents:
6000
diff
changeset
|
828 |
8e66a83d16ae
Core: added cyclic memory buffer support for error_log.
Valentin Bartenev <vbart@nginx.com>
parents:
6000
diff
changeset
|
829 if (mem == NULL) { |
8e66a83d16ae
Core: added cyclic memory buffer support for error_log.
Valentin Bartenev <vbart@nginx.com>
parents:
6000
diff
changeset
|
830 return; |
8e66a83d16ae
Core: added cyclic memory buffer support for error_log.
Valentin Bartenev <vbart@nginx.com>
parents:
6000
diff
changeset
|
831 } |
8e66a83d16ae
Core: added cyclic memory buffer support for error_log.
Valentin Bartenev <vbart@nginx.com>
parents:
6000
diff
changeset
|
832 |
8e66a83d16ae
Core: added cyclic memory buffer support for error_log.
Valentin Bartenev <vbart@nginx.com>
parents:
6000
diff
changeset
|
833 written = ngx_atomic_fetch_add(&mem->written, len); |
8e66a83d16ae
Core: added cyclic memory buffer support for error_log.
Valentin Bartenev <vbart@nginx.com>
parents:
6000
diff
changeset
|
834 |
8e66a83d16ae
Core: added cyclic memory buffer support for error_log.
Valentin Bartenev <vbart@nginx.com>
parents:
6000
diff
changeset
|
835 p = mem->pos + written % (mem->end - mem->pos); |
8e66a83d16ae
Core: added cyclic memory buffer support for error_log.
Valentin Bartenev <vbart@nginx.com>
parents:
6000
diff
changeset
|
836 |
8e66a83d16ae
Core: added cyclic memory buffer support for error_log.
Valentin Bartenev <vbart@nginx.com>
parents:
6000
diff
changeset
|
837 avail = mem->end - p; |
8e66a83d16ae
Core: added cyclic memory buffer support for error_log.
Valentin Bartenev <vbart@nginx.com>
parents:
6000
diff
changeset
|
838 |
8e66a83d16ae
Core: added cyclic memory buffer support for error_log.
Valentin Bartenev <vbart@nginx.com>
parents:
6000
diff
changeset
|
839 if (avail >= len) { |
8e66a83d16ae
Core: added cyclic memory buffer support for error_log.
Valentin Bartenev <vbart@nginx.com>
parents:
6000
diff
changeset
|
840 ngx_memcpy(p, buf, len); |
8e66a83d16ae
Core: added cyclic memory buffer support for error_log.
Valentin Bartenev <vbart@nginx.com>
parents:
6000
diff
changeset
|
841 |
8e66a83d16ae
Core: added cyclic memory buffer support for error_log.
Valentin Bartenev <vbart@nginx.com>
parents:
6000
diff
changeset
|
842 } else { |
8e66a83d16ae
Core: added cyclic memory buffer support for error_log.
Valentin Bartenev <vbart@nginx.com>
parents:
6000
diff
changeset
|
843 ngx_memcpy(p, buf, avail); |
8e66a83d16ae
Core: added cyclic memory buffer support for error_log.
Valentin Bartenev <vbart@nginx.com>
parents:
6000
diff
changeset
|
844 ngx_memcpy(mem->pos, buf + avail, len - avail); |
8e66a83d16ae
Core: added cyclic memory buffer support for error_log.
Valentin Bartenev <vbart@nginx.com>
parents:
6000
diff
changeset
|
845 } |
8e66a83d16ae
Core: added cyclic memory buffer support for error_log.
Valentin Bartenev <vbart@nginx.com>
parents:
6000
diff
changeset
|
846 } |
8e66a83d16ae
Core: added cyclic memory buffer support for error_log.
Valentin Bartenev <vbart@nginx.com>
parents:
6000
diff
changeset
|
847 |
8e66a83d16ae
Core: added cyclic memory buffer support for error_log.
Valentin Bartenev <vbart@nginx.com>
parents:
6000
diff
changeset
|
848 |
8e66a83d16ae
Core: added cyclic memory buffer support for error_log.
Valentin Bartenev <vbart@nginx.com>
parents:
6000
diff
changeset
|
849 static void |
8e66a83d16ae
Core: added cyclic memory buffer support for error_log.
Valentin Bartenev <vbart@nginx.com>
parents:
6000
diff
changeset
|
850 ngx_log_memory_cleanup(void *data) |
8e66a83d16ae
Core: added cyclic memory buffer support for error_log.
Valentin Bartenev <vbart@nginx.com>
parents:
6000
diff
changeset
|
851 { |
8e66a83d16ae
Core: added cyclic memory buffer support for error_log.
Valentin Bartenev <vbart@nginx.com>
parents:
6000
diff
changeset
|
852 ngx_log_t *log = data; |
8e66a83d16ae
Core: added cyclic memory buffer support for error_log.
Valentin Bartenev <vbart@nginx.com>
parents:
6000
diff
changeset
|
853 |
8e66a83d16ae
Core: added cyclic memory buffer support for error_log.
Valentin Bartenev <vbart@nginx.com>
parents:
6000
diff
changeset
|
854 ngx_log_debug0(NGX_LOG_DEBUG_CORE, log, 0, "destroy memory log buffer"); |
8e66a83d16ae
Core: added cyclic memory buffer support for error_log.
Valentin Bartenev <vbart@nginx.com>
parents:
6000
diff
changeset
|
855 |
8e66a83d16ae
Core: added cyclic memory buffer support for error_log.
Valentin Bartenev <vbart@nginx.com>
parents:
6000
diff
changeset
|
856 log->wdata = NULL; |
8e66a83d16ae
Core: added cyclic memory buffer support for error_log.
Valentin Bartenev <vbart@nginx.com>
parents:
6000
diff
changeset
|
857 } |
8e66a83d16ae
Core: added cyclic memory buffer support for error_log.
Valentin Bartenev <vbart@nginx.com>
parents:
6000
diff
changeset
|
858 |
8e66a83d16ae
Core: added cyclic memory buffer support for error_log.
Valentin Bartenev <vbart@nginx.com>
parents:
6000
diff
changeset
|
859 #endif |