blob: 86b41856252e8fb24761ba6f5b6075ae92f6ab0b [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>
33#include <types/session.h>
34
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[];
42
William Lallemandbddd4fd2012-02-27 11:23:10 +010043
William Lallemand1d705562012-03-12 12:46:41 +010044int build_logline(struct session *s, char *dst, size_t maxsize, struct list *list_format);
45
William Lallemandbddd4fd2012-02-27 11:23:10 +010046/*
47 * send a log for the session when we have enough info about it.
48 * Will not log if the frontend has no log defined.
49 */
50void sess_log(struct session *s);
51
William Lallemand723b73a2012-02-08 16:37:49 +010052/*
53 * Parse args in a logformat_var
54 */
55int parse_logformat_var_args(char *args, struct logformat_node *node);
56
57/*
Willy Tarreau8a3f52f2012-12-20 21:23:42 +010058 * Parse a variable '%varname' or '%{args}varname' in log-format
William Lallemand723b73a2012-02-08 16:37:49 +010059 *
60 */
Willy Tarreau8a3f52f2012-12-20 21:23:42 +010061int parse_logformat_var(char *arg, int arg_len, char *var, int var_len, struct proxy *curproxy, struct list *list_format, int *defoptions);
William Lallemand723b73a2012-02-08 16:37:49 +010062
63/*
64 * add to the logformat linked list
65 */
William Lallemand1d705562012-03-12 12:46:41 +010066void add_to_logformat_list(char *start, char *end, int type, struct list *list_format);
William Lallemand723b73a2012-02-08 16:37:49 +010067
68/*
69 * Parse the log_format string and fill a linked list.
70 * Variable name are preceded by % and composed by characters [a-zA-Z0-9]* : %varname
71 * You can set arguments using { } : %{many arguments}varname
72 */
Willy Tarreau434c57c2013-01-08 01:10:24 +010073void parse_logformat_string(const char *str, struct proxy *curproxy, struct list *list_format, int options, int cap);
Willy Tarreaubaaee002006-06-26 02:48:02 +020074/*
75 * Displays the message on stderr with the date and pid. Overrides the quiet
76 * mode during startup.
77 */
Willy Tarreau40d25162009-04-03 12:01:47 +020078void Alert(const char *fmt, ...)
79 __attribute__ ((format(printf, 1, 2)));
Willy Tarreaubaaee002006-06-26 02:48:02 +020080
81/*
82 * Displays the message on stderr with the date and pid.
83 */
Willy Tarreau40d25162009-04-03 12:01:47 +020084void Warning(const char *fmt, ...)
85 __attribute__ ((format(printf, 1, 2)));
Willy Tarreaubaaee002006-06-26 02:48:02 +020086
87/*
88 * Displays the message on <out> only if quiet mode is not set.
89 */
Willy Tarreau40d25162009-04-03 12:01:47 +020090void qfprintf(FILE *out, const char *fmt, ...)
91 __attribute__ ((format(printf, 2, 3)));
Willy Tarreaubaaee002006-06-26 02:48:02 +020092
William Lallemand2a4a44f2012-02-06 16:00:33 +010093/*
94 * This function adds a header to the message and sends the syslog message
95 * using a printf format string
96 */
97void send_log(struct proxy *p, int level, const char *format, ...)
98 __attribute__ ((format(printf, 3, 4)));
99
Willy Tarreaubaaee002006-06-26 02:48:02 +0200100/*
101 * This function sends a syslog message to both log servers of a proxy,
102 * or to global log servers if the proxy is NULL.
103 * It also tries not to waste too much time computing the message header.
104 * It doesn't care about errors nor does it report them.
105 */
Willy Tarreaubaaee002006-06-26 02:48:02 +0200106
William Lallemand2a4a44f2012-02-06 16:00:33 +0100107void __send_log(struct proxy *p, int level, char *message, size_t size);
Willy Tarreaubaaee002006-06-26 02:48:02 +0200108
109/*
110 * returns log level for <lev> or -1 if not found.
111 */
112int get_log_level(const char *lev);
113
114/*
115 * returns log facility for <fac> or -1 if not found.
116 */
117int get_log_facility(const char *fac);
118
William Lallemanda1cc3812012-02-08 16:38:44 +0100119/*
120 * Write a string in the log string
William Lallemand5f232402012-04-05 18:02:55 +0200121 * Take cares of quote options
William Lallemanda1cc3812012-02-08 16:38:44 +0100122 *
123 * Return the adress of the \0 character, or NULL on error
124 */
Willy Tarreau2b0108a2012-12-21 19:23:44 +0100125char *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 +0200126
127/*
128 * Write a IP adress to the log string
129 * +X option write in hexadecimal notation, most signifant byte on the left
130 */
131char *lf_ip(char *dst, struct sockaddr *sockaddr, size_t size, struct logformat_node *node);
132
133/*
134 * Write a port to the log
135 * +X option write in hexadecimal notation, most signifant byte on the left
136 */
137char *lf_port(char *dst, struct sockaddr *sockaddr, size_t size, struct logformat_node *node);
138
William Lallemanda1cc3812012-02-08 16:38:44 +0100139
Willy Tarreaubaaee002006-06-26 02:48:02 +0200140#endif /* _PROTO_LOG_H */
141
142/*
143 * Local variables:
144 * c-indent-level: 8
145 * c-basic-offset: 8
146 * End:
147 */