changeset 9224:c7c8354f99fa

Syslog: fixed duplicate errors with access logging to syslog. The ngx_syslog_send() function logs errors itself, so there is no need to additionally log errors in the caller, notably access log modules in http and stream. To ensure that incomplete and blocked writes are also logged, appropriate logging added to ngx_syslog_send().
author Maxim Dounin <mdounin@mdounin.ru>
date Fri, 01 Mar 2024 05:42:09 +0300
parents 697f452bc033
children 1c9264603adc
files src/core/ngx_syslog.c src/http/modules/ngx_http_log_module.c src/stream/ngx_stream_log_module.c
diffstat 3 files changed, 8 insertions(+), 30 deletions(-) [+]
line wrap: on
line diff
--- a/src/core/ngx_syslog.c
+++ b/src/core/ngx_syslog.c
@@ -319,6 +319,10 @@ ngx_syslog_send(ngx_syslog_peer_t *peer,
         }
 
         peer->conn.fd = (ngx_socket_t) -1;
+
+    } else if ((size_t) n != len) {
+        ngx_log_error(NGX_LOG_CRIT, &peer->log, 0,
+                      "send() incomplete");
     }
 
     return n;
--- a/src/http/modules/ngx_http_log_module.c
+++ b/src/http/modules/ngx_http_log_module.c
@@ -254,8 +254,7 @@ static ngx_int_t
 ngx_http_log_handler(ngx_http_request_t *r)
 {
     u_char                   *line, *p;
-    size_t                    len, size;
-    ssize_t                   n;
+    size_t                    len;
     ngx_str_t                 val;
     ngx_uint_t                i, l;
     ngx_http_log_t           *log;
@@ -376,19 +375,7 @@ ngx_http_log_handler(ngx_http_request_t 
 
         if (log[l].syslog_peer) {
 
-            size = p - line;
-
-            n = ngx_syslog_send(log[l].syslog_peer, line, size);
-
-            if (n < 0) {
-                ngx_log_error(NGX_LOG_WARN, r->connection->log, 0,
-                              "send() to syslog failed");
-
-            } else if ((size_t) n != size) {
-                ngx_log_error(NGX_LOG_WARN, r->connection->log, 0,
-                              "send() to syslog has written only %z of %uz",
-                              n, size);
-            }
+            (void) ngx_syslog_send(log[l].syslog_peer, line, p - line);
 
             continue;
         }
--- a/src/stream/ngx_stream_log_module.c
+++ b/src/stream/ngx_stream_log_module.c
@@ -201,8 +201,7 @@ static ngx_int_t
 ngx_stream_log_handler(ngx_stream_session_t *s)
 {
     u_char                     *line, *p;
-    size_t                      len, size;
-    ssize_t                     n;
+    size_t                      len;
     ngx_str_t                   val;
     ngx_uint_t                  i, l;
     ngx_stream_log_t           *log;
@@ -324,19 +323,7 @@ ngx_stream_log_handler(ngx_stream_sessio
 
         if (log[l].syslog_peer) {
 
-            size = p - line;
-
-            n = ngx_syslog_send(log[l].syslog_peer, line, size);
-
-            if (n < 0) {
-                ngx_log_error(NGX_LOG_WARN, s->connection->log, 0,
-                              "send() to syslog failed");
-
-            } else if ((size_t) n != size) {
-                ngx_log_error(NGX_LOG_WARN, s->connection->log, 0,
-                              "send() to syslog has written only %z of %uz",
-                              n, size);
-            }
+            (void) ngx_syslog_send(log[l].syslog_peer, line, p - line);
 
             continue;
         }