blob: cfafb919abc2b8f4a537daeda78e865c07269e41 [file] [log] [blame]
Willy Tarreaubaaee002006-06-26 02:48:02 +02001/*
2 include/types/log.h
3 This file contains definitions of log-related structures and macros.
4
5 Copyright (C) 2000-2006 Willy Tarreau - w@1wt.eu
6
7 This library is free software; you can redistribute it and/or
8 modify it under the terms of the GNU Lesser General Public
9 License as published by the Free Software Foundation, version 2.1
10 exclusively.
11
12 This library is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 Lesser General Public License for more details.
16
17 You should have received a copy of the GNU Lesser General Public
18 License along with this library; if not, write to the Free Software
19 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
20*/
21
22#ifndef _TYPES_LOG_H
23#define _TYPES_LOG_H
24
Willy Tarreau019767b2007-12-05 11:11:55 +010025#include <sys/socket.h>
Robert Tsai81ae1952007-12-05 10:47:29 +010026#include <sys/un.h>
27#include <netinet/in.h>
Willy Tarreau4c7e4b72020-05-27 12:58:42 +020028#include <haproxy/api-t.h>
Willy Tarreau3f567e42020-05-28 15:29:19 +020029#include <haproxy/thread.h>
Willy Tarreau853b2972020-05-27 18:01:47 +020030#include <haproxy/list-t.h>
Willy Tarreauc046d162019-08-30 15:24:59 +020031#include <types/ring.h>
Willy Tarreaubaaee002006-06-26 02:48:02 +020032
Willy Tarreaubaaee002006-06-26 02:48:02 +020033#define NB_LOG_FACILITIES 24
34#define NB_LOG_LEVELS 8
Dragan Dosen43885c72015-10-01 13:18:13 +020035#define NB_MSG_IOVEC_ELEMENTS 8
Willy Tarreaubaaee002006-06-26 02:48:02 +020036#define SYSLOG_PORT 514
William Lallemanda73203e2012-03-12 12:48:57 +010037#define UNIQUEID_LEN 128
38
Willy Tarreau869efd52019-11-15 15:16:57 +010039/* 64kB to archive startup-logs seems way more than enough */
40#ifndef STARTUP_LOG_SIZE
41#define STARTUP_LOG_SIZE 65536
42#endif
43
Thierry FOURNIER2ba18a22015-01-23 14:07:08 +010044/* The array containing the names of the log levels. */
45extern const char *log_levels[];
Willy Tarreaubaaee002006-06-26 02:48:02 +020046
Dragan Dosen1322d092015-09-22 16:05:32 +020047/* enum for log format */
48enum {
49 LOG_FORMAT_RFC3164 = 0,
50 LOG_FORMAT_RFC5424,
Willy Tarreaue8746a02018-11-12 08:45:00 +010051 LOG_FORMAT_SHORT,
Willy Tarreauc1b06452018-11-12 11:57:56 +010052 LOG_FORMAT_RAW,
Dragan Dosen1322d092015-09-22 16:05:32 +020053 LOG_FORMATS, /* number of supported log formats, must always be last */
54};
55
Willy Tarreauf3dc30f2019-08-30 14:18:44 +020056/* log target types */
57enum log_tgt {
58 LOG_TARGET_DGRAM = 0, // datagram address (udp, unix socket)
59 LOG_TARGET_FD, // file descriptor
Willy Tarreauc046d162019-08-30 15:24:59 +020060 LOG_TARGET_BUFFER, // ring buffer
Willy Tarreauf3dc30f2019-08-30 14:18:44 +020061};
62
William Lallemand723b73a2012-02-08 16:37:49 +010063/* lists of fields that can be logged */
64enum {
65
William Lallemand1d705562012-03-12 12:46:41 +010066 LOG_FMT_TEXT = 0, /* raw text */
Willy Tarreauc8368452012-12-21 00:09:23 +010067 LOG_FMT_EXPR, /* sample expression */
William Lallemand1d705562012-03-12 12:46:41 +010068 LOG_FMT_SEPARATOR, /* separator replaced by one space */
William Lallemand723b73a2012-02-08 16:37:49 +010069
70 /* information fields */
William Lallemand1d705562012-03-12 12:46:41 +010071 LOG_FMT_GLOBAL,
72 LOG_FMT_CLIENTIP,
73 LOG_FMT_CLIENTPORT,
74 LOG_FMT_BACKENDIP,
75 LOG_FMT_BACKENDPORT,
William Lallemand5f232402012-04-05 18:02:55 +020076 LOG_FMT_FRONTENDIP,
77 LOG_FMT_FRONTENDPORT,
78 LOG_FMT_SERVERPORT,
79 LOG_FMT_SERVERIP,
80 LOG_FMT_COUNTER,
Willy Tarreau7346acb2014-08-28 15:03:15 +020081 LOG_FMT_LOGCNT,
William Lallemand5f232402012-04-05 18:02:55 +020082 LOG_FMT_PID,
William Lallemand1d705562012-03-12 12:46:41 +010083 LOG_FMT_DATE,
84 LOG_FMT_DATEGMT,
Yuxans Yao4e25b012012-10-19 10:36:09 +080085 LOG_FMT_DATELOCAL,
William Lallemand5f232402012-04-05 18:02:55 +020086 LOG_FMT_TS,
William Lallemand1d705562012-03-12 12:46:41 +010087 LOG_FMT_MS,
88 LOG_FMT_FRONTEND,
Willy Tarreau773d65f2012-10-12 14:56:11 +020089 LOG_FMT_FRONTEND_XPRT,
William Lallemand1d705562012-03-12 12:46:41 +010090 LOG_FMT_BACKEND,
91 LOG_FMT_SERVER,
92 LOG_FMT_BYTES,
Willy Tarreauc5259fd2012-12-20 15:38:04 +010093 LOG_FMT_BYTES_UP,
Thierry FOURNIER / OZON.IO4cac3592016-07-28 17:19:45 +020094 LOG_FMT_Ta,
95 LOG_FMT_Th,
96 LOG_FMT_Ti,
William Lallemand1d705562012-03-12 12:46:41 +010097 LOG_FMT_TQ,
98 LOG_FMT_TW,
99 LOG_FMT_TC,
Thierry FOURNIER / OZON.IO4cac3592016-07-28 17:19:45 +0200100 LOG_FMT_Tr,
101 LOG_FMT_tr,
102 LOG_FMT_trg,
103 LOG_FMT_trl,
William Lallemand1d705562012-03-12 12:46:41 +0100104 LOG_FMT_TR,
Willy Tarreau27b639d2016-05-17 17:55:27 +0200105 LOG_FMT_TD,
William Lallemand1d705562012-03-12 12:46:41 +0100106 LOG_FMT_TT,
Damien Claisse57c8eb92020-04-28 12:09:19 +0000107 LOG_FMT_TU,
William Lallemand1d705562012-03-12 12:46:41 +0100108 LOG_FMT_STATUS,
109 LOG_FMT_CCLIENT,
110 LOG_FMT_CSERVER,
111 LOG_FMT_TERMSTATE,
112 LOG_FMT_TERMSTATE_CK,
William Lallemand1d705562012-03-12 12:46:41 +0100113 LOG_FMT_ACTCONN,
114 LOG_FMT_FECONN,
115 LOG_FMT_BECONN,
116 LOG_FMT_SRVCONN,
117 LOG_FMT_RETRIES,
William Lallemand1d705562012-03-12 12:46:41 +0100118 LOG_FMT_SRVQUEUE,
119 LOG_FMT_BCKQUEUE,
120 LOG_FMT_HDRREQUEST,
121 LOG_FMT_HDRRESPONS,
122 LOG_FMT_HDRREQUESTLIST,
123 LOG_FMT_HDRRESPONSLIST,
124 LOG_FMT_REQ,
Andrew Hayworth0ebc55f2015-04-27 21:37:03 +0000125 LOG_FMT_HTTP_METHOD,
126 LOG_FMT_HTTP_URI,
127 LOG_FMT_HTTP_PATH,
Andrew Hayworthe63ac872015-07-31 16:14:16 +0000128 LOG_FMT_HTTP_QUERY,
Andrew Hayworth0ebc55f2015-04-27 21:37:03 +0000129 LOG_FMT_HTTP_VERSION,
William Lallemand5f232402012-04-05 18:02:55 +0200130 LOG_FMT_HOSTNAME,
William Lallemanda73203e2012-03-12 12:48:57 +0100131 LOG_FMT_UNIQUEID,
Willy Tarreauffc3fcd2012-10-12 20:17:54 +0200132 LOG_FMT_SSL_CIPHER,
133 LOG_FMT_SSL_VERSION,
William Lallemand723b73a2012-02-08 16:37:49 +0100134};
135
Willy Tarreau8a3f52f2012-12-20 21:23:42 +0100136/* enum for parse_logformat_string */
William Lallemand723b73a2012-02-08 16:37:49 +0100137enum {
Willy Tarreau8a3f52f2012-12-20 21:23:42 +0100138 LF_INIT = 0, // before first character
139 LF_TEXT, // normal text
140 LF_SEPARATOR, // a single separator
141 LF_VAR, // variable name, after '%' or '%{..}'
142 LF_STARTVAR, // % in text
143 LF_STARG, // after '%{' and berore '}'
144 LF_EDARG, // '}' after '%{'
Willy Tarreauc8368452012-12-21 00:09:23 +0100145 LF_STEXPR, // after '%[' or '%{..}[' and berore ']'
146 LF_EDEXPR, // ']' after '%['
Willy Tarreau8a3f52f2012-12-20 21:23:42 +0100147 LF_END, // \0 found
William Lallemand723b73a2012-02-08 16:37:49 +0100148};
149
150
151struct logformat_node {
152 struct list list;
Willy Tarreauc8368452012-12-21 00:09:23 +0100153 int type; // LOG_FMT_*
154 int options; // LOG_OPT_*
155 char *arg; // text for LOG_FMT_TEXT, arg for others
156 void *expr; // for use with LOG_FMT_EXPR
William Lallemand723b73a2012-02-08 16:37:49 +0100157};
158
William Lallemand5f232402012-04-05 18:02:55 +0200159#define LOG_OPT_HEXA 0x00000001
William Lallemand723b73a2012-02-08 16:37:49 +0100160#define LOG_OPT_MANDATORY 0x00000002
161#define LOG_OPT_QUOTE 0x00000004
Willy Tarreauc8368452012-12-21 00:09:23 +0100162#define LOG_OPT_REQ_CAP 0x00000008
163#define LOG_OPT_RES_CAP 0x00000010
Thierry FOURNIERd048d8b2014-03-13 16:46:18 +0100164#define LOG_OPT_HTTP 0x00000020
Dragan Dosen835b9212016-02-12 13:23:03 +0100165#define LOG_OPT_ESC 0x00000040
William Lallemand723b73a2012-02-08 16:37:49 +0100166
Willy Tarreaubaaee002006-06-26 02:48:02 +0200167
Willy Tarreaud79a3b22012-12-28 09:40:16 +0100168/* Fields that need to be extracted from the incoming connection or request for
169 * logging or for sending specific header information. They're set in px->to_log
170 * and appear as flags in session->logs.logwait, which are removed once the
171 * required information has been collected.
172 */
173#define LW_INIT 1 /* anything */
Willy Tarreaubaaee002006-06-26 02:48:02 +0200174#define LW_CLIP 2 /* CLient IP */
175#define LW_SVIP 4 /* SerVer IP */
176#define LW_SVID 8 /* server ID */
177#define LW_REQ 16 /* http REQuest */
178#define LW_RESP 32 /* http RESPonse */
Willy Tarreaubaaee002006-06-26 02:48:02 +0200179#define LW_BYTES 256 /* bytes read from server */
180#define LW_COOKIE 512 /* captured cookie */
181#define LW_REQHDR 1024 /* request header(s) */
182#define LW_RSPHDR 2048 /* response header(s) */
William Lallemand5e19a282012-04-02 16:22:10 +0200183#define LW_BCKIP 4096 /* backend IP */
184#define LW_FRTIP 8192 /* frontend IP */
Willy Tarreau93dbc2b2012-10-12 18:01:49 +0200185#define LW_XPRT 16384 /* transport layer information (eg: SSL) */
Willy Tarreaubaaee002006-06-26 02:48:02 +0200186
Frédéric Lécailled95ea282019-04-24 16:14:33 +0200187/* Range of indexes for log sampling. */
188struct smp_log_range {
189 unsigned int low; /* Low limit of the indexes of this range. */
190 unsigned int high; /* High limit of the indexes of this range. */
191 size_t sz; /* The size of this range, or number of indexes in
192 * this range.
193 */
194 unsigned int curr_idx; /* The current index used to sample this range of
195 *indexes.
196 */
197};
198
199/* Log sampling information. */
200struct smp_info {
201 struct smp_log_range *smp_rgs; /* Array of ranges for log sampling. */
202 size_t smp_rgs_sz; /* The size of <smp_rgs> array. */
203 size_t smp_sz; /* The total number of logs to be sampled. */
204 unsigned int curr_rg; /* The current range to be sampled. */
205 unsigned int curr_idx; /* A counter to store the current index of the log
206 * already sampled.
207 */
208};
209
Robert Tsai81ae1952007-12-05 10:47:29 +0100210struct logsrv {
William Lallemand0f99e342011-10-12 17:50:54 +0200211 struct list list;
David du Colombier11bcb6c2011-03-24 12:23:00 +0100212 struct sockaddr_storage addr;
Frédéric Lécailled95ea282019-04-24 16:14:33 +0200213 struct smp_info lb;
Emeric Brune709e1e2020-05-06 17:23:59 +0200214 struct sink *sink;
Emeric Brun99c453d2020-05-25 15:01:04 +0200215 char *ring_name;
Willy Tarreauf3dc30f2019-08-30 14:18:44 +0200216 enum log_tgt type;
Dragan Dosen1322d092015-09-22 16:05:32 +0200217 int format;
William Lallemand0f99e342011-10-12 17:50:54 +0200218 int facility;
219 int level;
220 int minlvl;
Willy Tarreau18324f52014-06-27 18:10:07 +0200221 int maxlen;
Christopher Faulet28ac0992018-03-26 16:09:19 +0200222 struct logsrv *ref;
Willy Tarreauaf613e82020-06-05 08:40:51 +0200223 __decl_thread(HA_SPINLOCK_T lock);
Robert Tsai81ae1952007-12-05 10:47:29 +0100224};
225
Willy Tarreaubaaee002006-06-26 02:48:02 +0200226#endif /* _TYPES_LOG_H */
227
228/*
229 * Local variables:
230 * c-indent-level: 8
231 * c-basic-offset: 8
232 * End:
233 */