Mercurial > hg > nginx
comparison src/core/ngx_log.c @ 9298:14770557be17
Core: simplified log levels matching.
author | Maxim Dounin <mdounin@mdounin.ru> |
---|---|
date | Tue, 25 Jun 2024 22:58:36 +0300 |
parents | e1f15d47d102 |
children | 2706b60dc225 |
comparison
equal
deleted
inserted
replaced
9297:e1f15d47d102 | 9298:14770557be17 |
---|---|
611 | 611 |
612 | 612 |
613 static char * | 613 static char * |
614 ngx_log_set_levels(ngx_conf_t *cf, ngx_log_t *log) | 614 ngx_log_set_levels(ngx_conf_t *cf, ngx_log_t *log) |
615 { | 615 { |
616 ngx_uint_t i, n, d, found; | 616 ngx_uint_t i, n, d; |
617 ngx_str_t *value; | 617 ngx_str_t *value; |
618 | 618 |
619 if (cf->args->nelts == 2) { | |
620 log->log_level = NGX_LOG_ERR; | |
621 return NGX_CONF_OK; | |
622 } | |
623 | |
624 value = cf->args->elts; | 619 value = cf->args->elts; |
625 | 620 |
626 for (i = 2; i < cf->args->nelts; i++) { | 621 for (i = 2; i < cf->args->nelts; i++) { |
627 found = 0; | |
628 | 622 |
629 for (n = 1; n <= NGX_LOG_DEBUG; n++) { | 623 for (n = 1; n <= NGX_LOG_DEBUG; n++) { |
630 if (ngx_strcmp(value[i].data, err_levels[n].data) == 0) { | 624 if (ngx_strcmp(value[i].data, err_levels[n].data) == 0) { |
631 | 625 |
632 if (log->log_level != 0) { | 626 if (log->log_level != 0) { |
635 &value[i]); | 629 &value[i]); |
636 return NGX_CONF_ERROR; | 630 return NGX_CONF_ERROR; |
637 } | 631 } |
638 | 632 |
639 log->log_level = n; | 633 log->log_level = n; |
640 found = 1; | 634 goto next; |
641 break; | |
642 } | 635 } |
643 } | 636 } |
644 | 637 |
645 for (n = 0, d = NGX_LOG_DEBUG_FIRST; d <= NGX_LOG_DEBUG_LAST; d <<= 1) { | 638 for (n = 0, d = NGX_LOG_DEBUG_FIRST; d <= NGX_LOG_DEBUG_LAST; d <<= 1) { |
646 if (ngx_strcmp(value[i].data, debug_levels[n++]) == 0) { | 639 if (ngx_strcmp(value[i].data, debug_levels[n++]) == 0) { |
650 &value[i]); | 643 &value[i]); |
651 return NGX_CONF_ERROR; | 644 return NGX_CONF_ERROR; |
652 } | 645 } |
653 | 646 |
654 log->log_level |= d; | 647 log->log_level |= d; |
655 found = 1; | 648 goto next; |
656 break; | |
657 } | 649 } |
658 } | 650 } |
659 | 651 |
660 | 652 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, |
661 if (!found) { | 653 "invalid log level \"%V\"", &value[i]); |
662 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, | 654 return NGX_CONF_ERROR; |
663 "invalid log level \"%V\"", &value[i]); | 655 |
664 return NGX_CONF_ERROR; | 656 next: |
665 } | 657 |
658 continue; | |
659 } | |
660 | |
661 if (log->log_level == 0) { | |
662 log->log_level = NGX_LOG_ERR; | |
666 } | 663 } |
667 | 664 |
668 if (log->log_level == NGX_LOG_DEBUG) { | 665 if (log->log_level == NGX_LOG_DEBUG) { |
669 log->log_level = NGX_LOG_DEBUG_ALL; | 666 log->log_level = NGX_LOG_DEBUG_ALL; |
670 } | 667 } |