comparison src/core/ngx_log.c @ 2741:cda3738a85bd

use ngx_str_t for error levels
author Igor Sysoev <igor@sysoev.ru>
date Thu, 23 Apr 2009 08:05:54 +0000
parents d52cf82d0d77
children e138f820b5dc
comparison
equal deleted inserted replaced
2740:e5a4be07c3eb 2741:cda3738a85bd
49 49
50 static ngx_log_t ngx_log; 50 static ngx_log_t ngx_log;
51 static ngx_open_file_t ngx_stderr; 51 static ngx_open_file_t ngx_stderr;
52 52
53 53
54 static const char *err_levels[] = { 54 static ngx_str_t err_levels[] = {
55 "stderr", "emerg", "alert", "crit", "error", 55 ngx_string("stderr"),
56 "warn", "notice", "info", "debug" 56 ngx_string("emerg"),
57 ngx_string("alert"),
58 ngx_string("crit"),
59 ngx_string("error"),
60 ngx_string("warn"),
61 ngx_string("notice"),
62 ngx_string("info"),
63 ngx_string("debug")
57 }; 64 };
58 65
59 static const char *debug_levels[] = { 66 static const char *debug_levels[] = {
60 "debug_core", "debug_alloc", "debug_mutex", "debug_event", 67 "debug_core", "debug_alloc", "debug_mutex", "debug_event",
61 "debug_http", "debug_mail", "debug_mysql" 68 "debug_http", "debug_mail", "debug_mysql"
90 ngx_memcpy(errstr, ngx_cached_err_log_time.data, 97 ngx_memcpy(errstr, ngx_cached_err_log_time.data,
91 ngx_cached_err_log_time.len); 98 ngx_cached_err_log_time.len);
92 99
93 p = errstr + ngx_cached_err_log_time.len; 100 p = errstr + ngx_cached_err_log_time.len;
94 101
95 p = ngx_snprintf(p, last - p, " [%s] ", err_levels[level]); 102 p = ngx_snprintf(p, last - p, " [%V] ", &err_levels[level]);
96 103
97 /* pid#tid */ 104 /* pid#tid */
98 p = ngx_snprintf(p, last - p, "%P#" NGX_TID_T_FMT ": ", 105 p = ngx_snprintf(p, last - p, "%P#" NGX_TID_T_FMT ": ",
99 ngx_log_pid, ngx_log_tid); 106 ngx_log_pid, ngx_log_tid);
100 107
286 value = cf->args->elts; 293 value = cf->args->elts;
287 294
288 for (i = 2; i < cf->args->nelts; i++) { 295 for (i = 2; i < cf->args->nelts; i++) {
289 296
290 for (n = 1; n <= NGX_LOG_DEBUG; n++) { 297 for (n = 1; n <= NGX_LOG_DEBUG; n++) {
291 if (ngx_strcmp(value[i].data, err_levels[n]) == 0) { 298 if (ngx_strcmp(value[i].data, err_levels[n].data) == 0) {
292 299
293 if (log->log_level != 0) { 300 if (log->log_level != 0) {
294 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, 301 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
295 "duplicate log level \"%s\"", 302 "duplicate log level \"%V\"",
296 value[i].data); 303 &value[i]);
297 return NGX_CONF_ERROR; 304 return NGX_CONF_ERROR;
298 } 305 }
299 306
300 log->log_level = n; 307 log->log_level = n;
301 continue; 308 continue;
304 311
305 for (n = 0, d = NGX_LOG_DEBUG_FIRST; d <= NGX_LOG_DEBUG_LAST; d <<= 1) { 312 for (n = 0, d = NGX_LOG_DEBUG_FIRST; d <= NGX_LOG_DEBUG_LAST; d <<= 1) {
306 if (ngx_strcmp(value[i].data, debug_levels[n++]) == 0) { 313 if (ngx_strcmp(value[i].data, debug_levels[n++]) == 0) {
307 if (log->log_level & ~NGX_LOG_DEBUG_ALL) { 314 if (log->log_level & ~NGX_LOG_DEBUG_ALL) {
308 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, 315 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
309 "invalid log level \"%s\"", 316 "invalid log level \"%V\"",
310 value[i].data); 317 &value[i]);
311 return NGX_CONF_ERROR; 318 return NGX_CONF_ERROR;
312 } 319 }
313 320
314 log->log_level |= d; 321 log->log_level |= d;
315 } 322 }
316 } 323 }
317 324
318 325
319 if (log->log_level == 0) { 326 if (log->log_level == 0) {
320 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, 327 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
321 "invalid log level \"%s\"", value[i].data); 328 "invalid log level \"%V\"", &value[i]);
322 return NGX_CONF_ERROR; 329 return NGX_CONF_ERROR;
323 } 330 }
324 } 331 }
325 332
326 if (log->log_level == 0) { 333 if (log->log_level == 0) {