关于 error_log 指令的解析
---- nginx-1.0.9 ---
error_log 配置:
error_log logs/xxx.log error | debug_core | debug_alloc
-----------
总结
语法:
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 指令的日志级别配置分为 错误日志级别和调试日志级别
且 错误日志只能设置一个级别 且 错误日志必须书写在调试日志级别的前面 且 调试日志可以设置多个级别
其他配置方法可能达不到你的预期.
---- 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 指令的日志级别配置分为 错误日志级别和调试日志级别
且 错误日志只能设置一个级别 且 错误日志必须书写在调试日志级别的前面 且 调试日志可以设置多个级别
其他配置方法可能达不到你的预期.