Mercurial > hg > nginx
comparison src/core/ngx_log.c @ 92:19cc647ecd91
nginx-0.0.1-2003-05-20-19:37:55 import
author | Igor Sysoev <igor@sysoev.ru> |
---|---|
date | Tue, 20 May 2003 15:37:55 +0000 |
parents | a7e45c45a95c |
children | 738fe44c70d5 |
comparison
equal
deleted
inserted
replaced
91:637625a2acdb | 92:19cc647ecd91 |
---|---|
9 "[time as ctime()] [alert] (32)Broken pipe: anything" | 9 "[time as ctime()] [alert] (32)Broken pipe: anything" |
10 "[time as ctime()] [alert] anything" | 10 "[time as ctime()] [alert] anything" |
11 */ | 11 */ |
12 | 12 |
13 #include <ngx_config.h> | 13 #include <ngx_config.h> |
14 #include <ngx_errno.h> | 14 #include <ngx_core.h> |
15 #include <ngx_time.h> | |
16 #include <ngx_process.h> | |
17 #include <ngx_string.h> | |
18 #include <ngx_log.h> | |
19 | 15 |
20 | 16 |
21 static const char *err_levels[] = { | 17 static const char *err_levels[] = { |
22 "emerg", "alert", "crit", "error", "warn", "notice", "info", "debug" | 18 "stderr", "emerg", "alert", "crit", "error", |
19 "warn", "notice", "info", "debug" | |
23 }; | 20 }; |
24 | 21 |
25 #if (HAVE_VARIADIC_MACROS) | 22 #if (HAVE_VARIADIC_MACROS) |
26 void ngx_log_error_core(int level, ngx_log_t *log, ngx_err_t err, | 23 void ngx_log_error_core(int level, ngx_log_t *log, ngx_err_t err, |
27 const char *fmt, ...) | 24 const char *fmt, ...) |
28 #else | 25 #else |
29 void ngx_log_error_core(int level, ngx_log_t *log, ngx_err_t err, | 26 void ngx_log_error_core(int level, ngx_log_t *log, ngx_err_t err, |
30 const char *fmt, va_list args) | 27 const char *fmt, va_list args) |
31 #endif | 28 #endif |
32 { | 29 { |
33 char errstr[MAX_ERROR_STR]; | 30 char errstr[MAX_ERROR_STR]; |
34 ngx_tm_t tm; | 31 ngx_tm_t tm; |
35 size_t len; | 32 size_t len; |
36 #if (HAVE_VARIADIC_MACROS) | 33 #if (HAVE_VARIADIC_MACROS) |
37 va_list args; | 34 va_list args; |
38 #endif | 35 #endif |
39 | 36 |
40 ngx_localtime(&tm); | 37 ngx_localtime(&tm); |
41 len = ngx_snprintf(errstr, sizeof(errstr), "%4d/%02d/%02d %02d:%02d:%02d", | 38 len = ngx_snprintf(errstr, sizeof(errstr), "%4d/%02d/%02d %02d:%02d:%02d", |
42 tm.ngx_tm_year, tm.ngx_tm_mon, tm.ngx_tm_mday, | 39 tm.ngx_tm_year, tm.ngx_tm_mon, tm.ngx_tm_mday, |
91 #if (WIN32) | 88 #if (WIN32) |
92 errstr[len++] = '\r'; | 89 errstr[len++] = '\r'; |
93 #endif | 90 #endif |
94 errstr[len++] = '\n'; | 91 errstr[len++] = '\n'; |
95 | 92 |
96 write(2, errstr, len); | 93 write(log->fd, errstr, len); |
97 | 94 |
98 #if 0 | 95 #if 0 |
99 errstr[len] = '\0'; | 96 errstr[len] = '\0'; |
100 fputs(errstr, stderr); | 97 fputs(errstr, stderr); |
101 fflush(stderr); | 98 fflush(stderr); |
102 #endif | 99 #endif |
103 } | 100 } |
101 | |
104 | 102 |
105 #if !(HAVE_VARIADIC_MACROS) | 103 #if !(HAVE_VARIADIC_MACROS) |
106 | 104 |
107 void ngx_log_error(int level, ngx_log_t *log, ngx_err_t err, | 105 void ngx_log_error(int level, ngx_log_t *log, ngx_err_t err, |
108 const char *fmt, ...) | 106 const char *fmt, ...) |
114 ngx_log_error_core(level, log, err, fmt, args); | 112 ngx_log_error_core(level, log, err, fmt, args); |
115 va_end(args); | 113 va_end(args); |
116 } | 114 } |
117 } | 115 } |
118 | 116 |
117 | |
119 void ngx_log_debug_core(ngx_log_t *log, const char *fmt, ...) | 118 void ngx_log_debug_core(ngx_log_t *log, const char *fmt, ...) |
120 { | 119 { |
121 va_list args; | 120 va_list args; |
122 | 121 |
123 va_start(args, fmt); | 122 va_start(args, fmt); |
124 ngx_log_error_core(NGX_LOG_DEBUG, log, 0, fmt, args); | 123 ngx_log_error_core(NGX_LOG_DEBUG, log, 0, fmt, args); |
125 va_end(args); | 124 va_end(args); |
126 } | 125 } |
126 | |
127 | 127 |
128 void ngx_assert_core(ngx_log_t *log, const char *fmt, ...) | 128 void ngx_assert_core(ngx_log_t *log, const char *fmt, ...) |
129 { | 129 { |
130 va_list args; | 130 va_list args; |
131 | 131 |
133 ngx_log_error_core(NGX_LOG_ALERT, log, 0, fmt, args); | 133 ngx_log_error_core(NGX_LOG_ALERT, log, 0, fmt, args); |
134 va_end(args); | 134 va_end(args); |
135 } | 135 } |
136 | 136 |
137 #endif | 137 #endif |
138 | |
139 | |
140 void ngx_log_stderr(ngx_event_t *ev) | |
141 { | |
142 char errstr[MAX_ERROR_STR]; | |
143 ssize_t n; | |
144 ngx_err_t err; | |
145 | |
146 for ( ;; ) { | |
147 n = read((ngx_fd_t) ev->data, errstr, sizeof(errstr - 1)); | |
148 | |
149 if (n == -1) { | |
150 err = ngx_errno; | |
151 if (err == NGX_EAGAIN) { | |
152 return; | |
153 } | |
154 | |
155 ngx_log_error(NGX_LOG_ALERT, &ngx_log, err, "read() failed"); | |
156 return; | |
157 } | |
158 | |
159 if (n == 0) { | |
160 ngx_log_error(NGX_LOG_ALERT, &ngx_log, 0, "stderr clolsed"); | |
161 return; | |
162 } | |
163 | |
164 errstr[n] = '\0'; | |
165 ngx_log_error(NGX_LOG_STDERR, &ngx_log, 0, "%s", errstr); | |
166 } | |
167 } |