關於 error_log 指令的解析
---- nginx-1.0.9 ---
error_log 配置:
error_log logs/xxx.log error | debug_core | debug_alloc
main(){ //... prefix = ./configure --prefix ngx_init_cycle(ngx_cycle_t *old_cycle) { log.log_level = NGX_LOG_NOTICE; log = ngx_log_init() = $prefix + NGX_ERROR_LOG_PATH = $prefix/logs/error.log; ngx_conf_param(ngx_conf_t *cf) { ngx_error_log() { cycle->new_log = $conf_prefix/logs/xxx.log 或者 $prefix/logs/xxx.log; ngx_log_set_levels() { value = cf->args->elts; /* 從這段代碼上看: error_log 指令的記錄層級配置分為 錯誤記錄檔層級和調試記錄層級 且 錯誤記錄檔只能設定一個層級 且 錯誤記錄檔必須書寫在調試記錄層級的前面 且 調試日誌可以設定多個層級 其他配置方法可能達不到你的預期. */ for (i = 2; i < cf->args->nelts; i++) { found = 0; for (n = 1; n <= NGX_LOG_DEBUG; n++) { if (ngx_strcmp(value[i].data, err_levels[n].data) == 0) { /* 這裡匹配的是 錯誤記錄檔層級 */ log->log_level = n; found = 1; break; } } for (n = 0, d = NGX_LOG_DEBUG_FIRST; d <= NGX_LOG_DEBUG_LAST; d <<= 1) { /* 這裡匹配的是 調試記錄層級 */ if (ngx_strcmp(value[i].data, debug_levels[n++]) == 0) { log->log_level |= d; found = 1; break; } } } if (log->log_level == NGX_LOG_DEBUG) { log->log_level = NGX_LOG_DEBUG_ALL; } return NGX_CONF_OK; } } } cycle->log = &cycle->new_log; pool->log = &cycle->new_log; } //...}
-----------
總結
文法:
error_log file [ debug | info | notice | warn | error | crit ] | [{ debug_core | debug_alloc | debug_mutex | debug_event | debug_http | debug_mail | debug_mysql } ]
記錄層級 = 錯誤記錄檔層級 | 調試記錄層級; 或者
記錄層級 = 錯誤記錄檔層級;
錯誤記錄檔的層級: emerg, alert, crit, error, warn, notic, info, debug,
調試日誌的層級: debug_core, debug_alloc, debug_mutex, debug_event, debug_http, debug_mail, debug_mysql,
error_log 指令的記錄層級配置分為 錯誤記錄檔層級和調試記錄層級
且 錯誤記錄檔只能設定一個層級 且 錯誤記錄檔必須書寫在調試記錄層級的前面 且 調試日誌可以設定多個層級
其他配置方法可能達不到你的預期.