blob: 72ff744fbbaab454cf273924ed97e78486f3b2dc [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>
Willy Tarreaubaaee002006-06-26 02:48:02 +020031#include <types/log.h>
32#include <types/proxy.h>
Willy Tarreau87b09662015-04-03 00:22:06 +020033#include <types/stream.h>
Willy Tarreaubaaee002006-06-26 02:48:02 +020034
Willy Tarreau332f8bf2007-05-13 21:36:56 +020035extern struct pool_head *pool2_requri;
William Lallemanda73203e2012-03-12 12:48:57 +010036extern struct pool_head *pool2_uniqueid;
Willy Tarreau332f8bf2007-05-13 21:36:56 +020037
William Lallemand723b73a2012-02-08 16:37:49 +010038extern char *log_format;
William Lallemandbddd4fd2012-02-27 11:23:10 +010039extern char default_tcp_log_format[];
William Lallemand723b73a2012-02-08 16:37:49 +010040extern char default_http_log_format[];
41extern char clf_http_log_format[];
Dragan Dosen1322d092015-09-22 16:05:32 +020042
Dragan Dosen0b85ece2015-09-25 19:17:44 +020043extern char default_rfc5424_sd_log_format[];
44
Dragan Dosen59cee972015-09-19 22:09:02 +020045extern char *logheader;
Dragan Dosen1322d092015-09-22 16:05:32 +020046extern char *logheader_rfc5424;
Willy Tarreau18324f52014-06-27 18:10:07 +020047extern char *logline;
Dragan Dosen0b85ece2015-09-25 19:17:44 +020048extern char *logline_rfc5424;
William Lallemand723b73a2012-02-08 16:37:49 +010049
William Lallemandbddd4fd2012-02-27 11:23:10 +010050
Dragan Dosen835b9212016-02-12 13:23:03 +010051/*
52 * Initializes some log data.
53 */
54void init_log();
55
Christopher Faulet0132d062017-07-26 15:33:35 +020056
57/* Initialize/Deinitialize log buffers used for syslog messages */
58int init_log_buffers();
59void deinit_log_buffers();
60
Dragan Dosen835b9212016-02-12 13:23:03 +010061/*
62 * Builds a log line.
63 */
Willy Tarreau87b09662015-04-03 00:22:06 +020064int build_logline(struct stream *s, char *dst, size_t maxsize, struct list *list_format);
William Lallemand1d705562012-03-12 12:46:41 +010065
William Lallemandbddd4fd2012-02-27 11:23:10 +010066/*
Willy Tarreau87b09662015-04-03 00:22:06 +020067 * send a log for the stream when we have enough info about it.
William Lallemandbddd4fd2012-02-27 11:23:10 +010068 * Will not log if the frontend has no log defined.
69 */
Willy Tarreau87b09662015-04-03 00:22:06 +020070void strm_log(struct stream *s);
William Lallemandbddd4fd2012-02-27 11:23:10 +010071
William Lallemand723b73a2012-02-08 16:37:49 +010072/*
William Lallemand723b73a2012-02-08 16:37:49 +010073 * add to the logformat linked list
74 */
Thierry FOURNIER / OZON.IO8a4e4422016-11-23 00:41:28 +010075int add_to_logformat_list(char *start, char *end, int type, struct list *list_format, char **err);
William Lallemand723b73a2012-02-08 16:37:49 +010076
77/*
78 * Parse the log_format string and fill a linked list.
79 * Variable name are preceded by % and composed by characters [a-zA-Z0-9]* : %varname
80 * You can set arguments using { } : %{many arguments}varname
81 */
Thierry FOURNIER / OZON.IO8a4e4422016-11-23 00:41:28 +010082int parse_logformat_string(const char *str, struct proxy *curproxy, struct list *list_format, int options, int cap, char **err);
Willy Tarreaubaaee002006-06-26 02:48:02 +020083/*
84 * Displays the message on stderr with the date and pid. Overrides the quiet
85 * mode during startup.
86 */
Willy Tarreau40d25162009-04-03 12:01:47 +020087void Alert(const char *fmt, ...)
88 __attribute__ ((format(printf, 1, 2)));
Willy Tarreaubaaee002006-06-26 02:48:02 +020089
90/*
91 * Displays the message on stderr with the date and pid.
92 */
Willy Tarreau40d25162009-04-03 12:01:47 +020093void Warning(const char *fmt, ...)
94 __attribute__ ((format(printf, 1, 2)));
Willy Tarreaubaaee002006-06-26 02:48:02 +020095
96/*
97 * Displays the message on <out> only if quiet mode is not set.
98 */
Willy Tarreau40d25162009-04-03 12:01:47 +020099void qfprintf(FILE *out, const char *fmt, ...)
100 __attribute__ ((format(printf, 2, 3)));
Willy Tarreaubaaee002006-06-26 02:48:02 +0200101
William Lallemand2a4a44f2012-02-06 16:00:33 +0100102/*
103 * This function adds a header to the message and sends the syslog message
104 * using a printf format string
105 */
106void send_log(struct proxy *p, int level, const char *format, ...)
107 __attribute__ ((format(printf, 3, 4)));
108
Willy Tarreaubaaee002006-06-26 02:48:02 +0200109/*
110 * This function sends a syslog message to both log servers of a proxy,
111 * or to global log servers if the proxy is NULL.
112 * It also tries not to waste too much time computing the message header.
113 * It doesn't care about errors nor does it report them.
114 */
Willy Tarreaubaaee002006-06-26 02:48:02 +0200115
Dragan Dosen0b85ece2015-09-25 19:17:44 +0200116void __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 +0200117
118/*
Dragan Dosen1322d092015-09-22 16:05:32 +0200119 * returns log format for <fmt> or -1 if not found.
120 */
121int get_log_format(const char *fmt);
122
123/*
Willy Tarreaubaaee002006-06-26 02:48:02 +0200124 * returns log level for <lev> or -1 if not found.
125 */
126int get_log_level(const char *lev);
127
128/*
129 * returns log facility for <fac> or -1 if not found.
130 */
131int get_log_facility(const char *fac);
132
William Lallemanda1cc3812012-02-08 16:38:44 +0100133/*
134 * Write a string in the log string
William Lallemand5f232402012-04-05 18:02:55 +0200135 * Take cares of quote options
William Lallemanda1cc3812012-02-08 16:38:44 +0100136 *
137 * Return the adress of the \0 character, or NULL on error
138 */
Willy Tarreau2b0108a2012-12-21 19:23:44 +0100139char *lf_text_len(char *dst, const char *src, size_t len, size_t size, struct logformat_node *node);
William Lallemand5f232402012-04-05 18:02:55 +0200140
141/*
142 * Write a IP adress to the log string
143 * +X option write in hexadecimal notation, most signifant byte on the left
144 */
145char *lf_ip(char *dst, struct sockaddr *sockaddr, size_t size, struct logformat_node *node);
146
147/*
148 * Write a port to the log
149 * +X option write in hexadecimal notation, most signifant byte on the left
150 */
151char *lf_port(char *dst, struct sockaddr *sockaddr, size_t size, struct logformat_node *node);
152
William Lallemanda1cc3812012-02-08 16:38:44 +0100153
Willy Tarreaubaaee002006-06-26 02:48:02 +0200154#endif /* _PROTO_LOG_H */
155
156/*
157 * Local variables:
158 * c-indent-level: 8
159 * c-basic-offset: 8
160 * End:
161 */