mirror of
https://git.haproxy.org/git/haproxy.git/
synced 2025-11-02 09:31:19 +01:00
This patch adds the new global statement:
ring <name> [desc <desc>] [format <format>] [size <size>] [maxlen <length>]
Creates a named ring buffer which could be used on log line for instance.
<desc> is an optionnal description string of the ring. It will appear on
CLI. By default, <name> is reused to fill this field.
<format> is the log format used when generating syslog messages. It may be
one of the following :
iso A message containing only the ISO date, followed by the text.
The PID, process name and system name are omitted. This is
designed to be used with a local log server.
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.
(https://tools.ietf.org/html/rfc3164)
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.
timed A message containing only a level between angle brackets such as
'<3>', followed by ISO date and by the text. The PID, process
name and system name are omitted. This is designed to be
used with a local log server.
<length> is the maximum length of event message stored into the ring,
including formatted header. If the event message is longer
than <length>, it would be truncated to this length.
<name> is the ring identifier, which follows the same naming convention as
proxies and servers.
<size> is the optionnal size in bytes. Default value is set to BUFSIZE.
Note: Historically sink's name and desc were refs on const strings. But with new
configurable rings a dynamic allocation is needed.
92 lines
3.0 KiB
C
92 lines
3.0 KiB
C
/*
|
|
* include/proto/sink.h
|
|
* This file provides declarations for event sinks management
|
|
*
|
|
* Copyright (C) 2000-2019 Willy Tarreau - w@1wt.eu
|
|
*
|
|
* This library is free software; you can redistribute it and/or
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
* License as published by the Free Software Foundation, version 2.1
|
|
* exclusively.
|
|
*
|
|
* This library is distributed in the hope that it will be useful,
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
* Lesser General Public License for more details.
|
|
*
|
|
* You should have received a copy of the GNU Lesser General Public
|
|
* License along with this library; if not, write to the Free Software
|
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
|
*/
|
|
|
|
#ifndef _PROTO_SINK_H
|
|
#define _PROTO_SINK_H
|
|
|
|
#include <common/mini-clist.h>
|
|
#include <types/sink.h>
|
|
|
|
extern struct list sink_list;
|
|
|
|
struct sink *sink_find(const char *name);
|
|
struct sink *sink_new_fd(const char *name, const char *desc, enum sink_fmt fmt, int fd);
|
|
ssize_t __sink_write(struct sink *sink, const struct ist msg[], size_t nmsg,
|
|
int level, int facility, struct ist * tag,
|
|
struct ist *pid, struct ist *sd);
|
|
int sink_announce_dropped(struct sink *sink, int facility, struct ist *pid);
|
|
|
|
|
|
/* tries to send <nmsg> message parts (up to 8, ignored above) from message
|
|
* array <msg> to sink <sink>. Formatting according to the sink's preference is
|
|
* done here. Lost messages are accounted for in the sink's counter. If there
|
|
* were lost messages, an attempt is first made to indicate it.
|
|
* The function returns the number of Bytes effectively sent or announced.
|
|
* or <= 0 in other cases.
|
|
*/
|
|
static inline ssize_t sink_write(struct sink *sink, const struct ist msg[], size_t nmsg,
|
|
int level, int facility, struct ist * tag,
|
|
struct ist *pid, struct ist *sd)
|
|
{
|
|
ssize_t sent;
|
|
|
|
if (unlikely(sink->ctx.dropped > 0)) {
|
|
/* We need to take an exclusive lock so that other producers
|
|
* don't do the same thing at the same time and above all we
|
|
* want to be sure others have finished sending their messages
|
|
* so that the dropped event arrives exactly at the right
|
|
* position.
|
|
*/
|
|
HA_RWLOCK_WRLOCK(LOGSRV_LOCK, &sink->ctx.lock);
|
|
sent = sink_announce_dropped(sink, facility, pid);
|
|
HA_RWLOCK_WRUNLOCK(LOGSRV_LOCK, &sink->ctx.lock);
|
|
|
|
if (!sent) {
|
|
/* we failed, we don't try to send our log as if it
|
|
* would pass by chance, we'd get disordered events.
|
|
*/
|
|
goto fail;
|
|
}
|
|
}
|
|
|
|
HA_RWLOCK_RDLOCK(LOGSRV_LOCK, &sink->ctx.lock);
|
|
sent = __sink_write(sink, msg, nmsg, level, facility, tag, pid, sd);
|
|
HA_RWLOCK_RDUNLOCK(LOGSRV_LOCK, &sink->ctx.lock);
|
|
|
|
fail:
|
|
if (unlikely(sent <= 0))
|
|
HA_ATOMIC_ADD(&sink->ctx.dropped, 1);
|
|
|
|
return sent;
|
|
}
|
|
|
|
|
|
int parse_sinkbuf(char **args, char **err);
|
|
|
|
#endif /* _PROTO_SINK_H */
|
|
|
|
/*
|
|
* Local variables:
|
|
* c-indent-level: 8
|
|
* c-basic-offset: 8
|
|
* End:
|
|
*/
|