MEDIUM: log: add a new "raw" format

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.
This commit is contained in:
Willy Tarreau 2018-11-12 11:57:56 +01:00
parent e8746a08b2
commit c1b0645dac
3 changed files with 41 additions and 12 deletions

View 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

View 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 */
};

View File

@ -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 */
}