blob: 0e41ecab9e4e072f91f6a6b1e68e92c9782edb73 [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;
36
William Lallemand723b73a2012-02-08 16:37:49 +010037extern char *log_format;
William Lallemandbddd4fd2012-02-27 11:23:10 +010038extern char default_tcp_log_format[];
William Lallemand723b73a2012-02-08 16:37:49 +010039extern char default_http_log_format[];
40extern char clf_http_log_format[];
41
William Lallemandbddd4fd2012-02-27 11:23:10 +010042
William Lallemand1d705562012-03-12 12:46:41 +010043int build_logline(struct session *s, char *dst, size_t maxsize, struct list *list_format);
44
William Lallemandbddd4fd2012-02-27 11:23:10 +010045/*
46 * send a log for the session when we have enough info about it.
47 * Will not log if the frontend has no log defined.
48 */
49void sess_log(struct session *s);
50
William Lallemand723b73a2012-02-08 16:37:49 +010051/*
52 * Parse args in a logformat_var
53 */
54int parse_logformat_var_args(char *args, struct logformat_node *node);
55
56/*
57 * Parse a variable '%varname' or '%{args}varname' in logformat
58 *
59 */
William Lallemand1d705562012-03-12 12:46:41 +010060int parse_logformat_var(char *str, size_t len, struct proxy *curproxy, struct list *list_format, int *defoptions);
William Lallemand723b73a2012-02-08 16:37:49 +010061
62/*
63 * add to the logformat linked list
64 */
William Lallemand1d705562012-03-12 12:46:41 +010065void add_to_logformat_list(char *start, char *end, int type, struct list *list_format);
William Lallemand723b73a2012-02-08 16:37:49 +010066
67/*
68 * Parse the log_format string and fill a linked list.
69 * Variable name are preceded by % and composed by characters [a-zA-Z0-9]* : %varname
70 * You can set arguments using { } : %{many arguments}varname
71 */
William Lallemand1d705562012-03-12 12:46:41 +010072void parse_logformat_string(char *str, struct proxy *curproxy, struct list *list_format, int capabilities);
Willy Tarreaubaaee002006-06-26 02:48:02 +020073/*
74 * Displays the message on stderr with the date and pid. Overrides the quiet
75 * mode during startup.
76 */
Willy Tarreau40d25162009-04-03 12:01:47 +020077void Alert(const char *fmt, ...)
78 __attribute__ ((format(printf, 1, 2)));
Willy Tarreaubaaee002006-06-26 02:48:02 +020079
80/*
81 * Displays the message on stderr with the date and pid.
82 */
Willy Tarreau40d25162009-04-03 12:01:47 +020083void Warning(const char *fmt, ...)
84 __attribute__ ((format(printf, 1, 2)));
Willy Tarreaubaaee002006-06-26 02:48:02 +020085
86/*
87 * Displays the message on <out> only if quiet mode is not set.
88 */
Willy Tarreau40d25162009-04-03 12:01:47 +020089void qfprintf(FILE *out, const char *fmt, ...)
90 __attribute__ ((format(printf, 2, 3)));
Willy Tarreaubaaee002006-06-26 02:48:02 +020091
William Lallemand2a4a44f2012-02-06 16:00:33 +010092/*
93 * This function adds a header to the message and sends the syslog message
94 * using a printf format string
95 */
96void send_log(struct proxy *p, int level, const char *format, ...)
97 __attribute__ ((format(printf, 3, 4)));
98
Willy Tarreaubaaee002006-06-26 02:48:02 +020099/*
100 * This function sends a syslog message to both log servers of a proxy,
101 * or to global log servers if the proxy is NULL.
102 * It also tries not to waste too much time computing the message header.
103 * It doesn't care about errors nor does it report them.
104 */
Willy Tarreaubaaee002006-06-26 02:48:02 +0200105
William Lallemand2a4a44f2012-02-06 16:00:33 +0100106void __send_log(struct proxy *p, int level, char *message, size_t size);
Willy Tarreaubaaee002006-06-26 02:48:02 +0200107
108/*
109 * returns log level for <lev> or -1 if not found.
110 */
111int get_log_level(const char *lev);
112
113/*
114 * returns log facility for <fac> or -1 if not found.
115 */
116int get_log_facility(const char *fac);
117
William Lallemanda1cc3812012-02-08 16:38:44 +0100118/*
119 * Write a string in the log string
William Lallemand5f232402012-04-05 18:02:55 +0200120 * Take cares of quote options
William Lallemanda1cc3812012-02-08 16:38:44 +0100121 *
122 * Return the adress of the \0 character, or NULL on error
123 */
William Lallemand5f232402012-04-05 18:02:55 +0200124char *lf_text(char *dst, char *src, size_t size, struct logformat_node *node);
125
126/*
127 * Write a IP adress to the log string
128 * +X option write in hexadecimal notation, most signifant byte on the left
129 */
130char *lf_ip(char *dst, struct sockaddr *sockaddr, size_t size, struct logformat_node *node);
131
132/*
133 * Write a port to the log
134 * +X option write in hexadecimal notation, most signifant byte on the left
135 */
136char *lf_port(char *dst, struct sockaddr *sockaddr, size_t size, struct logformat_node *node);
137
William Lallemanda1cc3812012-02-08 16:38:44 +0100138
Willy Tarreaubaaee002006-06-26 02:48:02 +0200139#endif /* _PROTO_LOG_H */
140
141/*
142 * Local variables:
143 * c-indent-level: 8
144 * c-basic-offset: 8
145 * End:
146 */