]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
MEDIUM: log: add a new "raw" format
authorWilly Tarreau <w@1wt.eu>
Mon, 12 Nov 2018 10:57:56 +0000 (11:57 +0100)
committerWilly Tarreau <w@1wt.eu>
Mon, 12 Nov 2018 17:37:55 +0000 (18:37 +0100)
This format is pretty similar to the previous "short" format except
that it also removes the severity level. Thus only the raw message is
sent. This is suitable for use in containers, where only the raw
information is expected and where the severity is supposed to come
from the file descriptor used.

doc/configuration.txt
include/types/log.h
src/log.c

index 89fddc12075597c076ac88d625bc7dd3238cfb12..52cc4328e3847fb153c8e7a96a92a9f7ed485103 100644 (file)
@@ -856,7 +856,8 @@ log <address> [len <length>] [format <format>] <facility> [max level [min level]
           as non-blocking calls will be ignored. Also there will be no way to
           purge nor rotate this file without restarting the process. Note that
           the configured syslog format is preserved, so the output is suitable
-          for use with a TCP syslog server. See also the "short" format below.
+          for use with a TCP syslog server. See also the "short" and "raw"
+          format below.
 
         - "stdout" / "stderr", which are respectively aliases for "fd@1" and
           "fd@2", see above.
@@ -892,16 +893,21 @@ log <address> [len <length>] [format <format>] <facility> [max level [min level]
               local log server. This format is compatible with what the systemd
               logger consumes.
 
+    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).
+
   <facility> must be one of the 24 standard syslog facilities :
 
                  kern   user   mail   daemon auth   syslog lpr    news
                  uucp   cron   auth2  ftp    ntp    audit  alert  cron2
                  local0 local1 local2 local3 local4 local5 local6 local7
 
-             Note that the facility is ignored for the "short" format, but
-             still required as a positional field. It is recommended to use
-             "daemon" in this case to make it clear that it's only supposed to
-             be used locally.
+             Note that the facility is ignored for the "short" and "raw"
+             formats, but still required as a positional field. It is
+             recommended to use "daemon" in this case to make it clear that
+             it's only supposed to be used locally.
 
   An optional level can be specified to filter outgoing messages. By default,
   all messages are sent. If a maximum level is specified, only messages with a
@@ -5147,7 +5153,8 @@ no log
                  ignored. Also there will be no way to purge nor rotate this
                  file without restarting the process. Note that the configured
                  syslog format is preserved, so the output is suitable for use
-                 with a TCP syslog server. See also the "short" format below.
+                 with a TCP syslog server. See also the "short" and "raw"
+                 formats below.
 
                - "stdout" / "stderr", which are respectively aliases for "fd@1"
                  and "fd@2", see above.
@@ -5182,16 +5189,21 @@ no log
                 local log server. This format is compatible with what the
                 systemd logger consumes.
 
+      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).
+
     <facility> must be one of the 24 standard syslog facilities :
 
                    kern   user   mail   daemon auth   syslog lpr    news
                    uucp   cron   auth2  ftp    ntp    audit  alert  cron2
                    local0 local1 local2 local3 local4 local5 local6 local7
 
-               Note that the facility is ignored for the "short" format, but
-               still required as a positional field. It is recommended to use
-               "daemon" in this case to make it clear that it's only supposed
-               to be used locally.
+               Note that the facility is ignored for the "short" and "raw"
+               formats, but still required as a positional field. It is
+               recommended to use "daemon" in this case to make it clear that
+               it's only supposed to be used locally.
 
     <level>    is optional and can be specified to filter outgoing messages. By
                default, all messages are sent. If a level is specified, only
@@ -5218,8 +5230,9 @@ no log
 
   Example :
     log global
-    log stdout format short daemon          # send everything to stdout
-    log stderr format short daemon notice   # send important events to stderr
+    log stdout format short daemon          # send log to systemd
+    log stdout format raw daemon            # send everything to stdout
+    log stderr format raw daemon notice     # send important events to stderr
     log 127.0.0.1:514 local0 notice         # only send important events
     log 127.0.0.1:514 local0 notice notice  # same but limit output level
     log "${LOCAL_SYSLOG}:514" local0 notice   # send to local server
index 3813cfbdeaee06c27d5319cb0f3db23d00bedc2d..d4d5976a820fe0abd77385d9d0f3b4803920870d 100644 (file)
@@ -42,6 +42,7 @@ enum {
        LOG_FORMAT_RFC3164 = 0,
        LOG_FORMAT_RFC5424,
        LOG_FORMAT_SHORT,
+       LOG_FORMAT_RAW,
        LOG_FORMATS,          /* number of supported log formats, must always be last */
 };
 
index 2aef5520fcf1c49f7301a94573d2876179f2dfff..f6eeacbec9bf1d00a3cadaa23fc9a7aa808a363c 100644 (file)
--- a/src/log.c
+++ b/src/log.c
@@ -75,6 +75,13 @@ static const struct log_fmt log_formats[LOG_FORMATS] = {
                        .sep2 = { .area = " ", .data = 1 },
                }
        },
+       [LOG_FORMAT_RAW] = {
+               .name = "raw",
+               .pid = {
+                       .sep1 = { .area = "", .data = 0 },
+                       .sep2 = { .area = "", .data = 0 },
+               }
+       },
 };
 
 #define FD_SETS_ARE_BITFIELDS
@@ -1403,6 +1410,14 @@ void __send_log(struct proxy *p, int level, char *message, size_t size, char *sd
                        max = MIN(size, maxlen) - 1;
                        goto send;
 
+               case LOG_FORMAT_RAW:
+                       /* all fields are known, skip the header generation */
+                       hdr_ptr = hdr = "";
+                       hdr_max = 0;
+                       maxlen = logsrv->maxlen;
+                       max = MIN(size, maxlen) - 1;
+                       goto send;
+
                default:
                        continue; /* must never happen */
                }