[PATCH 1 of 5] Syslog: fixed duplicate errors with access logging to syslog
Maxim Dounin
mdounin at mdounin.ru
Fri Mar 1 03:18:17 UTC 2024
# HG changeset patch
# User Maxim Dounin <mdounin at mdounin.ru>
# Date 1709260929 -10800
# Fri Mar 01 05:42:09 2024 +0300
# Node ID c7c8354f99face52f3b51442360317f3e2768492
# Parent 697f452bc03301a8fe22d8bcae6f3bc06f4efe6f
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().
diff --git a/src/core/ngx_syslog.c b/src/core/ngx_syslog.c
--- 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;
diff --git a/src/http/modules/ngx_http_log_module.c b/src/http/modules/ngx_http_log_module.c
--- 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;
}
diff --git a/src/stream/ngx_stream_log_module.c b/src/stream/ngx_stream_log_module.c
--- 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;
}
More information about the nginx-devel
mailing list