]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
BUG/MEDIUM: local log format regression.
authorEmeric Brun <ebrun@haproxy.com>
Fri, 27 Nov 2020 15:24:34 +0000 (16:24 +0100)
committerWilly Tarreau <w@1wt.eu>
Tue, 1 Dec 2020 05:58:42 +0000 (06:58 +0100)
Since 2.3 default local log format always adds hostame field.
This behavior change was due to log/sink re-work, because according
to rfc3164 the hostname field is mandatory.

This patch re-introduce a legacy "local" format which is analog
to rfc3164 but with hostname stripped. This is the new
default if logs are generated by haproxy.

To stay compliant with previous configurations, the option
"log-send-hostname" acts as if the default format is switched
to rfc3164.

This patch addresses the github issue #963

This patch should be backported in branches >= 2.3.

doc/configuration.txt
include/haproxy/log-t.h
src/log.c
src/sink.c

index 59964075099afd60085b1860222f55344637ebbc..5eef1ff88b876126f331de03dd8e6a7d8ace8ced 100644 (file)
@@ -1279,7 +1279,12 @@ log <address> [len <length>] [format <format>] [sample <ranges>:<smp_size>]
   <format> is the log format used when generating syslog messages. It may be
            one of the following :
 
-    rfc3164   The RFC3164 syslog message format. This is the default.
+    local     Analog to rfc3164 syslog message format except that hostname
+              field is stripped. This is the default.
+              Note: option "log-send-hostname" switches the default to
+              rfc3164.
+
+    rfc3164   The RFC3164 syslog message format.
               (https://tools.ietf.org/html/rfc3164)
 
     rfc5424   The RFC5424 syslog message format.
@@ -2927,13 +2932,18 @@ format <format>
               The PID, process name and system name are omitted. This is
               designed to be used with a local log server.
 
+      local   Analog to rfc3164 syslog message format except that hostname
+              field is stripped. This is the default.
+              Note: option "log-send-hostname" switches the default to
+              rfc3164.
+
       raw     A message containing only the text. The level, PID, date, time,
               process name and system name are omitted. This is designed to be
               used in containers or during development, where the severity
               only depends on the file descriptor used (stdout/stderr). This
               is the default.
 
-      rfc3164 The RFC3164 syslog message format. This is the default.
+      rfc3164 The RFC3164 syslog message format.
               (https://tools.ietf.org/html/rfc3164)
 
       rfc5424 The RFC5424 syslog message format.
@@ -7175,7 +7185,12 @@ no log
     <format> is the log format used when generating syslog messages. It may be
              one of the following :
 
-      rfc3164   The RFC3164 syslog message format. This is the default.
+      local     Analog to rfc3164 syslog message format except that hostname
+                field is stripped. This is the default.
+                Note: option "log-send-hostname" switches the default to
+                rfc3164.
+
+      rfc3164   The RFC3164 syslog message format.
                 (https://tools.ietf.org/html/rfc3164)
 
       rfc5424   The RFC5424 syslog message format.
index bfaef7d061784b2ae3f95c5271982a00778e6f3c..c8f52f554cf573244cdbb0cc5037000cda16d307 100644 (file)
@@ -74,6 +74,7 @@
 /* enum for log format */
 enum log_fmt {
        LOG_FORMAT_UNSPEC = 0,
+       LOG_FORMAT_LOCAL,
        LOG_FORMAT_RFC3164,
        LOG_FORMAT_RFC5424,
        LOG_FORMAT_PRIO,
index c6ba5e635da186f58dd772ed44bdf8d71ad58eb7..6014bfc2d272ff17d4a263cc1fcb33c4aaa91dbb 100644 (file)
--- a/src/log.c
+++ b/src/log.c
@@ -56,6 +56,9 @@ struct log_fmt_st {
 };
 
 static const struct log_fmt_st log_formats[LOG_FORMATS] = {
+       [LOG_FORMAT_LOCAL] = {
+               .name = "local",
+       },
        [LOG_FORMAT_RFC3164] = {
                .name = "rfc3164",
        },
@@ -1475,6 +1478,14 @@ struct ist *build_log_header(enum log_fmt format, int level, int facility,
                                else
                                        format = LOG_FORMAT_RFC3164;
                        }
+                       else if (metadata[LOG_META_TAG].len) {
+                               /* Tag is present but no hostname, we should
+                                * consider we try to emmit a local log
+                                * in legacy format (analog to RFC3164 but
+                                * with stripped hostname).
+                                */
+                               format = LOG_FORMAT_LOCAL;
+                       }
                        else if (metadata[LOG_META_PRIO].len) {
                                /* the source seems a parsed message
                                 * offering a valid level/prio prefix
@@ -1487,6 +1498,7 @@ struct ist *build_log_header(enum log_fmt format, int level, int facility,
 
        /* prepare priority, stored into 1 single elem */
        switch (format) {
+               case LOG_FORMAT_LOCAL:
                case LOG_FORMAT_RFC3164:
                case LOG_FORMAT_RFC5424:
                case LOG_FORMAT_PRIO:
@@ -1516,6 +1528,7 @@ struct ist *build_log_header(enum log_fmt format, int level, int facility,
 
        /* prepare timestamp, stored into a max of 4 elems */
        switch (format) {
+               case LOG_FORMAT_LOCAL:
                case LOG_FORMAT_RFC3164:
                        /* rfc3164 ex: 'Jan  1 00:00:00 ' */
                        if (metadata && metadata[LOG_META_TIME].len == LOG_LEGACYTIME_LEN) {
@@ -1656,9 +1669,10 @@ struct ist *build_log_header(enum log_fmt format, int level, int facility,
                                hdr_ctx.ist_vector[(*nbelem)++] = metadata[LOG_META_HOST];
                                hdr_ctx.ist_vector[(*nbelem)++] = ist2(" ", 1);
                        }
-                       else /* the caller MUST fill the hostname */
+                       else /* the caller MUST fill the hostname, this field is mandatory */
                                hdr_ctx.ist_vector[(*nbelem)++] = ist2("localhost ", 10);
-
+                       /* fall through */
+               case LOG_FORMAT_LOCAL:
                        if (!metadata || !metadata[LOG_META_TAG].len)
                                break;
 
@@ -1918,8 +1932,6 @@ void __send_log(struct list *logsrvs, struct buffer *tagb, int level,
        if (!metadata[LOG_META_HOST].len) {
                if (global.log_send_hostname)
                        metadata[LOG_META_HOST] = ist2(global.log_send_hostname, strlen(global.log_send_hostname));
-               else
-                       metadata[LOG_META_HOST] = ist2(hostname, strlen(hostname));
        }
 
        if (!tagb || !tagb->area)
index 09a302633f82f903769b9523304574279d4d0743..4995270e49702f7e8e3455800a6672f4fc4c9552 100644 (file)
@@ -191,8 +191,6 @@ int sink_announce_dropped(struct sink *sink, int facility)
                if (!metadata[LOG_META_HOST].len) {
                        if (global.log_send_hostname)
                                metadata[LOG_META_HOST] = ist2(global.log_send_hostname, strlen(global.log_send_hostname));
-                       else
-                               metadata[LOG_META_HOST] = ist2(hostname, strlen(hostname));
                }
 
                if (!metadata[LOG_META_TAG].len)