mirror of
http://git.haproxy.org/git/haproxy.git/
synced 2025-02-12 16:37:20 +00:00
MEDIUM: log: support a new "short" format
This format is meant to be used with local file descriptors. It emits messages only prefixed with a level, removing all the process name, system name, date and so on. It is similar to the printk() format used on Linux. It's suitable to be sent to a local logger compatible with systemd's output format. Note that the facility is still required but not used, hence it is suggested to use "daemon" to remind that it's a local logger. Example : log stdout format short daemon # send everything to stdout log stderr format short daemon notice # send important events to stderr
This commit is contained in:
parent
5a32ecc6cf
commit
e8746a08b2
@ -856,7 +856,7 @@ 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.
|
||||
for use with a TCP syslog server. See also the "short" format below.
|
||||
|
||||
- "stdout" / "stderr", which are respectively aliases for "fd@1" and
|
||||
"fd@2", see above.
|
||||
@ -886,11 +886,22 @@ log <address> [len <length>] [format <format>] <facility> [max level [min level]
|
||||
rfc5424 The RFC5424 syslog message format.
|
||||
(https://tools.ietf.org/html/rfc5424)
|
||||
|
||||
short A message containing only a level between angle brackets such as
|
||||
'<3>', followed by the text. The PID, date, time, process name
|
||||
and system name are omitted. This is designed to be used with a
|
||||
local log server. This format is compatible with what the systemd
|
||||
logger consumes.
|
||||
|
||||
<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
|
||||
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.
|
||||
|
||||
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
|
||||
@ -5136,7 +5147,7 @@ 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.
|
||||
with a TCP syslog server. See also the "short" format below.
|
||||
|
||||
- "stdout" / "stderr", which are respectively aliases for "fd@1"
|
||||
and "fd@2", see above.
|
||||
@ -5165,11 +5176,22 @@ no log
|
||||
rfc5424 The RFC5424 syslog message format.
|
||||
(https://tools.ietf.org/html/rfc5424)
|
||||
|
||||
short A message containing only a level between angle brackets such as
|
||||
'<3>', followed by the text. The PID, date, time, process name
|
||||
and system name are omitted. This is designed to be used with a
|
||||
local log server. This format is compatible with what the
|
||||
systemd logger consumes.
|
||||
|
||||
<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
|
||||
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.
|
||||
|
||||
<level> is optional and can be specified to filter outgoing messages. By
|
||||
default, all messages are sent. If a level is specified, only
|
||||
@ -5196,6 +5218,8 @@ 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 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
|
||||
|
@ -41,6 +41,7 @@ extern const char *log_levels[];
|
||||
enum {
|
||||
LOG_FORMAT_RFC3164 = 0,
|
||||
LOG_FORMAT_RFC5424,
|
||||
LOG_FORMAT_SHORT,
|
||||
LOG_FORMATS, /* number of supported log formats, must always be last */
|
||||
};
|
||||
|
||||
|
24
src/log.c
24
src/log.c
@ -67,7 +67,14 @@ static const struct log_fmt log_formats[LOG_FORMATS] = {
|
||||
.sep1 = { .area = " ", .data = 1 },
|
||||
.sep2 = { .area = " - ", .data = 3 }
|
||||
}
|
||||
}
|
||||
},
|
||||
[LOG_FORMAT_SHORT] = {
|
||||
.name = "short",
|
||||
.pid = {
|
||||
.sep1 = { .area = "", .data = 0 },
|
||||
.sep2 = { .area = " ", .data = 1 },
|
||||
}
|
||||
},
|
||||
};
|
||||
|
||||
#define FD_SETS_ARE_BITFIELDS
|
||||
@ -1329,7 +1336,8 @@ void __send_log(struct proxy *p, int level, char *message, size_t size, char *sd
|
||||
const struct logsrv *logsrv = tmp;
|
||||
int *plogfd = logsrv->addr.ss_family == AF_UNIX ?
|
||||
&logfdunix : &logfdinet;
|
||||
char *pid_sep1 = NULL, *pid_sep2 = NULL;
|
||||
char *pid_sep1 = "", *pid_sep2 = "";
|
||||
char logheader_short[3];
|
||||
int sent;
|
||||
int maxlen;
|
||||
int hdr_max = 0;
|
||||
@ -1383,6 +1391,18 @@ void __send_log(struct proxy *p, int level, char *message, size_t size, char *sd
|
||||
sd_max = sd_size; /* the SD part allowed only in RFC5424 */
|
||||
break;
|
||||
|
||||
case LOG_FORMAT_SHORT:
|
||||
/* all fields are known, skip the header generation */
|
||||
hdr = logheader_short;
|
||||
hdr[0] = '<';
|
||||
hdr[1] = '0' + MAX(level, logsrv->minlvl);
|
||||
hdr[2] = '>';
|
||||
hdr_ptr = hdr;
|
||||
hdr_max = 3;
|
||||
maxlen = logsrv->maxlen - hdr_max;
|
||||
max = MIN(size, maxlen) - 1;
|
||||
goto send;
|
||||
|
||||
default:
|
||||
continue; /* must never happen */
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user