mirror of
https://github.com/haproxy/haproxy.git
synced 2026-02-03 20:39:41 -05:00
It is possible to globally declare ring-buffers, to be used as target for log
servers or traces.
ring <ringname>
Creates a new ring-buffer with name <ringname>.
description <text>
The descritpition is an optional description string of the ring. It will
appear on CLI. By default, <name> is reused to fill this field.
format <format>
Format used to store events into the ring buffer.
Arguments:
<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.
maxlen <length>
The maximum length of an event message stored into the ring,
including formatted header. If an event message is longer than
<length>, it will be truncated to this length.
size <size>
This is the optional size in bytes for the ring-buffer. Default value is
set to BUFSIZE.
Example:
global
log ring@myring local7
ring myring
description "My local buffer"
format rfc3164
maxlen 1200
Note: ring names are resolved during post configuration processing.
233 lines
6.2 KiB
C
233 lines
6.2 KiB
C
/*
|
|
include/types/log.h
|
|
This file contains definitions of log-related structures and macros.
|
|
|
|
Copyright (C) 2000-2006 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 _TYPES_LOG_H
|
|
#define _TYPES_LOG_H
|
|
|
|
#include <sys/socket.h>
|
|
#include <sys/un.h>
|
|
#include <netinet/in.h>
|
|
#include <common/config.h>
|
|
#include <common/hathreads.h>
|
|
#include <common/mini-clist.h>
|
|
#include <types/ring.h>
|
|
|
|
#define NB_LOG_FACILITIES 24
|
|
#define NB_LOG_LEVELS 8
|
|
#define NB_MSG_IOVEC_ELEMENTS 8
|
|
#define SYSLOG_PORT 514
|
|
#define UNIQUEID_LEN 128
|
|
|
|
/* 64kB to archive startup-logs seems way more than enough */
|
|
#ifndef STARTUP_LOG_SIZE
|
|
#define STARTUP_LOG_SIZE 65536
|
|
#endif
|
|
|
|
/* The array containing the names of the log levels. */
|
|
extern const char *log_levels[];
|
|
|
|
/* enum for log format */
|
|
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 */
|
|
};
|
|
|
|
/* log target types */
|
|
enum log_tgt {
|
|
LOG_TARGET_DGRAM = 0, // datagram address (udp, unix socket)
|
|
LOG_TARGET_FD, // file descriptor
|
|
LOG_TARGET_BUFFER, // ring buffer
|
|
};
|
|
|
|
/* lists of fields that can be logged */
|
|
enum {
|
|
|
|
LOG_FMT_TEXT = 0, /* raw text */
|
|
LOG_FMT_EXPR, /* sample expression */
|
|
LOG_FMT_SEPARATOR, /* separator replaced by one space */
|
|
|
|
/* information fields */
|
|
LOG_FMT_GLOBAL,
|
|
LOG_FMT_CLIENTIP,
|
|
LOG_FMT_CLIENTPORT,
|
|
LOG_FMT_BACKENDIP,
|
|
LOG_FMT_BACKENDPORT,
|
|
LOG_FMT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TP_VERSION,
|
|
LOG_FMT_HOSTNAME,
|
|
LOG_FMT_UNIQUEID,
|
|
LOG_FMT_SSL_CIPHER,
|
|
LOG_FMT_SSL_VERSION,
|
|
};
|
|
|
|
/* enum for parse_logformat_string */
|
|
enum {
|
|
LF_INIT = 0, // before first character
|
|
LF_TEXT, // normal text
|
|
LF_SEPARATOR, // a single separator
|
|
LF_VAR, // variable name, after '%' or '%{..}'
|
|
LF_STARTVAR, // % in text
|
|
LF_STARG, // after '%{' and berore '}'
|
|
LF_EDARG, // '}' after '%{'
|
|
LF_STEXPR, // after '%[' or '%{..}[' and berore ']'
|
|
LF_EDEXPR, // ']' after '%['
|
|
LF_END, // \0 found
|
|
};
|
|
|
|
|
|
struct logformat_node {
|
|
struct list list;
|
|
int type; // LOG_FMT_*
|
|
int options; // LOG_OPT_*
|
|
char *arg; // text for LOG_FMT_TEXT, arg for others
|
|
void *expr; // for use with LOG_FMT_EXPR
|
|
};
|
|
|
|
#define LOG_OPT_HEXA 0x00000001
|
|
#define LOG_OPT_MANDATORY 0x00000002
|
|
#define LOG_OPT_QUOTE 0x00000004
|
|
#define LOG_OPT_REQ_CAP 0x00000008
|
|
#define LOG_OPT_RES_CAP 0x00000010
|
|
#define LOG_OPT_HTTP 0x00000020
|
|
#define LOG_OPT_ESC 0x00000040
|
|
|
|
|
|
/* Fields that need to be extracted from the incoming connection or request for
|
|
* logging or for sending specific header information. They're set in px->to_log
|
|
* and appear as flags in session->logs.logwait, which are removed once the
|
|
* required information has been collected.
|
|
*/
|
|
#define LW_INIT 1 /* anything */
|
|
#define LW_CLIP 2 /* CLient IP */
|
|
#define LW_SVIP 4 /* SerVer IP */
|
|
#define LW_SVID 8 /* server ID */
|
|
#define LW_REQ 16 /* http REQuest */
|
|
#define LW_RESP 32 /* http RESPonse */
|
|
#define LW_BYTES 256 /* bytes read from server */
|
|
#define LW_COOKIE 512 /* captured cookie */
|
|
#define LW_REQHDR 1024 /* request header(s) */
|
|
#define LW_RSPHDR 2048 /* response header(s) */
|
|
#define LW_BCKIP 4096 /* backend IP */
|
|
#define LW_FRTIP 8192 /* frontend IP */
|
|
#define LW_XPRT 16384 /* transport layer information (eg: SSL) */
|
|
|
|
/* Range of indexes for log sampling. */
|
|
struct smp_log_range {
|
|
unsigned int low; /* Low limit of the indexes of this range. */
|
|
unsigned int high; /* High limit of the indexes of this range. */
|
|
size_t sz; /* The size of this range, or number of indexes in
|
|
* this range.
|
|
*/
|
|
unsigned int curr_idx; /* The current index used to sample this range of
|
|
*indexes.
|
|
*/
|
|
};
|
|
|
|
/* Log sampling information. */
|
|
struct smp_info {
|
|
struct smp_log_range *smp_rgs; /* Array of ranges for log sampling. */
|
|
size_t smp_rgs_sz; /* The size of <smp_rgs> array. */
|
|
size_t smp_sz; /* The total number of logs to be sampled. */
|
|
unsigned int curr_rg; /* The current range to be sampled. */
|
|
unsigned int curr_idx; /* A counter to store the current index of the log
|
|
* already sampled.
|
|
*/
|
|
};
|
|
|
|
struct logsrv {
|
|
struct list list;
|
|
struct sockaddr_storage addr;
|
|
struct smp_info lb;
|
|
struct sink *sink;
|
|
char *ring_name;
|
|
enum log_tgt type;
|
|
int format;
|
|
int facility;
|
|
int level;
|
|
int minlvl;
|
|
int maxlen;
|
|
struct logsrv *ref;
|
|
__decl_hathreads(HA_SPINLOCK_T lock);
|
|
};
|
|
|
|
#endif /* _TYPES_LOG_H */
|
|
|
|
/*
|
|
* Local variables:
|
|
* c-indent-level: 8
|
|
* c-basic-offset: 8
|
|
* End:
|
|
*/
|