blob: dbbd73bf70d843283a029429ffb8f4c2d8b8ee6a [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 Tarreaue3ba5f02006-06-29 18:54:54 +020028#include <common/config.h>
Frédéric Lécailled803e472019-04-25 07:42:09 +020029#include <common/hathreads.h>
Willy Tarreauc7e42382012-08-24 19:22:53 +020030#include <common/mini-clist.h>
Willy Tarreaubaaee002006-06-26 02:48:02 +020031
Willy Tarreaubaaee002006-06-26 02:48:02 +020032#define NB_LOG_FACILITIES 24
33#define NB_LOG_LEVELS 8
Dragan Dosen43885c72015-10-01 13:18:13 +020034#define NB_MSG_IOVEC_ELEMENTS 8
Willy Tarreaubaaee002006-06-26 02:48:02 +020035#define SYSLOG_PORT 514
William Lallemanda73203e2012-03-12 12:48:57 +010036#define UNIQUEID_LEN 128
37
Thierry FOURNIER2ba18a22015-01-23 14:07:08 +010038/* The array containing the names of the log levels. */
39extern const char *log_levels[];
Willy Tarreaubaaee002006-06-26 02:48:02 +020040
Dragan Dosen1322d092015-09-22 16:05:32 +020041/* enum for log format */
42enum {
43 LOG_FORMAT_RFC3164 = 0,
44 LOG_FORMAT_RFC5424,
Willy Tarreaue8746a02018-11-12 08:45:00 +010045 LOG_FORMAT_SHORT,
Willy Tarreauc1b06452018-11-12 11:57:56 +010046 LOG_FORMAT_RAW,
Dragan Dosen1322d092015-09-22 16:05:32 +020047 LOG_FORMATS, /* number of supported log formats, must always be last */
48};
49
Willy Tarreauf3dc30f2019-08-30 14:18:44 +020050/* log target types */
51enum log_tgt {
52 LOG_TARGET_DGRAM = 0, // datagram address (udp, unix socket)
53 LOG_TARGET_FD, // file descriptor
54};
55
William Lallemand723b73a2012-02-08 16:37:49 +010056/* lists of fields that can be logged */
57enum {
58
William Lallemand1d705562012-03-12 12:46:41 +010059 LOG_FMT_TEXT = 0, /* raw text */
Willy Tarreauc8368452012-12-21 00:09:23 +010060 LOG_FMT_EXPR, /* sample expression */
William Lallemand1d705562012-03-12 12:46:41 +010061 LOG_FMT_SEPARATOR, /* separator replaced by one space */
William Lallemand723b73a2012-02-08 16:37:49 +010062
63 /* information fields */
William Lallemand1d705562012-03-12 12:46:41 +010064 LOG_FMT_GLOBAL,
65 LOG_FMT_CLIENTIP,
66 LOG_FMT_CLIENTPORT,
67 LOG_FMT_BACKENDIP,
68 LOG_FMT_BACKENDPORT,
William Lallemand5f232402012-04-05 18:02:55 +020069 LOG_FMT_FRONTENDIP,
70 LOG_FMT_FRONTENDPORT,
71 LOG_FMT_SERVERPORT,
72 LOG_FMT_SERVERIP,
73 LOG_FMT_COUNTER,
Willy Tarreau7346acb2014-08-28 15:03:15 +020074 LOG_FMT_LOGCNT,
William Lallemand5f232402012-04-05 18:02:55 +020075 LOG_FMT_PID,
William Lallemand1d705562012-03-12 12:46:41 +010076 LOG_FMT_DATE,
77 LOG_FMT_DATEGMT,
Yuxans Yao4e25b012012-10-19 10:36:09 +080078 LOG_FMT_DATELOCAL,
William Lallemand5f232402012-04-05 18:02:55 +020079 LOG_FMT_TS,
William Lallemand1d705562012-03-12 12:46:41 +010080 LOG_FMT_MS,
81 LOG_FMT_FRONTEND,
Willy Tarreau773d65f2012-10-12 14:56:11 +020082 LOG_FMT_FRONTEND_XPRT,
William Lallemand1d705562012-03-12 12:46:41 +010083 LOG_FMT_BACKEND,
84 LOG_FMT_SERVER,
85 LOG_FMT_BYTES,
Willy Tarreauc5259fd2012-12-20 15:38:04 +010086 LOG_FMT_BYTES_UP,
Thierry FOURNIER / OZON.IO4cac3592016-07-28 17:19:45 +020087 LOG_FMT_Ta,
88 LOG_FMT_Th,
89 LOG_FMT_Ti,
William Lallemand1d705562012-03-12 12:46:41 +010090 LOG_FMT_TQ,
91 LOG_FMT_TW,
92 LOG_FMT_TC,
Thierry FOURNIER / OZON.IO4cac3592016-07-28 17:19:45 +020093 LOG_FMT_Tr,
94 LOG_FMT_tr,
95 LOG_FMT_trg,
96 LOG_FMT_trl,
William Lallemand1d705562012-03-12 12:46:41 +010097 LOG_FMT_TR,
Willy Tarreau27b639d2016-05-17 17:55:27 +020098 LOG_FMT_TD,
William Lallemand1d705562012-03-12 12:46:41 +010099 LOG_FMT_TT,
100 LOG_FMT_STATUS,
101 LOG_FMT_CCLIENT,
102 LOG_FMT_CSERVER,
103 LOG_FMT_TERMSTATE,
104 LOG_FMT_TERMSTATE_CK,
William Lallemand1d705562012-03-12 12:46:41 +0100105 LOG_FMT_ACTCONN,
106 LOG_FMT_FECONN,
107 LOG_FMT_BECONN,
108 LOG_FMT_SRVCONN,
109 LOG_FMT_RETRIES,
William Lallemand1d705562012-03-12 12:46:41 +0100110 LOG_FMT_SRVQUEUE,
111 LOG_FMT_BCKQUEUE,
112 LOG_FMT_HDRREQUEST,
113 LOG_FMT_HDRRESPONS,
114 LOG_FMT_HDRREQUESTLIST,
115 LOG_FMT_HDRRESPONSLIST,
116 LOG_FMT_REQ,
Andrew Hayworth0ebc55f2015-04-27 21:37:03 +0000117 LOG_FMT_HTTP_METHOD,
118 LOG_FMT_HTTP_URI,
119 LOG_FMT_HTTP_PATH,
Andrew Hayworthe63ac872015-07-31 16:14:16 +0000120 LOG_FMT_HTTP_QUERY,
Andrew Hayworth0ebc55f2015-04-27 21:37:03 +0000121 LOG_FMT_HTTP_VERSION,
William Lallemand5f232402012-04-05 18:02:55 +0200122 LOG_FMT_HOSTNAME,
William Lallemanda73203e2012-03-12 12:48:57 +0100123 LOG_FMT_UNIQUEID,
Willy Tarreauffc3fcd2012-10-12 20:17:54 +0200124 LOG_FMT_SSL_CIPHER,
125 LOG_FMT_SSL_VERSION,
William Lallemand723b73a2012-02-08 16:37:49 +0100126};
127
Willy Tarreau8a3f52f2012-12-20 21:23:42 +0100128/* enum for parse_logformat_string */
William Lallemand723b73a2012-02-08 16:37:49 +0100129enum {
Willy Tarreau8a3f52f2012-12-20 21:23:42 +0100130 LF_INIT = 0, // before first character
131 LF_TEXT, // normal text
132 LF_SEPARATOR, // a single separator
133 LF_VAR, // variable name, after '%' or '%{..}'
134 LF_STARTVAR, // % in text
135 LF_STARG, // after '%{' and berore '}'
136 LF_EDARG, // '}' after '%{'
Willy Tarreauc8368452012-12-21 00:09:23 +0100137 LF_STEXPR, // after '%[' or '%{..}[' and berore ']'
138 LF_EDEXPR, // ']' after '%['
Willy Tarreau8a3f52f2012-12-20 21:23:42 +0100139 LF_END, // \0 found
William Lallemand723b73a2012-02-08 16:37:49 +0100140};
141
142
143struct logformat_node {
144 struct list list;
Willy Tarreauc8368452012-12-21 00:09:23 +0100145 int type; // LOG_FMT_*
146 int options; // LOG_OPT_*
147 char *arg; // text for LOG_FMT_TEXT, arg for others
148 void *expr; // for use with LOG_FMT_EXPR
William Lallemand723b73a2012-02-08 16:37:49 +0100149};
150
William Lallemand5f232402012-04-05 18:02:55 +0200151#define LOG_OPT_HEXA 0x00000001
William Lallemand723b73a2012-02-08 16:37:49 +0100152#define LOG_OPT_MANDATORY 0x00000002
153#define LOG_OPT_QUOTE 0x00000004
Willy Tarreauc8368452012-12-21 00:09:23 +0100154#define LOG_OPT_REQ_CAP 0x00000008
155#define LOG_OPT_RES_CAP 0x00000010
Thierry FOURNIERd048d8b2014-03-13 16:46:18 +0100156#define LOG_OPT_HTTP 0x00000020
Dragan Dosen835b9212016-02-12 13:23:03 +0100157#define LOG_OPT_ESC 0x00000040
William Lallemand723b73a2012-02-08 16:37:49 +0100158
Willy Tarreaubaaee002006-06-26 02:48:02 +0200159
Willy Tarreaud79a3b22012-12-28 09:40:16 +0100160/* Fields that need to be extracted from the incoming connection or request for
161 * logging or for sending specific header information. They're set in px->to_log
162 * and appear as flags in session->logs.logwait, which are removed once the
163 * required information has been collected.
164 */
165#define LW_INIT 1 /* anything */
Willy Tarreaubaaee002006-06-26 02:48:02 +0200166#define LW_CLIP 2 /* CLient IP */
167#define LW_SVIP 4 /* SerVer IP */
168#define LW_SVID 8 /* server ID */
169#define LW_REQ 16 /* http REQuest */
170#define LW_RESP 32 /* http RESPonse */
Willy Tarreaubaaee002006-06-26 02:48:02 +0200171#define LW_BYTES 256 /* bytes read from server */
172#define LW_COOKIE 512 /* captured cookie */
173#define LW_REQHDR 1024 /* request header(s) */
174#define LW_RSPHDR 2048 /* response header(s) */
William Lallemand5e19a282012-04-02 16:22:10 +0200175#define LW_BCKIP 4096 /* backend IP */
176#define LW_FRTIP 8192 /* frontend IP */
Willy Tarreau93dbc2b2012-10-12 18:01:49 +0200177#define LW_XPRT 16384 /* transport layer information (eg: SSL) */
Willy Tarreaubaaee002006-06-26 02:48:02 +0200178
Frédéric Lécailled95ea282019-04-24 16:14:33 +0200179/* Range of indexes for log sampling. */
180struct smp_log_range {
181 unsigned int low; /* Low limit of the indexes of this range. */
182 unsigned int high; /* High limit of the indexes of this range. */
183 size_t sz; /* The size of this range, or number of indexes in
184 * this range.
185 */
186 unsigned int curr_idx; /* The current index used to sample this range of
187 *indexes.
188 */
189};
190
191/* Log sampling information. */
192struct smp_info {
193 struct smp_log_range *smp_rgs; /* Array of ranges for log sampling. */
194 size_t smp_rgs_sz; /* The size of <smp_rgs> array. */
195 size_t smp_sz; /* The total number of logs to be sampled. */
196 unsigned int curr_rg; /* The current range to be sampled. */
197 unsigned int curr_idx; /* A counter to store the current index of the log
198 * already sampled.
199 */
200};
201
Robert Tsai81ae1952007-12-05 10:47:29 +0100202struct logsrv {
William Lallemand0f99e342011-10-12 17:50:54 +0200203 struct list list;
David du Colombier11bcb6c2011-03-24 12:23:00 +0100204 struct sockaddr_storage addr;
Frédéric Lécailled95ea282019-04-24 16:14:33 +0200205 struct smp_info lb;
Willy Tarreauf3dc30f2019-08-30 14:18:44 +0200206 enum log_tgt type;
Dragan Dosen1322d092015-09-22 16:05:32 +0200207 int format;
William Lallemand0f99e342011-10-12 17:50:54 +0200208 int facility;
209 int level;
210 int minlvl;
Willy Tarreau18324f52014-06-27 18:10:07 +0200211 int maxlen;
Christopher Faulet28ac0992018-03-26 16:09:19 +0200212 struct logsrv *ref;
Frédéric Lécailled803e472019-04-25 07:42:09 +0200213 __decl_hathreads(HA_SPINLOCK_T lock);
Robert Tsai81ae1952007-12-05 10:47:29 +0100214};
215
Willy Tarreaubaaee002006-06-26 02:48:02 +0200216#endif /* _TYPES_LOG_H */
217
218/*
219 * Local variables:
220 * c-indent-level: 8
221 * c-basic-offset: 8
222 * End:
223 */