[patch] Logging: raise severity level for logged messages

Sergei Turchanov turchanov at farpost.com
Mon Dec 30 01:35:06 UTC 2013


# HG changeset patch
# User Sergei Turchanov <turchanov at farpost.com>
# Date 1388366954 -39600
# Node ID 309f46326753b70222ed86d0c09cb1f702aeffda
# Parent  2cfc095a607a2e6205e45ee0be062f57a8d7ac88
Logging: raise severity level for logged messages

Nginx is inconsistent in respect to severity level used for messages that
are logged for user/server errors resulting in 4xx/5xx response codes.
There are some places where INFO level is used which makes hard to debug
user problems because setting logging level of 'error_log' to 'info' 
produces
too much of an output whereas with this patch setting level to 'warn' gives
more relevant messages.

diff -r 2cfc095a607a -r 309f46326753 src/http/ngx_http_request.c
--- a/src/http/ngx_http_request.c	Fri Dec 27 19:40:04 2013 +0400
+++ b/src/http/ngx_http_request.c	Mon Dec 30 12:29:14 2013 +1100
@@ -918,7 +918,7 @@
                  rc = ngx_http_validate_host(&host, r->pool, 0);

                  if (rc == NGX_DECLINED) {
-                    ngx_log_error(NGX_LOG_INFO, c->log, 0,
+                    ngx_log_error(NGX_LOG_ERR, c->log, 0,
                                    "client sent invalid host in request 
line");
                      ngx_http_finalize_request(r, NGX_HTTP_BAD_REQUEST);
                      return;
@@ -970,7 +970,7 @@

              /* there was error while a request line parsing */

-            ngx_log_error(NGX_LOG_INFO, c->log, 0,
+            ngx_log_error(NGX_LOG_ERR, c->log, 0,
                            ngx_http_client_errors[rc - 
NGX_HTTP_CLIENT_ERROR]);
              ngx_http_finalize_request(r, NGX_HTTP_BAD_REQUEST);
              return;
@@ -991,7 +991,7 @@
                  r->request_line.len = r->header_in->end - 
r->request_start;
                  r->request_line.data = r->request_start;

-                ngx_log_error(NGX_LOG_INFO, c->log, 0,
+                ngx_log_error(NGX_LOG_ERR, c->log, 0,
                                "client sent too long URI");
                  ngx_http_finalize_request(r, 
NGX_HTTP_REQUEST_URI_TOO_LARGE);
                  return;
@@ -1023,7 +1023,7 @@
          cscf = ngx_http_get_module_srv_conf(r, ngx_http_core_module);

          if (ngx_http_parse_complex_uri(r, cscf->merge_slashes) != 
NGX_OK) {
-            ngx_log_error(NGX_LOG_INFO, r->connection->log, 0,
+            ngx_log_error(NGX_LOG_ERR, r->connection->log, 0,
                            "client sent invalid request");
              ngx_http_finalize_request(r, NGX_HTTP_BAD_REQUEST);
              return NGX_ERROR;
@@ -1070,7 +1070,7 @@
               */

              if (p < last && *p == '$') {
-                ngx_log_error(NGX_LOG_INFO, r->connection->log, 0,
+                ngx_log_error(NGX_LOG_ERR, r->connection->log, 0,
                                "client sent unsafe win32 URI");
                  ngx_http_finalize_request(r, NGX_HTTP_BAD_REQUEST);
                  return NGX_ERROR;
@@ -1166,7 +1166,7 @@
                      r->lingering_close = 1;

                      if (p == NULL) {
-                        ngx_log_error(NGX_LOG_INFO, c->log, 0,
+                        ngx_log_error(NGX_LOG_ERR, c->log, 0,
                                        "client sent too large request");
                          ngx_http_finalize_request(r,
 
NGX_HTTP_REQUEST_HEADER_TOO_LARGE);
@@ -1180,7 +1180,7 @@
                          p[len++] = '.'; p[len++] = '.'; p[len++] = '.';
                      }

-                    ngx_log_error(NGX_LOG_INFO, c->log, 0,
+                    ngx_log_error(NGX_LOG_ERR, c->log, 0,
                                    "client sent too long header line: 
\"%*s\"",
                                    len, r->header_name_start);

@@ -1211,7 +1211,7 @@

                  /* there was error while a header line parsing */

-                ngx_log_error(NGX_LOG_INFO, c->log, 0,
+                ngx_log_error(NGX_LOG_WARN, c->log, 0,
                                "client sent invalid header line: \"%*s\"",
                                r->header_end - r->header_name_start,
                                r->header_name_start);
@@ -1534,7 +1534,7 @@
          return NGX_OK;
      }

-    ngx_log_error(NGX_LOG_INFO, r->connection->log, 0,
+    ngx_log_error(NGX_LOG_ERR, r->connection->log, 0,
                    "client sent duplicate header line: \"%V: %V\", "
                    "previous value: \"%V: %V\"",
                    &h->key, &h->value, &(*ph)->key, &(*ph)->value);
@@ -1561,7 +1561,7 @@
      rc = ngx_http_validate_host(&host, r->pool, 0);

      if (rc == NGX_DECLINED) {
-        ngx_log_error(NGX_LOG_INFO, r->connection->log, 0,
+        ngx_log_error(NGX_LOG_ERR, r->connection->log, 0,
                        "client sent invalid host header");
          ngx_http_finalize_request(r, NGX_HTTP_BAD_REQUEST);
          return NGX_ERROR;
@@ -1714,7 +1714,7 @@
      }

      if (r->headers_in.host == NULL && r->http_version > 
NGX_HTTP_VERSION_10) {
-        ngx_log_error(NGX_LOG_INFO, r->connection->log, 0,
+        ngx_log_error(NGX_LOG_ERR, r->connection->log, 0,
                     "client sent HTTP/1.1 request without \"Host\" 
header");
          ngx_http_finalize_request(r, NGX_HTTP_BAD_REQUEST);
          return NGX_ERROR;
@@ -1726,7 +1726,7 @@
 
r->headers_in.content_length->value.len);
          if (r->headers_in.content_length_n == NGX_ERROR) {
-            ngx_log_error(NGX_LOG_INFO, r->connection->log, 0,
+            ngx_log_error(NGX_LOG_ERR, r->connection->log, 0,
                            "client sent invalid \"Content-Length\" 
header");
              ngx_http_finalize_request(r, NGX_HTTP_BAD_REQUEST);
              return NGX_ERROR;
@@ -1734,7 +1734,7 @@
      }

      if (r->method & NGX_HTTP_TRACE) {
-        ngx_log_error(NGX_LOG_INFO, r->connection->log, 0,
+        ngx_log_error(NGX_LOG_ERR, r->connection->log, 0,
                        "client sent TRACE method");
          ngx_http_finalize_request(r, NGX_HTTP_NOT_ALLOWED);
          return NGX_ERROR;
@@ -1753,7 +1753,7 @@
              || 
ngx_strncasecmp(r->headers_in.transfer_encoding->value.data,
                                 (u_char *) "identity", 8) != 0)
          {
-            ngx_log_error(NGX_LOG_INFO, r->connection->log, 0,
+            ngx_log_error(NGX_LOG_ERR, r->connection->log, 0,
                            "client sent unknown \"Transfer-Encoding\": 
\"%V\"",
                            &r->headers_in.transfer_encoding->value);
              ngx_http_finalize_request(r, NGX_HTTP_NOT_IMPLEMENTED);
@@ -1788,7 +1788,7 @@
          ngx_http_ssl_srv_conf_t  *sscf;

          if (c->ssl == NULL) {
-            ngx_log_error(NGX_LOG_INFO, c->log, 0,
+            ngx_log_error(NGX_LOG_ERR, c->log, 0,
                            "client sent plain HTTP request to HTTPS port");
              ngx_http_finalize_request(r, NGX_HTTP_TO_HTTPS);
              return;
@@ -1802,7 +1802,7 @@
              if (rc != X509_V_OK
                  && (sscf->verify != 3 || 
!ngx_ssl_verify_error_optional(rc)))
              {
-                ngx_log_error(NGX_LOG_INFO, c->log, 0,
+                ngx_log_error(NGX_LOG_ERR, c->log, 0,
                                "client SSL certificate verify error: 
(%l:%s)",
                                rc, X509_verify_cert_error_string(rc));

@@ -1817,7 +1817,7 @@
                  cert = SSL_get_peer_certificate(c->ssl->connection);

                  if (cert == NULL) {
-                    ngx_log_error(NGX_LOG_INFO, c->log, 0,
+                    ngx_log_error(NGX_LOG_ERR, c->log, 0,
                                    "client sent no required SSL 
certificate");

                      ngx_ssl_remove_cached_session(sscf->ssl.ctx,
@@ -2000,7 +2000,7 @@
          sscf = ngx_http_get_module_srv_conf(cscf->ctx, 
ngx_http_ssl_module);

          if (sscf->verify) {
-            ngx_log_error(NGX_LOG_INFO, r->connection->log, 0,
+            ngx_log_error(NGX_LOG_ERR, r->connection->log, 0,
                            "client attempted to request the server name "
                            "different from that one was negotiated");
              ngx_http_finalize_request(r, NGX_HTTP_BAD_REQUEST);



More information about the nginx-devel mailing list