blob: 7b056c5feff91ca957da96111a702a8b566bb714 [file] [log] [blame]
Willy Tarreaubaaee002006-06-26 02:48:02 +02001/*
2 include/proto/log.h
3 This file contains definitions of log-related functions, structures,
4 and macros.
5
Willy Tarreauec6c5df2008-07-15 00:22:45 +02006 Copyright (C) 2000-2008 Willy Tarreau - w@1wt.eu
Willy Tarreaubaaee002006-06-26 02:48:02 +02007
8 This library is free software; you can redistribute it and/or
9 modify it under the terms of the GNU Lesser General Public
10 License as published by the Free Software Foundation, version 2.1
11 exclusively.
12
13 This library is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 Lesser General Public License for more details.
17
18 You should have received a copy of the GNU Lesser General Public
19 License along with this library; if not, write to the Free Software
20 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
21*/
22
23#ifndef _PROTO_LOG_H
24#define _PROTO_LOG_H
25
26#include <stdio.h>
27#include <syslog.h>
28
Willy Tarreaue3ba5f02006-06-29 18:54:54 +020029#include <common/config.h>
Willy Tarreau332f8bf2007-05-13 21:36:56 +020030#include <common/memory.h>
Christopher Fauletf8188c62017-06-02 16:20:16 +020031#include <common/hathreads.h>
32
Willy Tarreaubaaee002006-06-26 02:48:02 +020033#include <types/log.h>
34#include <types/proxy.h>
Willy Tarreau87b09662015-04-03 00:22:06 +020035#include <types/stream.h>
Willy Tarreaubaaee002006-06-26 02:48:02 +020036
Willy Tarreau43c538e2018-09-05 14:58:15 +020037#include <proto/stream.h>
38
Willy Tarreaubafbe012017-11-24 17:34:44 +010039extern struct pool_head *pool_head_requri;
40extern struct pool_head *pool_head_uniqueid;
Willy Tarreau332f8bf2007-05-13 21:36:56 +020041
William Lallemand723b73a2012-02-08 16:37:49 +010042extern char *log_format;
William Lallemandbddd4fd2012-02-27 11:23:10 +010043extern char default_tcp_log_format[];
William Lallemand723b73a2012-02-08 16:37:49 +010044extern char default_http_log_format[];
45extern char clf_http_log_format[];
Dragan Dosen1322d092015-09-22 16:05:32 +020046
Dragan Dosen0b85ece2015-09-25 19:17:44 +020047extern char default_rfc5424_sd_log_format[];
48
Willy Tarreau13ef7732018-11-12 07:25:28 +010049extern unsigned int dropped_logs;
50
Christopher Fauletf8188c62017-06-02 16:20:16 +020051extern THREAD_LOCAL char *logheader;
52extern THREAD_LOCAL char *logheader_rfc5424;
53extern THREAD_LOCAL char *logline;
54extern THREAD_LOCAL char *logline_rfc5424;
William Lallemand723b73a2012-02-08 16:37:49 +010055
William Lallemandbddd4fd2012-02-27 11:23:10 +010056
Frédéric Lécailled803e472019-04-25 07:42:09 +020057/*
58 * Test if <idx> index numbered from 0 is in <rg> range with low and high
59 * limits of indexes numbered from 1.
60 */
61static inline int in_smp_log_range(struct smp_log_range *rg, unsigned int idx)
62{
63 if (idx + 1 <= rg->high && idx + 1 >= rg->low)
64 return 1;
65 return 0;
66}
67
Christopher Faulet0132d062017-07-26 15:33:35 +020068/* Initialize/Deinitialize log buffers used for syslog messages */
69int init_log_buffers();
70void deinit_log_buffers();
71
Dragan Dosen835b9212016-02-12 13:23:03 +010072/*
73 * Builds a log line.
74 */
Willy Tarreau43c538e2018-09-05 14:58:15 +020075int sess_build_logline(struct session *sess, struct stream *s, char *dst, size_t maxsize, struct list *list_format);
76
77static inline int build_logline(struct stream *s, char *dst, size_t maxsize, struct list *list_format)
78{
79 return sess_build_logline(strm_sess(s), s, dst, maxsize, list_format);
80}
81
William Lallemand1d705562012-03-12 12:46:41 +010082
William Lallemandbddd4fd2012-02-27 11:23:10 +010083/*
Willy Tarreau87b09662015-04-03 00:22:06 +020084 * send a log for the stream when we have enough info about it.
William Lallemandbddd4fd2012-02-27 11:23:10 +010085 * Will not log if the frontend has no log defined.
86 */
Willy Tarreau87b09662015-04-03 00:22:06 +020087void strm_log(struct stream *s);
Willy Tarreau53839352018-09-05 19:51:10 +020088void sess_log(struct session *sess);
William Lallemandbddd4fd2012-02-27 11:23:10 +010089
William Lallemand723b73a2012-02-08 16:37:49 +010090/*
William Lallemand723b73a2012-02-08 16:37:49 +010091 * add to the logformat linked list
92 */
Thierry FOURNIER / OZON.IO8a4e4422016-11-23 00:41:28 +010093int add_to_logformat_list(char *start, char *end, int type, struct list *list_format, char **err);
William Lallemand723b73a2012-02-08 16:37:49 +010094
95/*
96 * Parse the log_format string and fill a linked list.
97 * Variable name are preceded by % and composed by characters [a-zA-Z0-9]* : %varname
98 * You can set arguments using { } : %{many arguments}varname
99 */
Thierry FOURNIER / OZON.IO8a4e4422016-11-23 00:41:28 +0100100int parse_logformat_string(const char *str, struct proxy *curproxy, struct list *list_format, int options, int cap, char **err);
Christopher Faulet4b0b79d2018-03-26 15:54:32 +0200101
102/* Parse "log" keyword and update the linked list. */
103int parse_logsrv(char **args, struct list *logsrvs, int do_del, char **err);
104
Willy Tarreaubaaee002006-06-26 02:48:02 +0200105/*
106 * Displays the message on stderr with the date and pid. Overrides the quiet
107 * mode during startup.
108 */
Christopher Faulet767a84b2017-11-24 16:50:31 +0100109void ha_alert(const char *fmt, ...)
Willy Tarreau40d25162009-04-03 12:01:47 +0200110 __attribute__ ((format(printf, 1, 2)));
Willy Tarreaubaaee002006-06-26 02:48:02 +0200111
112/*
113 * Displays the message on stderr with the date and pid.
114 */
Christopher Faulet767a84b2017-11-24 16:50:31 +0100115void ha_warning(const char *fmt, ...)
Willy Tarreau40d25162009-04-03 12:01:47 +0200116 __attribute__ ((format(printf, 1, 2)));
Willy Tarreaubaaee002006-06-26 02:48:02 +0200117
118/*
William Lallemand9c56a222018-11-21 18:04:52 +0100119 * Displays the message on stderr with the date and pid.
120 */
121void ha_notice(const char *fmt, ...)
122 __attribute__ ((format(printf, 1, 2)));
123
124/*
Willy Tarreaubaaee002006-06-26 02:48:02 +0200125 * Displays the message on <out> only if quiet mode is not set.
126 */
Willy Tarreau40d25162009-04-03 12:01:47 +0200127void qfprintf(FILE *out, const char *fmt, ...)
128 __attribute__ ((format(printf, 2, 3)));
Willy Tarreaubaaee002006-06-26 02:48:02 +0200129
William Lallemand2a4a44f2012-02-06 16:00:33 +0100130/*
131 * This function adds a header to the message and sends the syslog message
132 * using a printf format string
133 */
134void send_log(struct proxy *p, int level, const char *format, ...)
135 __attribute__ ((format(printf, 3, 4)));
136
Willy Tarreaubaaee002006-06-26 02:48:02 +0200137/*
138 * This function sends a syslog message to both log servers of a proxy,
139 * or to global log servers if the proxy is NULL.
140 * It also tries not to waste too much time computing the message header.
141 * It doesn't care about errors nor does it report them.
142 */
Willy Tarreaubaaee002006-06-26 02:48:02 +0200143
Dragan Dosen0b85ece2015-09-25 19:17:44 +0200144void __send_log(struct proxy *p, int level, char *message, size_t size, char *sd, size_t sd_size);
Willy Tarreaubaaee002006-06-26 02:48:02 +0200145
146/*
Dragan Dosen1322d092015-09-22 16:05:32 +0200147 * returns log format for <fmt> or -1 if not found.
148 */
149int get_log_format(const char *fmt);
150
151/*
Willy Tarreaubaaee002006-06-26 02:48:02 +0200152 * returns log level for <lev> or -1 if not found.
153 */
154int get_log_level(const char *lev);
155
156/*
157 * returns log facility for <fac> or -1 if not found.
158 */
159int get_log_facility(const char *fac);
160
William Lallemanda1cc3812012-02-08 16:38:44 +0100161/*
162 * Write a string in the log string
William Lallemand5f232402012-04-05 18:02:55 +0200163 * Take cares of quote options
William Lallemanda1cc3812012-02-08 16:38:44 +0100164 *
Joseph Herlant85b40592018-11-15 12:10:04 -0800165 * Return the address of the \0 character, or NULL on error
William Lallemanda1cc3812012-02-08 16:38:44 +0100166 */
Olivier Houchard54620522018-09-06 18:14:09 +0200167char *lf_text_len(char *dst, const char *src, size_t len, size_t size, const struct logformat_node *node);
William Lallemand5f232402012-04-05 18:02:55 +0200168
169/*
Joseph Herlant85b40592018-11-15 12:10:04 -0800170 * Write a IP address to the log string
William Lallemand5f232402012-04-05 18:02:55 +0200171 * +X option write in hexadecimal notation, most signifant byte on the left
172 */
Willy Tarreau26ffa852018-09-05 15:23:10 +0200173char *lf_ip(char *dst, const struct sockaddr *sockaddr, size_t size, const struct logformat_node *node);
William Lallemand5f232402012-04-05 18:02:55 +0200174
175/*
176 * Write a port to the log
177 * +X option write in hexadecimal notation, most signifant byte on the left
178 */
Willy Tarreau26ffa852018-09-05 15:23:10 +0200179char *lf_port(char *dst, const struct sockaddr *sockaddr, size_t size, const struct logformat_node *node);
William Lallemand5f232402012-04-05 18:02:55 +0200180
William Lallemanda1cc3812012-02-08 16:38:44 +0100181
Willy Tarreaubaaee002006-06-26 02:48:02 +0200182#endif /* _PROTO_LOG_H */
183
184/*
185 * Local variables:
186 * c-indent-level: 8
187 * c-basic-offset: 8
188 * End:
189 */