blob: d36d879881ef1e49fdeb49e2231092c77002388f [file] [log] [blame]
Willy Tarreaubaaee002006-06-26 02:48:02 +02001/*
2 * General logging functions.
3 *
Willy Tarreaub7f694f2008-06-22 17:18:02 +02004 * Copyright 2000-2008 Willy Tarreau <w@1wt.eu>
Willy Tarreaubaaee002006-06-26 02:48:02 +02005 *
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License
8 * as published by the Free Software Foundation; either version
9 * 2 of the License, or (at your option) any later version.
10 *
11 */
12
Willy Tarreau8a3f52f2012-12-20 21:23:42 +010013#include <ctype.h>
Willy Tarreauc8f24f82007-11-30 18:38:35 +010014#include <fcntl.h>
Willy Tarreaubaaee002006-06-26 02:48:02 +020015#include <stdarg.h>
16#include <stdio.h>
17#include <stdlib.h>
18#include <string.h>
19#include <syslog.h>
20#include <time.h>
21#include <unistd.h>
Robert Tsai81ae1952007-12-05 10:47:29 +010022#include <errno.h>
Willy Tarreaubaaee002006-06-26 02:48:02 +020023
24#include <sys/time.h>
25
Willy Tarreaue3ba5f02006-06-29 18:54:54 +020026#include <common/config.h>
Willy Tarreaud6d06902009-08-19 11:22:33 +020027#include <common/compat.h>
Willy Tarreau2dd0d472006-06-29 17:53:05 +020028#include <common/standard.h>
Willy Tarreaufb278672006-10-15 15:38:50 +020029#include <common/time.h>
Willy Tarreaubaaee002006-06-26 02:48:02 +020030
Willy Tarreaubaaee002006-06-26 02:48:02 +020031#include <types/global.h>
William Lallemand723b73a2012-02-08 16:37:49 +010032#include <types/log.h>
Willy Tarreauec6c5df2008-07-15 00:22:45 +020033
William Lallemand5f232402012-04-05 18:02:55 +020034#include <proto/frontend.h>
Willy Tarreauec6c5df2008-07-15 00:22:45 +020035#include <proto/log.h>
Willy Tarreauc8368452012-12-21 00:09:23 +010036#include <proto/sample.h>
Willy Tarreau827aee92011-03-10 16:55:02 +010037#include <proto/stream_interface.h>
Willy Tarreau773d65f2012-10-12 14:56:11 +020038#ifdef USE_OPENSSL
39#include <proto/ssl_sock.h>
40#endif
Willy Tarreaubaaee002006-06-26 02:48:02 +020041
Willy Tarreaubaaee002006-06-26 02:48:02 +020042const char *log_facilities[NB_LOG_FACILITIES] = {
43 "kern", "user", "mail", "daemon",
44 "auth", "syslog", "lpr", "news",
45 "uucp", "cron", "auth2", "ftp",
46 "ntp", "audit", "alert", "cron2",
47 "local0", "local1", "local2", "local3",
48 "local4", "local5", "local6", "local7"
49};
50
51
52const char *log_levels[NB_LOG_LEVELS] = {
53 "emerg", "alert", "crit", "err",
54 "warning", "notice", "info", "debug"
55};
56
Justin Karnegeseb2c24a2012-05-24 15:28:52 -070057const char sess_term_cond[16] = "-cCsSPRIDKUIIIII"; /* normal, CliTo, CliErr, SrvTo, SrvErr, PxErr, Resource, Internal, Down, Killed, Up, -- */
Willy Tarreaub8750a82006-09-03 09:56:00 +020058const char sess_fin_state[8] = "-RCHDLQT"; /* cliRequest, srvConnect, srvHeader, Data, Last, Queue, Tarpit */
Willy Tarreaubaaee002006-06-26 02:48:02 +020059
William Lallemand723b73a2012-02-08 16:37:49 +010060
61/* log_format */
62struct logformat_type {
63 char *name;
64 int type;
William Lallemandbddd4fd2012-02-27 11:23:10 +010065 int mode;
William Lallemand5e19a282012-04-02 16:22:10 +020066 int lw; /* logwait bitsfield */
William Lallemandb7ff6a32012-03-02 14:35:21 +010067 int (*config_callback)(struct logformat_node *node, struct proxy *curproxy);
Willy Tarreau2beef582012-12-20 17:22:52 +010068 const char *replace_by; /* new option to use instead of old one */
William Lallemand723b73a2012-02-08 16:37:49 +010069};
70
William Lallemandb7ff6a32012-03-02 14:35:21 +010071int prepare_addrsource(struct logformat_node *node, struct proxy *curproxy);
72
William Lallemand723b73a2012-02-08 16:37:49 +010073/* log_format variable names */
74static const struct logformat_type logformat_keywords[] = {
William Lallemand5e19a282012-04-02 16:22:10 +020075 { "o", LOG_FMT_GLOBAL, PR_MODE_TCP, 0, NULL }, /* global option */
Willy Tarreau2beef582012-12-20 17:22:52 +010076
77 /* please keep these lines sorted ! */
78 { "B", LOG_FMT_BYTES, PR_MODE_TCP, LW_BYTES, NULL }, /* bytes from server to client */
79 { "CC", LOG_FMT_CCLIENT, PR_MODE_HTTP, LW_REQHDR, NULL }, /* client cookie */
80 { "CS", LOG_FMT_CSERVER, PR_MODE_HTTP, LW_RSPHDR, NULL }, /* server cookie */
81 { "H", LOG_FMT_HOSTNAME, PR_MODE_TCP, LW_INIT, NULL }, /* Hostname */
82 { "ID", LOG_FMT_UNIQUEID, PR_MODE_HTTP, LW_BYTES, NULL }, /* Unique ID */
83 { "ST", LOG_FMT_STATUS, PR_MODE_HTTP, LW_RESP, NULL }, /* status code */
William Lallemand5e19a282012-04-02 16:22:10 +020084 { "T", LOG_FMT_DATEGMT, PR_MODE_TCP, LW_INIT, NULL }, /* date GMT */
Willy Tarreau2beef582012-12-20 17:22:52 +010085 { "Tc", LOG_FMT_TC, PR_MODE_TCP, LW_BYTES, NULL }, /* Tc */
Yuxans Yao4e25b012012-10-19 10:36:09 +080086 { "Tl", LOG_FMT_DATELOCAL, PR_MODE_TCP, LW_INIT, NULL }, /* date local timezone */
William Lallemand5e19a282012-04-02 16:22:10 +020087 { "Tq", LOG_FMT_TQ, PR_MODE_HTTP, LW_BYTES, NULL }, /* Tq */
William Lallemand5e19a282012-04-02 16:22:10 +020088 { "Tr", LOG_FMT_TR, PR_MODE_HTTP, LW_BYTES, NULL }, /* Tr */
Willy Tarreau2beef582012-12-20 17:22:52 +010089 { "Ts", LOG_FMT_TS, PR_MODE_TCP, LW_INIT, NULL }, /* timestamp GMT */
William Lallemand5e19a282012-04-02 16:22:10 +020090 { "Tt", LOG_FMT_TT, PR_MODE_TCP, LW_BYTES, NULL }, /* Tt */
Willy Tarreau2beef582012-12-20 17:22:52 +010091 { "Tw", LOG_FMT_TW, PR_MODE_TCP, LW_BYTES, NULL }, /* Tw */
92 { "U", LOG_FMT_BYTES_UP, PR_MODE_TCP, LW_BYTES, NULL }, /* bytes from client to server */
William Lallemand5e19a282012-04-02 16:22:10 +020093 { "ac", LOG_FMT_ACTCONN, PR_MODE_TCP, LW_BYTES, NULL }, /* actconn */
Willy Tarreau2beef582012-12-20 17:22:52 +010094 { "b", LOG_FMT_BACKEND, PR_MODE_TCP, LW_INIT, NULL }, /* backend */
William Lallemand5e19a282012-04-02 16:22:10 +020095 { "bc", LOG_FMT_BECONN, PR_MODE_TCP, LW_BYTES, NULL }, /* beconn */
Willy Tarreau2beef582012-12-20 17:22:52 +010096 { "bi", LOG_FMT_BACKENDIP, PR_MODE_TCP, LW_BCKIP, prepare_addrsource }, /* backend source ip */
97 { "bp", LOG_FMT_BACKENDPORT, PR_MODE_TCP, LW_BCKIP, prepare_addrsource }, /* backend source port */
William Lallemand5e19a282012-04-02 16:22:10 +020098 { "bq", LOG_FMT_BCKQUEUE, PR_MODE_TCP, LW_BYTES, NULL }, /* backend_queue */
Willy Tarreau2beef582012-12-20 17:22:52 +010099 { "ci", LOG_FMT_CLIENTIP, PR_MODE_TCP, LW_CLIP, NULL }, /* client ip */
100 { "cp", LOG_FMT_CLIENTPORT, PR_MODE_TCP, LW_CLIP, NULL }, /* client port */
101 { "f", LOG_FMT_FRONTEND, PR_MODE_TCP, LW_INIT, NULL }, /* frontend */
102 { "fc", LOG_FMT_FECONN, PR_MODE_TCP, LW_BYTES, NULL }, /* feconn */
103 { "fi", LOG_FMT_FRONTENDIP, PR_MODE_TCP, LW_FRTIP, NULL }, /* frontend ip */
104 { "fp", LOG_FMT_FRONTENDPORT, PR_MODE_TCP, LW_FRTIP, NULL }, /* frontend port */
105 { "ft", LOG_FMT_FRONTEND_XPRT, PR_MODE_TCP, LW_INIT, NULL }, /* frontend with transport mode */
William Lallemand5e19a282012-04-02 16:22:10 +0200106 { "hr", LOG_FMT_HDRREQUEST, PR_MODE_HTTP, LW_REQHDR, NULL }, /* header request */
William Lallemand5e19a282012-04-02 16:22:10 +0200107 { "hrl", LOG_FMT_HDRREQUESTLIST, PR_MODE_HTTP, LW_REQHDR, NULL }, /* header request list */
Willy Tarreau2beef582012-12-20 17:22:52 +0100108 { "hs", LOG_FMT_HDRRESPONS, PR_MODE_HTTP, LW_RSPHDR, NULL }, /* header response */
William Lallemand5e19a282012-04-02 16:22:10 +0200109 { "hsl", LOG_FMT_HDRRESPONSLIST, PR_MODE_HTTP, LW_RSPHDR, NULL }, /* header response list */
Willy Tarreau2beef582012-12-20 17:22:52 +0100110 { "ms", LOG_FMT_MS, PR_MODE_TCP, LW_INIT, NULL }, /* accept date millisecond */
William Lallemand5e19a282012-04-02 16:22:10 +0200111 { "pid", LOG_FMT_PID, PR_MODE_TCP, LW_INIT, NULL }, /* log pid */
Willy Tarreau2beef582012-12-20 17:22:52 +0100112 { "r", LOG_FMT_REQ, PR_MODE_HTTP, LW_REQ, NULL }, /* request */
113 { "rc", LOG_FMT_RETRIES, PR_MODE_TCP, LW_BYTES, NULL }, /* retries */
William Lallemand5e19a282012-04-02 16:22:10 +0200114 { "rt", LOG_FMT_COUNTER, PR_MODE_HTTP, LW_REQ, NULL }, /* HTTP request counter */
Willy Tarreau2beef582012-12-20 17:22:52 +0100115 { "s", LOG_FMT_SERVER, PR_MODE_TCP, LW_SVID, NULL }, /* server */
116 { "sc", LOG_FMT_SRVCONN, PR_MODE_TCP, LW_BYTES, NULL }, /* srv_conn */
117 { "si", LOG_FMT_SERVERIP, PR_MODE_TCP, LW_SVIP, NULL }, /* server destination ip */
118 { "sp", LOG_FMT_SERVERPORT, PR_MODE_TCP, LW_SVIP, NULL }, /* server destination port */
119 { "sq", LOG_FMT_SRVQUEUE, PR_MODE_TCP, LW_BYTES, NULL }, /* srv_queue */
Willy Tarreauffc3fcd2012-10-12 20:17:54 +0200120 { "sslc", LOG_FMT_SSL_CIPHER, PR_MODE_TCP, LW_XPRT, NULL }, /* client-side SSL ciphers */
121 { "sslv", LOG_FMT_SSL_VERSION, PR_MODE_TCP, LW_XPRT, NULL }, /* client-side SSL protocol version */
Willy Tarreau2beef582012-12-20 17:22:52 +0100122 { "t", LOG_FMT_DATE, PR_MODE_TCP, LW_INIT, NULL }, /* date */
123 { "ts", LOG_FMT_TERMSTATE, PR_MODE_TCP, LW_BYTES, NULL },/* termination state */
124 { "tsc", LOG_FMT_TERMSTATE_CK, PR_MODE_TCP, LW_INIT, NULL },/* termination state */
125
126 /* The following tags are deprecated and will be removed soon */
127 { "Bi", LOG_FMT_BACKENDIP, PR_MODE_TCP, LW_BCKIP, prepare_addrsource, "bi" }, /* backend source ip */
128 { "Bp", LOG_FMT_BACKENDPORT, PR_MODE_TCP, LW_BCKIP, prepare_addrsource, "bp" }, /* backend source port */
129 { "Ci", LOG_FMT_CLIENTIP, PR_MODE_TCP, LW_CLIP, NULL, "ci" }, /* client ip */
130 { "Cp", LOG_FMT_CLIENTPORT, PR_MODE_TCP, LW_CLIP, NULL, "cp" }, /* client port */
131 { "Fi", LOG_FMT_FRONTENDIP, PR_MODE_TCP, LW_FRTIP, NULL, "fi" }, /* frontend ip */
132 { "Fp", LOG_FMT_FRONTENDPORT, PR_MODE_TCP, LW_FRTIP, NULL, "fp" }, /* frontend port */
133 { "Si", LOG_FMT_SERVERIP, PR_MODE_TCP, LW_SVIP, NULL, "si" }, /* server destination ip */
134 { "Sp", LOG_FMT_SERVERPORT, PR_MODE_TCP, LW_SVIP, NULL, "sp" }, /* server destination port */
135 { "cc", LOG_FMT_CCLIENT, PR_MODE_HTTP, LW_REQHDR, NULL, "CC" }, /* client cookie */
136 { "cs", LOG_FMT_CSERVER, PR_MODE_HTTP, LW_RSPHDR, NULL, "CS" }, /* server cookie */
137 { "st", LOG_FMT_STATUS, PR_MODE_HTTP, LW_RESP, NULL, "ST" }, /* status code */
William Lallemand5e19a282012-04-02 16:22:10 +0200138 { 0, 0, 0, 0, NULL }
William Lallemand723b73a2012-02-08 16:37:49 +0100139};
140
Willy Tarreau2beef582012-12-20 17:22:52 +0100141char default_http_log_format[] = "%ci:%cp [%t] %ft %b/%s %Tq/%Tw/%Tc/%Tr/%Tt %ST %B %CC %CS %tsc %ac/%fc/%bc/%sc/%rc %sq/%bq %hr %hs %{+Q}r"; // default format
142char clf_http_log_format[] = "%{+Q}o %{-Q}ci - - [%T] %r %ST %B \"\" \"\" %cp %ms %ft %b %s %Tq %Tw %Tc %Tr %Tt %tsc %ac %fc %bc %sc %rc %sq %bq %CC %CS %hrl %hsl";
143char default_tcp_log_format[] = "%ci:%cp [%t] %ft %b/%s %Tw/%Tc/%Tt %B %ts %ac/%fc/%bc/%sc/%rc %sq/%bq";
William Lallemand723b73a2012-02-08 16:37:49 +0100144char *log_format = NULL;
145
Willy Tarreaub1a2faf2012-03-19 16:51:53 +0100146/* This is a global syslog line, common to all outgoing messages. It begins
147 * with the syslog tag and the date that are updated by update_log_hdr().
148 */
149static char logline[MAX_SYSLOG_LEN];
150
William Lallemand723b73a2012-02-08 16:37:49 +0100151struct logformat_var_args {
152 char *name;
153 int mask;
154};
155
156struct logformat_var_args var_args_list[] = {
157// global
158 { "M", LOG_OPT_MANDATORY },
159 { "Q", LOG_OPT_QUOTE },
William Lallemand5f232402012-04-05 18:02:55 +0200160 { "X", LOG_OPT_HEXA },
William Lallemand723b73a2012-02-08 16:37:49 +0100161 { 0, 0 }
162};
163
164/*
William Lallemandb7ff6a32012-03-02 14:35:21 +0100165 * callback used to configure addr source retrieval
166 */
167int prepare_addrsource(struct logformat_node *node, struct proxy *curproxy)
168{
169 curproxy->options2 |= PR_O2_SRC_ADDR;
170
171 return 0;
172}
173
174
175/*
William Lallemand723b73a2012-02-08 16:37:49 +0100176 * Parse args in a logformat_var
177 */
178int parse_logformat_var_args(char *args, struct logformat_node *node)
179{
180 int i = 0;
181 int end = 0;
182 int flags = 0; // 1 = + 2 = -
183 char *sp = NULL; // start pointer
184
185 if (args == NULL)
186 return 1;
187
188 while (1) {
189 if (*args == '\0')
190 end = 1;
191
192 if (*args == '+') {
193 // add flag
194 sp = args + 1;
195 flags = 1;
196 }
197 if (*args == '-') {
198 // delete flag
199 sp = args + 1;
200 flags = 2;
201 }
202
203 if (*args == '\0' || *args == ',') {
204 *args = '\0';
Willy Tarreau254d44c2012-12-20 18:19:26 +0100205 for (i = 0; sp && var_args_list[i].name; i++) {
William Lallemand723b73a2012-02-08 16:37:49 +0100206 if (strcmp(sp, var_args_list[i].name) == 0) {
207 if (flags == 1) {
208 node->options |= var_args_list[i].mask;
209 break;
210 } else if (flags == 2) {
211 node->options &= ~var_args_list[i].mask;
212 break;
213 }
214 }
215 }
216 sp = NULL;
217 if (end)
218 break;
219 }
Willy Tarreau254d44c2012-12-20 18:19:26 +0100220 args++;
William Lallemand723b73a2012-02-08 16:37:49 +0100221 }
222 return 0;
223}
224
225/*
Willy Tarreau8a3f52f2012-12-20 21:23:42 +0100226 * Parse a variable '%varname' or '%{args}varname' in log-format. The caller
227 * must pass the args part in the <arg> pointer with its length in <arg_len>,
228 * and varname with its length in <var> and <var_len> respectively. <arg> is
229 * ignored when arg_len is 0. Neither <var> nor <var_len> may be null.
William Lallemand723b73a2012-02-08 16:37:49 +0100230 */
Willy Tarreau8a3f52f2012-12-20 21:23:42 +0100231int 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 +0100232{
Willy Tarreau8a3f52f2012-12-20 21:23:42 +0100233 int j;
234 struct logformat_node *node;
William Lallemand723b73a2012-02-08 16:37:49 +0100235
Willy Tarreau8a3f52f2012-12-20 21:23:42 +0100236 for (j = 0; logformat_keywords[j].name; j++) { // search a log type
237 if (strlen(logformat_keywords[j].name) == var_len &&
238 strncmp(var, logformat_keywords[j].name, var_len) == 0) {
239 if (logformat_keywords[j].mode != PR_MODE_HTTP || curproxy->mode == PR_MODE_HTTP) {
240 node = calloc(1, sizeof(struct logformat_node));
241 node->type = logformat_keywords[j].type;
242 node->options = *defoptions;
243 if (arg_len) {
244 node->arg = my_strndup(arg, arg_len);
245 parse_logformat_var_args(node->arg, node);
246 }
247 if (node->type == LOG_FMT_GLOBAL) {
248 *defoptions = node->options;
249 free(node->arg);
250 free(node);
251 } else {
252 if (logformat_keywords[j].config_callback &&
253 logformat_keywords[j].config_callback(node, curproxy) != 0) {
William Lallemandbddd4fd2012-02-27 11:23:10 +0100254 return -1;
William Lallemand723b73a2012-02-08 16:37:49 +0100255 }
Willy Tarreau8a3f52f2012-12-20 21:23:42 +0100256 curproxy->to_log |= logformat_keywords[j].lw;
257 LIST_ADDQ(list_format, &node->list);
William Lallemand723b73a2012-02-08 16:37:49 +0100258 }
Willy Tarreau8a3f52f2012-12-20 21:23:42 +0100259 if (logformat_keywords[j].replace_by)
260 Warning("Warning: deprecated variable '%s' in log-format, please replace it with '%s'\n",
261 logformat_keywords[j].name, logformat_keywords[j].replace_by);
262 return 0;
263 } else {
264 Warning("Warning: log-format variable name '%s' is not suited to HTTP mode\n", logformat_keywords[j].name);
265 return -1;
William Lallemand723b73a2012-02-08 16:37:49 +0100266 }
William Lallemand723b73a2012-02-08 16:37:49 +0100267 }
268 }
Willy Tarreau8a3f52f2012-12-20 21:23:42 +0100269
270 j = var[var_len];
271 var[var_len] = 0;
272 Warning("Warning: no such variable name '%s' in log-format\n", var);
273 var[var_len] = j;
William Lallemand723b73a2012-02-08 16:37:49 +0100274 return -1;
275}
276
277/*
278 * push to the logformat linked list
279 *
280 * start: start pointer
281 * end: end text pointer
282 * type: string type
William Lallemand1d705562012-03-12 12:46:41 +0100283 * list_format: destination list
William Lallemand723b73a2012-02-08 16:37:49 +0100284 *
285 * LOG_TEXT: copy chars from start to end excluding end.
286 *
287*/
William Lallemand1d705562012-03-12 12:46:41 +0100288void add_to_logformat_list(char *start, char *end, int type, struct list *list_format)
William Lallemand723b73a2012-02-08 16:37:49 +0100289{
290 char *str;
291
Willy Tarreaua3571662012-12-20 21:59:12 +0100292 if (type == LF_TEXT) { /* type text */
William Lallemand723b73a2012-02-08 16:37:49 +0100293 struct logformat_node *node = calloc(1, sizeof(struct logformat_node));
William Lallemand723b73a2012-02-08 16:37:49 +0100294 str = calloc(end - start + 1, 1);
295 strncpy(str, start, end - start);
William Lallemand723b73a2012-02-08 16:37:49 +0100296 str[end - start] = '\0';
297 node->arg = str;
William Lallemand1d705562012-03-12 12:46:41 +0100298 node->type = LOG_FMT_TEXT; // type string
299 LIST_ADDQ(list_format, &node->list);
Willy Tarreaua3571662012-12-20 21:59:12 +0100300 } else if (type == LF_SEPARATOR) {
William Lallemand723b73a2012-02-08 16:37:49 +0100301 struct logformat_node *node = calloc(1, sizeof(struct logformat_node));
William Lallemand1d705562012-03-12 12:46:41 +0100302 node->type = LOG_FMT_SEPARATOR;
303 LIST_ADDQ(list_format, &node->list);
William Lallemand723b73a2012-02-08 16:37:49 +0100304 }
305}
306
307/*
Willy Tarreauc8368452012-12-21 00:09:23 +0100308 * Parse the sample fetch expression <text> and add a node to <list_format> upon
309 * success. At the moment, sample converters are not yet supported but fetch arguments
310 * should work.
311 */
312void add_sample_to_logformat_list(char *text, char *arg, int arg_len, struct proxy *curpx, struct list *list_format, int options)
313{
314 char *cmd[2];
315 struct sample_expr *expr;
316 struct logformat_node *node;
317 int cmd_arg;
318
319 cmd[0] = text;
320 cmd[1] = "";
321 cmd_arg = 0;
322
323 expr = sample_parse_expr(cmd, &cmd_arg, trash.str, trash.size);
324 if (!expr) {
325 Warning("log-format: sample fetch <%s> failed with : %s\n", text, trash.str);
326 return;
327 }
328
329 node = calloc(1, sizeof(struct logformat_node));
330 node->type = LOG_FMT_EXPR;
331 node->expr = expr;
332 node->options = options;
333
334 if (arg_len) {
335 node->arg = my_strndup(arg, arg_len);
336 parse_logformat_var_args(node->arg, node);
337 }
338 if (expr->fetch->cap & SMP_CAP_REQ)
339 node->options |= LOG_OPT_REQ_CAP; /* fetch method is request-compatible */
340
341 if (expr->fetch->cap & SMP_CAP_RES)
342 node->options |= LOG_OPT_RES_CAP; /* fetch method is response-compatible */
343
344 /* check if we need to allocate an hdr_idx struct for HTTP parsing */
345 /* Note, we may also need to set curpx->to_log with certain fetches */
346 if (expr->fetch->cap & SMP_CAP_L7)
347 curpx->acl_requires |= ACL_USE_L7_ANY;
348
Willy Tarreau1f31c732013-01-10 16:22:27 +0100349 /* FIXME: temporary workaround for missing LW_XPRT flag needed with some
350 * sample fetches (eg: ssl*). We always set it for now on, but this will
351 * leave with sample capabilities soon.
352 */
353 curpx->to_log |= LW_XPRT;
Willy Tarreauc8368452012-12-21 00:09:23 +0100354 LIST_ADDQ(list_format, &node->list);
355}
356
357/*
William Lallemand723b73a2012-02-08 16:37:49 +0100358 * Parse the log_format string and fill a linked list.
359 * Variable name are preceded by % and composed by characters [a-zA-Z0-9]* : %varname
360 * You can set arguments using { } : %{many arguments}varname
William Lallemand1d705562012-03-12 12:46:41 +0100361 *
362 * str: the string to parse
363 * curproxy: the proxy affected
364 * list_format: the destination list
365 * capabilities: PR_MODE_TCP_ | PR_MODE_HTTP
William Lallemand723b73a2012-02-08 16:37:49 +0100366 */
Willy Tarreaub83bc1e2012-12-24 12:36:33 +0100367void parse_logformat_string(const char *fmt, struct proxy *curproxy, struct list *list_format, int capabilities)
William Lallemand723b73a2012-02-08 16:37:49 +0100368{
Willy Tarreaub83bc1e2012-12-24 12:36:33 +0100369 char *sp, *str, *backfmt; /* start pointer for text parts */
Willy Tarreau8a3f52f2012-12-20 21:23:42 +0100370 char *arg = NULL; /* start pointer for args */
371 char *var = NULL; /* start pointer for vars */
372 int arg_len = 0;
373 int var_len = 0;
374 int cformat; /* current token format */
375 int pformat; /* previous token format */
William Lallemand723b73a2012-02-08 16:37:49 +0100376 struct logformat_node *tmplf, *back;
William Lallemand81f51172012-03-12 11:03:47 +0100377 int options = 0;
William Lallemand723b73a2012-02-08 16:37:49 +0100378
Willy Tarreaub83bc1e2012-12-24 12:36:33 +0100379 sp = str = backfmt = strdup(fmt);
William Lallemand1dc00ef2012-08-09 16:41:35 +0200380 curproxy->to_log |= LW_INIT;
William Lallemand5e19a282012-04-02 16:22:10 +0200381
William Lallemand723b73a2012-02-08 16:37:49 +0100382 /* flush the list first. */
William Lallemand1d705562012-03-12 12:46:41 +0100383 list_for_each_entry_safe(tmplf, back, list_format, list) {
William Lallemand723b73a2012-02-08 16:37:49 +0100384 LIST_DEL(&tmplf->list);
385 free(tmplf);
386 }
387
Willy Tarreau8a3f52f2012-12-20 21:23:42 +0100388 for (cformat = LF_INIT; cformat != LF_END; str++) {
William Lallemand723b73a2012-02-08 16:37:49 +0100389 pformat = cformat;
390
Willy Tarreau8a3f52f2012-12-20 21:23:42 +0100391 if (!*str)
392 cformat = LF_END; // preset it to save all states from doing this
William Lallemand723b73a2012-02-08 16:37:49 +0100393
Willy Tarreau8a3f52f2012-12-20 21:23:42 +0100394 /* The prinicple of the two-step state machine below is to first detect a change, and
395 * second have all common paths processed at one place. The common paths are the ones
396 * encountered in text areas (LF_INIT, LF_TEXT, LF_SEPARATOR) and at the end (LF_END).
397 * We use the common LF_INIT state to dispatch to the different final states.
398 */
399 switch (pformat) {
400 case LF_STARTVAR: // text immediately following a '%'
Willy Tarreauc8368452012-12-21 00:09:23 +0100401 arg = NULL; var = NULL;
Willy Tarreau8a3f52f2012-12-20 21:23:42 +0100402 arg_len = var_len = 0;
403 if (*str == '{') { // optional argument
404 cformat = LF_STARG;
405 arg = str + 1;
William Lallemand723b73a2012-02-08 16:37:49 +0100406 }
Willy Tarreauc8368452012-12-21 00:09:23 +0100407 else if (*str == '[') {
408 cformat = LF_STEXPR;
409 var = str + 1; // store expr in variable name
410 }
Willy Tarreau8a3f52f2012-12-20 21:23:42 +0100411 else if (isalnum((int)*str)) { // variable name
William Lallemand723b73a2012-02-08 16:37:49 +0100412 cformat = LF_VAR;
Willy Tarreau8a3f52f2012-12-20 21:23:42 +0100413 var = str;
William Lallemand723b73a2012-02-08 16:37:49 +0100414 }
Willy Tarreau8a3f52f2012-12-20 21:23:42 +0100415 else if (*str == '%')
416 cformat = LF_TEXT; // convert this character to a litteral (useful for '%')
417 else
418 cformat = LF_INIT; // handle other cases of litterals
419 break;
420
421 case LF_STARG: // text immediately following '%{'
422 if (*str == '}') { // end of arg
William Lallemand723b73a2012-02-08 16:37:49 +0100423 cformat = LF_EDARG;
Willy Tarreau8a3f52f2012-12-20 21:23:42 +0100424 arg_len = str - arg;
425 *str = 0; // used for reporting errors
William Lallemand723b73a2012-02-08 16:37:49 +0100426 }
Willy Tarreau8a3f52f2012-12-20 21:23:42 +0100427 break;
428
429 case LF_EDARG: // text immediately following '%{arg}'
Willy Tarreauc8368452012-12-21 00:09:23 +0100430 if (*str == '[') {
431 cformat = LF_STEXPR;
432 var = str + 1; // store expr in variable name
433 break;
434 }
435 else if (isalnum((int)*str)) { // variable name
William Lallemand723b73a2012-02-08 16:37:49 +0100436 cformat = LF_VAR;
Willy Tarreau8a3f52f2012-12-20 21:23:42 +0100437 var = str;
438 break;
439 }
Willy Tarreau8a3f52f2012-12-20 21:23:42 +0100440 Warning("Skipping isolated argument in log-format line : '%%{%s}'\n", arg);
441 cformat = LF_INIT;
442 break;
443
Willy Tarreauc8368452012-12-21 00:09:23 +0100444 case LF_STEXPR: // text immediately following '%['
445 if (*str == ']') { // end of arg
446 cformat = LF_EDEXPR;
447 var_len = str - var;
448 *str = 0; // needed for parsing the expression
449 }
450 break;
451
Willy Tarreau8a3f52f2012-12-20 21:23:42 +0100452 case LF_VAR: // text part of a variable name
453 var_len = str - var;
454 if (!isalnum((int)*str))
455 cformat = LF_INIT; // not variable name anymore
456 break;
457
Willy Tarreauc8368452012-12-21 00:09:23 +0100458 default: // LF_INIT, LF_TEXT, LF_SEPARATOR, LF_END, LF_EDEXPR
Willy Tarreau8a3f52f2012-12-20 21:23:42 +0100459 cformat = LF_INIT;
460 }
461
462 if (cformat == LF_INIT) { /* resynchronize state to text/sep/startvar */
463 switch (*str) {
464 case '%': cformat = LF_STARTVAR; break;
465 case ' ': cformat = LF_SEPARATOR; break;
466 case 0 : cformat = LF_END; break;
467 default : cformat = LF_TEXT; break;
William Lallemand723b73a2012-02-08 16:37:49 +0100468 }
469 }
470
Willy Tarreau8a3f52f2012-12-20 21:23:42 +0100471 if (cformat != pformat || pformat == LF_SEPARATOR) {
472 switch (pformat) {
473 case LF_VAR:
474 parse_logformat_var(arg, arg_len, var, var_len, curproxy, list_format, &options);
475 break;
Willy Tarreauc8368452012-12-21 00:09:23 +0100476 case LF_STEXPR:
477 add_sample_to_logformat_list(var, arg, arg_len, curproxy, list_format, options);
478 break;
Willy Tarreau8a3f52f2012-12-20 21:23:42 +0100479 case LF_TEXT:
480 case LF_SEPARATOR:
481 add_to_logformat_list(sp, str, pformat, list_format);
482 break;
483 }
484 sp = str; /* new start of text at every state switch and at every separator */
William Lallemand723b73a2012-02-08 16:37:49 +0100485 }
486 }
Willy Tarreau8a3f52f2012-12-20 21:23:42 +0100487
Willy Tarreauc8368452012-12-21 00:09:23 +0100488 if (pformat == LF_STARTVAR || pformat == LF_STARG || pformat == LF_STEXPR)
489 Warning("Ignoring end of truncated log-format line after '%s'\n", var ? var : arg ? arg : "%");
Willy Tarreau3ed22a42012-12-23 17:29:07 +0100490
Willy Tarreaub83bc1e2012-12-24 12:36:33 +0100491 free(backfmt);
William Lallemand723b73a2012-02-08 16:37:49 +0100492}
493
Willy Tarreaubaaee002006-06-26 02:48:02 +0200494/*
495 * Displays the message on stderr with the date and pid. Overrides the quiet
496 * mode during startup.
497 */
Willy Tarreaub17916e2006-10-15 15:17:57 +0200498void Alert(const char *fmt, ...)
Willy Tarreaubaaee002006-06-26 02:48:02 +0200499{
500 va_list argp;
Willy Tarreaufe944602007-10-25 10:34:16 +0200501 struct tm tm;
Willy Tarreaubaaee002006-06-26 02:48:02 +0200502
503 if (!(global.mode & MODE_QUIET) || (global.mode & (MODE_VERBOSE | MODE_STARTING))) {
504 va_start(argp, fmt);
505
Willy Tarreaub7f694f2008-06-22 17:18:02 +0200506 get_localtime(date.tv_sec, &tm);
Willy Tarreaubaaee002006-06-26 02:48:02 +0200507 fprintf(stderr, "[ALERT] %03d/%02d%02d%02d (%d) : ",
Willy Tarreaufe944602007-10-25 10:34:16 +0200508 tm.tm_yday, tm.tm_hour, tm.tm_min, tm.tm_sec, (int)getpid());
Willy Tarreaubaaee002006-06-26 02:48:02 +0200509 vfprintf(stderr, fmt, argp);
510 fflush(stderr);
511 va_end(argp);
512 }
513}
514
515
516/*
517 * Displays the message on stderr with the date and pid.
518 */
Willy Tarreaub17916e2006-10-15 15:17:57 +0200519void Warning(const char *fmt, ...)
Willy Tarreaubaaee002006-06-26 02:48:02 +0200520{
521 va_list argp;
Willy Tarreaufe944602007-10-25 10:34:16 +0200522 struct tm tm;
Willy Tarreaubaaee002006-06-26 02:48:02 +0200523
524 if (!(global.mode & MODE_QUIET) || (global.mode & MODE_VERBOSE)) {
525 va_start(argp, fmt);
526
Willy Tarreaub7f694f2008-06-22 17:18:02 +0200527 get_localtime(date.tv_sec, &tm);
Willy Tarreaubaaee002006-06-26 02:48:02 +0200528 fprintf(stderr, "[WARNING] %03d/%02d%02d%02d (%d) : ",
Willy Tarreaufe944602007-10-25 10:34:16 +0200529 tm.tm_yday, tm.tm_hour, tm.tm_min, tm.tm_sec, (int)getpid());
Willy Tarreaubaaee002006-06-26 02:48:02 +0200530 vfprintf(stderr, fmt, argp);
531 fflush(stderr);
532 va_end(argp);
533 }
534}
535
536/*
537 * Displays the message on <out> only if quiet mode is not set.
538 */
Willy Tarreaub17916e2006-10-15 15:17:57 +0200539void qfprintf(FILE *out, const char *fmt, ...)
Willy Tarreaubaaee002006-06-26 02:48:02 +0200540{
541 va_list argp;
542
543 if (!(global.mode & MODE_QUIET) || (global.mode & MODE_VERBOSE)) {
544 va_start(argp, fmt);
545 vfprintf(out, fmt, argp);
546 fflush(out);
547 va_end(argp);
548 }
549}
550
551/*
552 * returns log level for <lev> or -1 if not found.
553 */
554int get_log_level(const char *lev)
555{
556 int level;
557
558 level = NB_LOG_LEVELS - 1;
559 while (level >= 0 && strcmp(log_levels[level], lev))
560 level--;
561
562 return level;
563}
564
565
566/*
567 * returns log facility for <fac> or -1 if not found.
568 */
569int get_log_facility(const char *fac)
570{
571 int facility;
572
573 facility = NB_LOG_FACILITIES - 1;
574 while (facility >= 0 && strcmp(log_facilities[facility], fac))
575 facility--;
William Lallemand2a4a44f2012-02-06 16:00:33 +0100576
Willy Tarreaubaaee002006-06-26 02:48:02 +0200577 return facility;
578}
579
William Lallemanda1cc3812012-02-08 16:38:44 +0100580/*
581 * Write a string in the log string
William Lallemand5f232402012-04-05 18:02:55 +0200582 * Take cares of quote options
William Lallemanda1cc3812012-02-08 16:38:44 +0100583 *
584 * Return the adress of the \0 character, or NULL on error
585 */
Willy Tarreau2b0108a2012-12-21 19:23:44 +0100586char *lf_text_len(char *dst, const char *src, size_t len, size_t size, struct logformat_node *node)
William Lallemanda1cc3812012-02-08 16:38:44 +0100587{
Willy Tarreau2b0108a2012-12-21 19:23:44 +0100588 if (size < 2)
589 return NULL;
William Lallemanda1cc3812012-02-08 16:38:44 +0100590
Willy Tarreau2b0108a2012-12-21 19:23:44 +0100591 if (node->options & LOG_OPT_QUOTE) {
592 *(dst++) = '"';
593 size--;
William Lallemandbddd4fd2012-02-27 11:23:10 +0100594 }
Willy Tarreau2b0108a2012-12-21 19:23:44 +0100595
596 if (src) {
597 if (++len > size)
598 len = size;
599 len = strlcpy2(dst, src, len);
600
601 size -= len;
602 dst += len;
603 }
604
605 if (node->options & LOG_OPT_QUOTE) {
606 if (size < 2)
607 return NULL;
608 *(dst++) = '"';
609 }
610
611 *dst = '\0';
William Lallemandbddd4fd2012-02-27 11:23:10 +0100612 return dst;
William Lallemanda1cc3812012-02-08 16:38:44 +0100613}
614
Willy Tarreau2b0108a2012-12-21 19:23:44 +0100615static inline char *lf_text(char *dst, const char *src, size_t size, struct logformat_node *node)
616{
617 return lf_text_len(dst, src, size, size, node);
618}
619
William Lallemand5f232402012-04-05 18:02:55 +0200620/*
621 * Write a IP adress to the log string
622 * +X option write in hexadecimal notation, most signifant byte on the left
623 */
624char *lf_ip(char *dst, struct sockaddr *sockaddr, size_t size, struct logformat_node *node)
625{
626 char *ret = dst;
627 int iret;
628 char pn[INET6_ADDRSTRLEN];
629
630 if (node->options & LOG_OPT_HEXA) {
631 const unsigned char *addr = (const unsigned char *)&((struct sockaddr_in *)sockaddr)->sin_addr.s_addr;
632 iret = snprintf(dst, size, "%02X%02X%02X%02X", addr[0], addr[1], addr[2], addr[3]);
633 if (iret < 0 || iret > size)
634 return NULL;
635 ret += iret;
636 } else {
637 addr_to_str((struct sockaddr_storage *)sockaddr, pn, sizeof(pn));
638 ret = lf_text(dst, pn, size, node);
639 if (ret == NULL)
640 return NULL;
641 }
642 return ret;
643}
644
645/*
646 * Write a port to the log
647 * +X option write in hexadecimal notation, most signifant byte on the left
648 */
649char *lf_port(char *dst, struct sockaddr *sockaddr, size_t size, struct logformat_node *node)
650{
651 char *ret = dst;
652 int iret;
653
654 if (node->options & LOG_OPT_HEXA) {
655 const unsigned char *port = (const unsigned char *)&((struct sockaddr_in *)sockaddr)->sin_port;
656 iret = snprintf(dst, size, "%02X%02X", port[0], port[1]);
657 if (iret < 0 || iret > size)
658 return NULL;
659 ret += iret;
660 } else {
661 ret = ltoa_o(get_host_port((struct sockaddr_storage *)sockaddr), dst, size);
662 if (ret == NULL)
663 return NULL;
664 }
665 return ret;
666}
667
Willy Tarreaub1a2faf2012-03-19 16:51:53 +0100668/* Re-generate the syslog header at the beginning of logline once a second and
669 * return the pointer to the first character after the header.
670 */
671static char *update_log_hdr()
Willy Tarreaubaaee002006-06-26 02:48:02 +0200672{
Willy Tarreaub1a2faf2012-03-19 16:51:53 +0100673 static long tvsec;
674 static char *dataptr = NULL; /* backup of last end of header, NULL first time */
Willy Tarreaubaaee002006-06-26 02:48:02 +0200675
Willy Tarreaub7f694f2008-06-22 17:18:02 +0200676 if (unlikely(date.tv_sec != tvsec || dataptr == NULL)) {
Willy Tarreaubaaee002006-06-26 02:48:02 +0200677 /* this string is rebuild only once a second */
Willy Tarreaufe944602007-10-25 10:34:16 +0200678 struct tm tm;
Willy Tarreaub1a2faf2012-03-19 16:51:53 +0100679 int hdr_len;
Willy Tarreaufe944602007-10-25 10:34:16 +0200680
Willy Tarreaub7f694f2008-06-22 17:18:02 +0200681 tvsec = date.tv_sec;
Willy Tarreaufe944602007-10-25 10:34:16 +0200682 get_localtime(tvsec, &tm);
Willy Tarreaubaaee002006-06-26 02:48:02 +0200683
Willy Tarreaub1a2faf2012-03-19 16:51:53 +0100684 hdr_len = snprintf(logline, MAX_SYSLOG_LEN,
Joe Williamsdf5b38f2010-12-29 17:05:48 +0100685 "<<<<>%s %2d %02d:%02d:%02d %s%s[%d]: ",
Willy Tarreaufe944602007-10-25 10:34:16 +0200686 monthname[tm.tm_mon],
687 tm.tm_mday, tm.tm_hour, tm.tm_min, tm.tm_sec,
Joe Williamsdf5b38f2010-12-29 17:05:48 +0100688 global.log_send_hostname ? global.log_send_hostname : "",
Kevinm48936af2010-12-22 16:08:21 +0000689 global.log_tag, pid);
Willy Tarreaubaaee002006-06-26 02:48:02 +0200690 /* WARNING: depending upon implementations, snprintf may return
691 * either -1 or the number of bytes that would be needed to store
692 * the total message. In both cases, we must adjust it.
693 */
William Lallemand2a4a44f2012-02-06 16:00:33 +0100694 if (hdr_len < 0 || hdr_len > MAX_SYSLOG_LEN)
695 hdr_len = MAX_SYSLOG_LEN;
Willy Tarreaubaaee002006-06-26 02:48:02 +0200696
Willy Tarreaub1a2faf2012-03-19 16:51:53 +0100697 dataptr = logline + hdr_len;
Willy Tarreaubaaee002006-06-26 02:48:02 +0200698 }
699
William Lallemand2a4a44f2012-02-06 16:00:33 +0100700 return dataptr;
701}
702
703/*
704 * This function adds a header to the message and sends the syslog message
Willy Tarreau53bf6af2012-02-24 11:46:54 +0100705 * using a printf format string. It expects an LF-terminated message.
William Lallemand2a4a44f2012-02-06 16:00:33 +0100706 */
707void send_log(struct proxy *p, int level, const char *format, ...)
708{
709 va_list argp;
Willy Tarreaub1a2faf2012-03-19 16:51:53 +0100710 char *dataptr;
711 int data_len;
William Lallemand2a4a44f2012-02-06 16:00:33 +0100712
713 if (level < 0 || format == NULL)
714 return;
715
Willy Tarreaub1a2faf2012-03-19 16:51:53 +0100716 dataptr = update_log_hdr(); /* update log header and skip it */
717 data_len = dataptr - logline;
William Lallemand2a4a44f2012-02-06 16:00:33 +0100718
719 va_start(argp, format);
Willy Tarreaub1a2faf2012-03-19 16:51:53 +0100720 data_len += vsnprintf(dataptr, logline + sizeof(logline) - dataptr, format, argp);
William Lallemand2a4a44f2012-02-06 16:00:33 +0100721 if (data_len < 0 || data_len > MAX_SYSLOG_LEN)
722 data_len = MAX_SYSLOG_LEN;
Willy Tarreaubaaee002006-06-26 02:48:02 +0200723 va_end(argp);
William Lallemand2a4a44f2012-02-06 16:00:33 +0100724
Willy Tarreaub1a2faf2012-03-19 16:51:53 +0100725 __send_log(p, level, logline, data_len);
William Lallemand2a4a44f2012-02-06 16:00:33 +0100726}
727
728/*
729 * This function sends a syslog message.
730 * It doesn't care about errors nor does it report them.
Willy Tarreau53bf6af2012-02-24 11:46:54 +0100731 * It overrides the last byte (message[size-1]) with an LF character.
William Lallemand2a4a44f2012-02-06 16:00:33 +0100732 */
733void __send_log(struct proxy *p, int level, char *message, size_t size)
734{
735 static int logfdunix = -1; /* syslog to AF_UNIX socket */
736 static int logfdinet = -1; /* syslog to AF_INET socket */
737 static char *dataptr = NULL;
738 int fac_level;
739 struct list *logsrvs = NULL;
740 struct logsrv *tmp = NULL;
741 int nblogger;
742 char *log_ptr;
743
744 dataptr = message;
Willy Tarreaubaaee002006-06-26 02:48:02 +0200745
746 if (p == NULL) {
William Lallemand0f99e342011-10-12 17:50:54 +0200747 if (!LIST_ISEMPTY(&global.logsrvs)) {
748 logsrvs = &global.logsrvs;
Willy Tarreaubaaee002006-06-26 02:48:02 +0200749 }
750 } else {
William Lallemand0f99e342011-10-12 17:50:54 +0200751 if (!LIST_ISEMPTY(&p->logsrvs)) {
752 logsrvs = &p->logsrvs;
Willy Tarreaubaaee002006-06-26 02:48:02 +0200753 }
Robert Tsai81ae1952007-12-05 10:47:29 +0100754 }
755
William Lallemand0f99e342011-10-12 17:50:54 +0200756 if (!logsrvs)
757 return;
758
William Lallemand2a4a44f2012-02-06 16:00:33 +0100759 message[size - 1] = '\n';
760
Robert Tsai81ae1952007-12-05 10:47:29 +0100761 /* Lazily set up syslog sockets for protocol families of configured
762 * syslog servers. */
William Lallemand0f99e342011-10-12 17:50:54 +0200763 nblogger = 0;
764 list_for_each_entry(tmp, logsrvs, list) {
765 const struct logsrv *logsrv = tmp;
Robert Tsai81ae1952007-12-05 10:47:29 +0100766 int proto, *plogfd;
William Lallemand0f99e342011-10-12 17:50:54 +0200767
David du Colombier11bcb6c2011-03-24 12:23:00 +0100768 if (logsrv->addr.ss_family == AF_UNIX) {
Robert Tsai81ae1952007-12-05 10:47:29 +0100769 proto = 0;
770 plogfd = &logfdunix;
771 } else {
Robert Tsai81ae1952007-12-05 10:47:29 +0100772 proto = IPPROTO_UDP;
773 plogfd = &logfdinet;
774 }
775 if (*plogfd >= 0) {
776 /* socket already created. */
777 continue;
778 }
David du Colombier11bcb6c2011-03-24 12:23:00 +0100779 if ((*plogfd = socket(logsrv->addr.ss_family, SOCK_DGRAM,
Robert Tsai81ae1952007-12-05 10:47:29 +0100780 proto)) < 0) {
781 Alert("socket for logger #%d failed: %s (errno=%d)\n",
782 nblogger + 1, strerror(errno), errno);
783 return;
784 }
785 /* we don't want to receive anything on this socket */
786 setsockopt(*plogfd, SOL_SOCKET, SO_RCVBUF, &zero, sizeof(zero));
787 /* does nothing under Linux, maybe needed for others */
788 shutdown(*plogfd, SHUT_RD);
William Lallemand0f99e342011-10-12 17:50:54 +0200789 nblogger++;
Willy Tarreaubaaee002006-06-26 02:48:02 +0200790 }
791
Robert Tsai81ae1952007-12-05 10:47:29 +0100792 /* Send log messages to syslog server. */
William Lallemand0f99e342011-10-12 17:50:54 +0200793 nblogger = 0;
794 list_for_each_entry(tmp, logsrvs, list) {
795 const struct logsrv *logsrv = tmp;
David du Colombier11bcb6c2011-03-24 12:23:00 +0100796 int *plogfd = logsrv->addr.ss_family == AF_UNIX ?
Robert Tsai81ae1952007-12-05 10:47:29 +0100797 &logfdunix : &logfdinet;
798 int sent;
799
Willy Tarreaubaaee002006-06-26 02:48:02 +0200800 /* we can filter the level of the messages that are sent to each logger */
William Lallemand0f99e342011-10-12 17:50:54 +0200801 if (level > logsrv->level)
Willy Tarreaubaaee002006-06-26 02:48:02 +0200802 continue;
William Lallemandbddd4fd2012-02-27 11:23:10 +0100803
Willy Tarreaubaaee002006-06-26 02:48:02 +0200804 /* For each target, we may have a different facility.
805 * We can also have a different log level for each message.
806 * This induces variations in the message header length.
807 * Since we don't want to recompute it each time, nor copy it every
808 * time, we only change the facility in the pre-computed header,
809 * and we change the pointer to the header accordingly.
810 */
William Lallemand0f99e342011-10-12 17:50:54 +0200811 fac_level = (logsrv->facility << 3) + MAX(level, logsrv->minlvl);
William Lallemand2a4a44f2012-02-06 16:00:33 +0100812 log_ptr = dataptr + 3; /* last digit of the log level */
Willy Tarreaubaaee002006-06-26 02:48:02 +0200813 do {
814 *log_ptr = '0' + fac_level % 10;
815 fac_level /= 10;
816 log_ptr--;
William Lallemand2a4a44f2012-02-06 16:00:33 +0100817 } while (fac_level && log_ptr > dataptr);
Willy Tarreaubaaee002006-06-26 02:48:02 +0200818 *log_ptr = '<';
William Lallemand2a4a44f2012-02-06 16:00:33 +0100819
William Lallemandbfb099c2012-03-19 16:15:12 +0100820 sent = sendto(*plogfd, log_ptr, size + log_ptr - dataptr,
Willy Tarreau1b4b7ce2011-04-05 16:56:50 +0200821 MSG_DONTWAIT | MSG_NOSIGNAL,
822 (struct sockaddr *)&logsrv->addr, get_addr_len(&logsrv->addr));
Robert Tsai81ae1952007-12-05 10:47:29 +0100823 if (sent < 0) {
824 Alert("sendto logger #%d failed: %s (errno=%d)\n",
825 nblogger, strerror(errno), errno);
826 }
William Lallemand0f99e342011-10-12 17:50:54 +0200827 nblogger++;
Willy Tarreaubaaee002006-06-26 02:48:02 +0200828 }
829}
830
William Lallemandbddd4fd2012-02-27 11:23:10 +0100831extern fd_set hdr_encode_map[];
832extern fd_set url_encode_map[];
833
Willy Tarreaubaaee002006-06-26 02:48:02 +0200834
Willy Tarreauc89ccb62012-04-05 21:18:22 +0200835const char sess_cookie[8] = "NIDVEOU7"; /* No cookie, Invalid cookie, cookie for a Down server, Valid cookie, Expired cookie, Old cookie, Unused, unknown */
William Lallemandbddd4fd2012-02-27 11:23:10 +0100836const char sess_set_cookie[8] = "NPDIRU67"; /* No set-cookie, Set-cookie found and left unchanged (passive),
837 Set-cookie Deleted, Set-Cookie Inserted, Set-cookie Rewritten,
838 Set-cookie Updated, unknown, unknown */
839
William Lallemand1d705562012-03-12 12:46:41 +0100840/*
841 * try to write a character if there is enough space, or goto out
842 */
William Lallemandbddd4fd2012-02-27 11:23:10 +0100843#define LOGCHAR(x) do { \
William Lallemand1d705562012-03-12 12:46:41 +0100844 if (tmplog < dst + maxsize - 1) { \
William Lallemandbddd4fd2012-02-27 11:23:10 +0100845 *(tmplog++) = (x); \
846 } else { \
847 goto out; \
848 } \
849 } while(0)
850
William Lallemand1d705562012-03-12 12:46:41 +0100851
Willy Tarreaudf974472012-12-28 02:44:01 +0100852/* Builds a log line in <dst> based on <list_format>, and stops before reaching
853 * <maxsize> characters. Returns the size of the output string in characters,
854 * not counting the trailing zero which is always added if the resulting size
855 * is not zero.
856 */
William Lallemand1d705562012-03-12 12:46:41 +0100857int build_logline(struct session *s, char *dst, size_t maxsize, struct list *list_format)
Willy Tarreaubaaee002006-06-26 02:48:02 +0200858{
Willy Tarreau73de9892006-11-30 11:40:23 +0100859 struct proxy *fe = s->fe;
Willy Tarreauddb358d2006-12-17 22:55:52 +0100860 struct proxy *be = s->be;
William Lallemandbddd4fd2012-02-27 11:23:10 +0100861 struct http_txn *txn = &s->txn;
William Lallemandbddd4fd2012-02-27 11:23:10 +0100862 char *uri;
Willy Tarreaufe944602007-10-25 10:34:16 +0200863 struct tm tm;
William Lallemandbddd4fd2012-02-27 11:23:10 +0100864 int t_request;
865 int hdr;
866 int last_isspace = 1;
Willy Tarreaub1a2faf2012-03-19 16:51:53 +0100867 char *tmplog;
William Lallemand1d705562012-03-12 12:46:41 +0100868 char *ret;
869 int iret;
William Lallemandbddd4fd2012-02-27 11:23:10 +0100870 struct logformat_node *tmp;
Willy Tarreaubaaee002006-06-26 02:48:02 +0200871
William Lallemandbddd4fd2012-02-27 11:23:10 +0100872 /* FIXME: let's limit ourselves to frontend logging for now. */
Willy Tarreaubaaee002006-06-26 02:48:02 +0200873
William Lallemandbddd4fd2012-02-27 11:23:10 +0100874 t_request = -1;
875 if (tv_isge(&s->logs.tv_request, &s->logs.tv_accept))
876 t_request = tv_ms_elapsed(&s->logs.tv_accept, &s->logs.tv_request);
877
William Lallemand1d705562012-03-12 12:46:41 +0100878 tmplog = dst;
Willy Tarreauc9bd0cc2009-05-10 11:57:02 +0200879
William Lallemandbddd4fd2012-02-27 11:23:10 +0100880 /* fill logbuffer */
William Lallemand1d705562012-03-12 12:46:41 +0100881 if (LIST_ISEMPTY(list_format))
882 return 0;
William Lallemandbddd4fd2012-02-27 11:23:10 +0100883
William Lallemand1d705562012-03-12 12:46:41 +0100884 list_for_each_entry(tmp, list_format, list) {
Willy Tarreau4f653562012-10-12 19:48:16 +0200885 const char *src = NULL;
Willy Tarreauc8368452012-12-21 00:09:23 +0100886 struct sample *key;
William Lallemandbddd4fd2012-02-27 11:23:10 +0100887
Willy Tarreauc8368452012-12-21 00:09:23 +0100888 switch (tmp->type) {
William Lallemand1d705562012-03-12 12:46:41 +0100889 case LOG_FMT_SEPARATOR:
William Lallemandbddd4fd2012-02-27 11:23:10 +0100890 if (!last_isspace) {
891 LOGCHAR(' ');
892 last_isspace = 1;
William Lallemandbddd4fd2012-02-27 11:23:10 +0100893 }
894 break;
895
William Lallemand1d705562012-03-12 12:46:41 +0100896 case LOG_FMT_TEXT: // text
William Lallemandbddd4fd2012-02-27 11:23:10 +0100897 src = tmp->arg;
William Lallemand5f232402012-04-05 18:02:55 +0200898 iret = strlcpy2(tmplog, src, dst + maxsize - tmplog);
William Lallemand1d705562012-03-12 12:46:41 +0100899 if (iret == 0)
William Lallemandbddd4fd2012-02-27 11:23:10 +0100900 goto out;
William Lallemand1d705562012-03-12 12:46:41 +0100901 tmplog += iret;
William Lallemandbddd4fd2012-02-27 11:23:10 +0100902 last_isspace = 0;
903 break;
904
Willy Tarreauc8368452012-12-21 00:09:23 +0100905 case LOG_FMT_EXPR: // sample expression, may be request or response
906 key = NULL;
907 if (tmp->options & LOG_OPT_REQ_CAP)
908 key = sample_fetch_string(be, s, txn, SMP_OPT_DIR_REQ|SMP_OPT_FINAL, tmp->expr);
909 if (!key && (tmp->options & LOG_OPT_RES_CAP))
910 key = sample_fetch_string(be, s, txn, SMP_OPT_DIR_RES|SMP_OPT_FINAL, tmp->expr);
911 if (!key)
912 break;
913 ret = lf_text_len(tmplog, key->data.str.str, key->data.str.len, dst + maxsize - tmplog, tmp);
914 if (ret == 0)
915 goto out;
916 tmplog = ret;
917 last_isspace = 0;
918 break;
919
Willy Tarreau2beef582012-12-20 17:22:52 +0100920 case LOG_FMT_CLIENTIP: // %ci
Willy Tarreauf2943dc2012-10-26 20:10:28 +0200921 ret = lf_ip(tmplog, (struct sockaddr *)&s->req->prod->conn->addr.from,
William Lallemand5f232402012-04-05 18:02:55 +0200922 dst + maxsize - tmplog, tmp);
William Lallemand1d705562012-03-12 12:46:41 +0100923 if (ret == NULL)
William Lallemandbddd4fd2012-02-27 11:23:10 +0100924 goto out;
William Lallemand1d705562012-03-12 12:46:41 +0100925 tmplog = ret;
William Lallemandbddd4fd2012-02-27 11:23:10 +0100926 last_isspace = 0;
927 break;
928
Willy Tarreau2beef582012-12-20 17:22:52 +0100929 case LOG_FMT_CLIENTPORT: // %cp
Willy Tarreauf2943dc2012-10-26 20:10:28 +0200930 if (s->req->prod->conn->addr.from.ss_family == AF_UNIX) {
William Lallemand5f232402012-04-05 18:02:55 +0200931 ret = ltoa_o(s->listener->luid, tmplog, dst + maxsize - tmplog);
932 } else {
Willy Tarreauf2943dc2012-10-26 20:10:28 +0200933 ret = lf_port(tmplog, (struct sockaddr *)&s->req->prod->conn->addr.from,
William Lallemand5f232402012-04-05 18:02:55 +0200934 dst + maxsize - tmplog, tmp);
935 }
936 if (ret == NULL)
937 goto out;
938 tmplog = ret;
939 last_isspace = 0;
940 break;
941
Willy Tarreau2beef582012-12-20 17:22:52 +0100942 case LOG_FMT_FRONTENDIP: // %fi
Willy Tarreauf2943dc2012-10-26 20:10:28 +0200943 conn_get_to_addr(s->req->prod->conn);
944 ret = lf_ip(tmplog, (struct sockaddr *)&s->req->prod->conn->addr.to,
William Lallemand5f232402012-04-05 18:02:55 +0200945 dst + maxsize - tmplog, tmp);
William Lallemand1d705562012-03-12 12:46:41 +0100946 if (ret == NULL)
William Lallemandbddd4fd2012-02-27 11:23:10 +0100947 goto out;
William Lallemand1d705562012-03-12 12:46:41 +0100948 tmplog = ret;
William Lallemandbddd4fd2012-02-27 11:23:10 +0100949 last_isspace = 0;
950 break;
951
Willy Tarreau2beef582012-12-20 17:22:52 +0100952 case LOG_FMT_FRONTENDPORT: // %fp
Willy Tarreauf2943dc2012-10-26 20:10:28 +0200953 conn_get_to_addr(s->req->prod->conn);
954 if (s->req->prod->conn->addr.to.ss_family == AF_UNIX) {
William Lallemand5f232402012-04-05 18:02:55 +0200955 ret = ltoa_o(s->listener->luid,
956 tmplog, dst + maxsize - tmplog);
957 } else {
Willy Tarreauf2943dc2012-10-26 20:10:28 +0200958 ret = lf_port(tmplog, (struct sockaddr *)&s->req->prod->conn->addr.to,
William Lallemand5f232402012-04-05 18:02:55 +0200959 dst + maxsize - tmplog, tmp);
960 }
961 if (ret == NULL)
962 goto out;
963 tmplog = ret;
964 last_isspace = 0;
965 break;
966
Willy Tarreau2beef582012-12-20 17:22:52 +0100967 case LOG_FMT_BACKENDIP: // %bi
Willy Tarreauf2943dc2012-10-26 20:10:28 +0200968 ret = lf_ip(tmplog, (struct sockaddr *)&s->req->cons->conn->addr.from,
William Lallemand5f232402012-04-05 18:02:55 +0200969 dst + maxsize - tmplog, tmp);
William Lallemand1d705562012-03-12 12:46:41 +0100970 if (ret == NULL)
William Lallemandb7ff6a32012-03-02 14:35:21 +0100971 goto out;
William Lallemand1d705562012-03-12 12:46:41 +0100972 tmplog = ret;
William Lallemandb7ff6a32012-03-02 14:35:21 +0100973 last_isspace = 0;
974 break;
975
Willy Tarreau2beef582012-12-20 17:22:52 +0100976 case LOG_FMT_BACKENDPORT: // %bp
Willy Tarreauf2943dc2012-10-26 20:10:28 +0200977 ret = lf_port(tmplog, (struct sockaddr *)&s->req->cons->conn->addr.from,
William Lallemand5f232402012-04-05 18:02:55 +0200978 dst + maxsize - tmplog, tmp);
979 if (ret == NULL)
980 goto out;
981 tmplog = ret;
982 last_isspace = 0;
983 break;
984
Willy Tarreau2beef582012-12-20 17:22:52 +0100985 case LOG_FMT_SERVERIP: // %si
Willy Tarreauf2943dc2012-10-26 20:10:28 +0200986 ret = lf_ip(tmplog, (struct sockaddr *)&s->req->cons->conn->addr.to,
William Lallemand5f232402012-04-05 18:02:55 +0200987 dst + maxsize - tmplog, tmp);
988 if (ret == NULL)
989 goto out;
990 tmplog = ret;
991 last_isspace = 0;
992 break;
993
Willy Tarreau2beef582012-12-20 17:22:52 +0100994 case LOG_FMT_SERVERPORT: // %sp
Willy Tarreauf2943dc2012-10-26 20:10:28 +0200995 ret = lf_port(tmplog, (struct sockaddr *)&s->req->cons->conn->addr.to,
William Lallemand5f232402012-04-05 18:02:55 +0200996 dst + maxsize - tmplog, tmp);
William Lallemand1d705562012-03-12 12:46:41 +0100997 if (ret == NULL)
William Lallemandb7ff6a32012-03-02 14:35:21 +0100998 goto out;
William Lallemand1d705562012-03-12 12:46:41 +0100999 tmplog = ret;
William Lallemandb7ff6a32012-03-02 14:35:21 +01001000 last_isspace = 0;
1001 break;
1002
William Lallemand1d705562012-03-12 12:46:41 +01001003 case LOG_FMT_DATE: // %t
William Lallemandbddd4fd2012-02-27 11:23:10 +01001004 get_localtime(s->logs.accept_date.tv_sec, &tm);
William Lallemand5f232402012-04-05 18:02:55 +02001005 ret = date2str_log(tmplog, &tm, &(s->logs.accept_date),
1006 dst + maxsize - tmplog);
William Lallemand1d705562012-03-12 12:46:41 +01001007 if (ret == NULL)
William Lallemandbddd4fd2012-02-27 11:23:10 +01001008 goto out;
William Lallemand1d705562012-03-12 12:46:41 +01001009 tmplog = ret;
William Lallemandbddd4fd2012-02-27 11:23:10 +01001010 last_isspace = 0;
1011 break;
1012
William Lallemand1d705562012-03-12 12:46:41 +01001013 case LOG_FMT_DATEGMT: // %T
William Lallemandbddd4fd2012-02-27 11:23:10 +01001014 get_gmtime(s->logs.accept_date.tv_sec, &tm);
William Lallemand5f232402012-04-05 18:02:55 +02001015 ret = gmt2str_log(tmplog, &tm, dst + maxsize - tmplog);
William Lallemand1d705562012-03-12 12:46:41 +01001016 if (ret == NULL)
William Lallemandbddd4fd2012-02-27 11:23:10 +01001017 goto out;
William Lallemand1d705562012-03-12 12:46:41 +01001018 tmplog = ret;
William Lallemandbddd4fd2012-02-27 11:23:10 +01001019 last_isspace = 0;
1020 break;
1021
Yuxans Yao4e25b012012-10-19 10:36:09 +08001022 case LOG_FMT_DATELOCAL: // %Tl
1023 get_localtime(s->logs.accept_date.tv_sec, &tm);
1024 ret = localdate2str_log(tmplog, &tm, dst + maxsize - tmplog);
1025 if (ret == NULL)
1026 goto out;
1027 tmplog = ret;
1028 last_isspace = 0;
1029 break;
1030
William Lallemand5f232402012-04-05 18:02:55 +02001031 case LOG_FMT_TS: // %Ts
1032 get_gmtime(s->logs.accept_date.tv_sec, &tm);
1033 if (tmp->options & LOG_OPT_HEXA) {
1034 iret = snprintf(tmplog, dst + maxsize - tmplog, "%04X", (unsigned int)s->logs.accept_date.tv_sec);
1035 if (iret < 0 || iret > dst + maxsize - tmplog)
1036 goto out;
1037 last_isspace = 0;
1038 tmplog += iret;
1039 } else {
1040 ret = ltoa_o(s->logs.accept_date.tv_sec, tmplog, dst + maxsize - tmplog);
1041 if (ret == NULL)
1042 goto out;
1043 tmplog = ret;
1044 last_isspace = 0;
1045 }
1046 break;
1047
William Lallemand1d705562012-03-12 12:46:41 +01001048 case LOG_FMT_MS: // %ms
William Lallemand5f232402012-04-05 18:02:55 +02001049 if (tmp->options & LOG_OPT_HEXA) {
1050 iret = snprintf(tmplog, dst + maxsize - tmplog, "%02X",(unsigned int)s->logs.accept_date.tv_usec/1000);
1051 if (iret < 0 || iret > dst + maxsize - tmplog)
1052 goto out;
1053 last_isspace = 0;
1054 tmplog += iret;
1055 } else {
1056 if ((dst + maxsize - tmplog) < 4)
William Lallemandbddd4fd2012-02-27 11:23:10 +01001057 goto out;
Willy Tarreau9e60cd82013-01-24 01:18:16 +01001058 ret = utoa_pad((unsigned int)s->logs.accept_date.tv_usec/1000,
1059 tmplog, 4);
1060 if (ret == NULL)
William Lallemand51b5dca2012-03-26 17:52:55 +02001061 goto out;
Willy Tarreau9e60cd82013-01-24 01:18:16 +01001062 tmplog = ret;
William Lallemandbddd4fd2012-02-27 11:23:10 +01001063 last_isspace = 0;
William Lallemand5f232402012-04-05 18:02:55 +02001064 }
1065 break;
William Lallemandbddd4fd2012-02-27 11:23:10 +01001066
William Lallemand1d705562012-03-12 12:46:41 +01001067 case LOG_FMT_FRONTEND: // %f
William Lallemandbddd4fd2012-02-27 11:23:10 +01001068 src = fe->id;
William Lallemand5f232402012-04-05 18:02:55 +02001069 ret = lf_text(tmplog, src, dst + maxsize - tmplog, tmp);
William Lallemand1d705562012-03-12 12:46:41 +01001070 if (ret == NULL)
William Lallemandbddd4fd2012-02-27 11:23:10 +01001071 goto out;
William Lallemand1d705562012-03-12 12:46:41 +01001072 tmplog = ret;
William Lallemand51b5dca2012-03-26 17:52:55 +02001073 last_isspace = 0;
William Lallemandbddd4fd2012-02-27 11:23:10 +01001074 break;
1075
Willy Tarreau773d65f2012-10-12 14:56:11 +02001076 case LOG_FMT_FRONTEND_XPRT: // %ft
1077 src = fe->id;
1078 if (tmp->options & LOG_OPT_QUOTE)
1079 LOGCHAR('"');
1080 iret = strlcpy2(tmplog, src, dst + maxsize - tmplog);
1081 if (iret == 0)
1082 goto out;
1083 tmplog += iret;
1084#ifdef USE_OPENSSL
1085 if (s->listener->xprt == &ssl_sock)
1086 LOGCHAR('~');
1087#endif
1088 if (tmp->options & LOG_OPT_QUOTE)
1089 LOGCHAR('"');
1090 last_isspace = 0;
1091 break;
Willy Tarreauffc3fcd2012-10-12 20:17:54 +02001092#ifdef USE_OPENSSL
1093 case LOG_FMT_SSL_CIPHER: // %sslc
1094 src = NULL;
1095 if (s->listener->xprt == &ssl_sock)
Willy Tarreauf2943dc2012-10-26 20:10:28 +02001096 src = ssl_sock_get_cipher_name(s->si[0].conn);
Willy Tarreauffc3fcd2012-10-12 20:17:54 +02001097 ret = lf_text(tmplog, src, dst + maxsize - tmplog, tmp);
1098 if (ret == NULL)
1099 goto out;
1100 tmplog = ret;
1101 last_isspace = 0;
1102 break;
Willy Tarreau773d65f2012-10-12 14:56:11 +02001103
Willy Tarreauffc3fcd2012-10-12 20:17:54 +02001104 case LOG_FMT_SSL_VERSION: // %sslv
1105 src = NULL;
1106 if (s->listener->xprt == &ssl_sock)
Willy Tarreauf2943dc2012-10-26 20:10:28 +02001107 src = ssl_sock_get_proto_version(s->si[0].conn);
Willy Tarreauffc3fcd2012-10-12 20:17:54 +02001108 ret = lf_text(tmplog, src, dst + maxsize - tmplog, tmp);
1109 if (ret == NULL)
1110 goto out;
1111 tmplog = ret;
1112 last_isspace = 0;
1113 break;
1114#endif
William Lallemand1d705562012-03-12 12:46:41 +01001115 case LOG_FMT_BACKEND: // %b
William Lallemandbddd4fd2012-02-27 11:23:10 +01001116 src = be->id;
William Lallemand5f232402012-04-05 18:02:55 +02001117 ret = lf_text(tmplog, src, dst + maxsize - tmplog, tmp);
William Lallemand1d705562012-03-12 12:46:41 +01001118 if (ret == NULL)
William Lallemandbddd4fd2012-02-27 11:23:10 +01001119 goto out;
William Lallemand1d705562012-03-12 12:46:41 +01001120 tmplog = ret;
William Lallemand51b5dca2012-03-26 17:52:55 +02001121 last_isspace = 0;
William Lallemandbddd4fd2012-02-27 11:23:10 +01001122 break;
1123
William Lallemand1d705562012-03-12 12:46:41 +01001124 case LOG_FMT_SERVER: // %s
Willy Tarreaud79a3b22012-12-28 09:40:16 +01001125 switch (obj_type(s->target)) {
1126 case OBJ_TYPE_SERVER:
1127 src = objt_server(s->target)->id;
1128 break;
1129 case OBJ_TYPE_APPLET:
1130 src = objt_applet(s->target)->name;
1131 break;
1132 default:
1133 src = "<NOSRV>";
1134 break;
1135 }
William Lallemand5f232402012-04-05 18:02:55 +02001136 ret = lf_text(tmplog, src, dst + maxsize - tmplog, tmp);
William Lallemand1d705562012-03-12 12:46:41 +01001137 if (ret == NULL)
William Lallemandbddd4fd2012-02-27 11:23:10 +01001138 goto out;
William Lallemand1d705562012-03-12 12:46:41 +01001139 tmplog = ret;
William Lallemandbddd4fd2012-02-27 11:23:10 +01001140 last_isspace = 0;
1141 break;
1142
William Lallemand1d705562012-03-12 12:46:41 +01001143 case LOG_FMT_TQ: // %Tq
William Lallemand5f232402012-04-05 18:02:55 +02001144 ret = ltoa_o(t_request, tmplog, dst + maxsize - tmplog);
William Lallemand1d705562012-03-12 12:46:41 +01001145 if (ret == NULL)
William Lallemandbddd4fd2012-02-27 11:23:10 +01001146 goto out;
William Lallemand1d705562012-03-12 12:46:41 +01001147 tmplog = ret;
William Lallemandbddd4fd2012-02-27 11:23:10 +01001148 last_isspace = 0;
1149 break;
1150
William Lallemand1d705562012-03-12 12:46:41 +01001151 case LOG_FMT_TW: // %Tw
1152 ret = ltoa_o((s->logs.t_queue >= 0) ? s->logs.t_queue - t_request : -1,
William Lallemand5f232402012-04-05 18:02:55 +02001153 tmplog, dst + maxsize - tmplog);
William Lallemand1d705562012-03-12 12:46:41 +01001154 if (ret == NULL)
William Lallemandbddd4fd2012-02-27 11:23:10 +01001155 goto out;
William Lallemand1d705562012-03-12 12:46:41 +01001156 tmplog = ret;
William Lallemandbddd4fd2012-02-27 11:23:10 +01001157 last_isspace = 0;
1158 break;
1159
William Lallemand1d705562012-03-12 12:46:41 +01001160 case LOG_FMT_TC: // %Tc
1161 ret = ltoa_o((s->logs.t_connect >= 0) ? s->logs.t_connect - s->logs.t_queue : -1,
William Lallemand5f232402012-04-05 18:02:55 +02001162 tmplog, dst + maxsize - tmplog);
William Lallemand1d705562012-03-12 12:46:41 +01001163 if (ret == NULL)
William Lallemandbddd4fd2012-02-27 11:23:10 +01001164 goto out;
William Lallemand1d705562012-03-12 12:46:41 +01001165 tmplog = ret;
William Lallemandbddd4fd2012-02-27 11:23:10 +01001166 last_isspace = 0;
1167 break;
1168
William Lallemand1d705562012-03-12 12:46:41 +01001169 case LOG_FMT_TR: // %Tr
1170 ret = ltoa_o((s->logs.t_data >= 0) ? s->logs.t_data - s->logs.t_connect : -1,
William Lallemand5f232402012-04-05 18:02:55 +02001171 tmplog, dst + maxsize - tmplog);
William Lallemand1d705562012-03-12 12:46:41 +01001172 if (ret == NULL)
William Lallemandbddd4fd2012-02-27 11:23:10 +01001173 goto out;
William Lallemand1d705562012-03-12 12:46:41 +01001174 tmplog = ret;
William Lallemandbddd4fd2012-02-27 11:23:10 +01001175 last_isspace = 0;
1176 break;
1177
William Lallemand1d705562012-03-12 12:46:41 +01001178 case LOG_FMT_TT: // %Tt
Willy Tarreaud79a3b22012-12-28 09:40:16 +01001179 if (!(fe->to_log & LW_BYTES))
William Lallemand1d705562012-03-12 12:46:41 +01001180 LOGCHAR('+');
William Lallemand5f232402012-04-05 18:02:55 +02001181 ret = ltoa_o(s->logs.t_close, tmplog, dst + maxsize - tmplog);
William Lallemand1d705562012-03-12 12:46:41 +01001182 if (ret == NULL)
William Lallemandbddd4fd2012-02-27 11:23:10 +01001183 goto out;
William Lallemand1d705562012-03-12 12:46:41 +01001184 tmplog = ret;
William Lallemandbddd4fd2012-02-27 11:23:10 +01001185 last_isspace = 0;
1186 break;
1187
Willy Tarreau2beef582012-12-20 17:22:52 +01001188 case LOG_FMT_STATUS: // %ST
William Lallemand5f232402012-04-05 18:02:55 +02001189 ret = ltoa_o(txn->status, tmplog, dst + maxsize - tmplog);
William Lallemand1d705562012-03-12 12:46:41 +01001190 if (ret == NULL)
William Lallemandbddd4fd2012-02-27 11:23:10 +01001191 goto out;
William Lallemand1d705562012-03-12 12:46:41 +01001192 tmplog = ret;
William Lallemandbddd4fd2012-02-27 11:23:10 +01001193 last_isspace = 0;
1194 break;
1195
William Lallemand1d705562012-03-12 12:46:41 +01001196 case LOG_FMT_BYTES: // %B
Willy Tarreaud79a3b22012-12-28 09:40:16 +01001197 if (!(fe->to_log & LW_BYTES))
William Lallemand1d705562012-03-12 12:46:41 +01001198 LOGCHAR('+');
William Lallemand5f232402012-04-05 18:02:55 +02001199 ret = lltoa(s->logs.bytes_out, tmplog, dst + maxsize - tmplog);
William Lallemand1d705562012-03-12 12:46:41 +01001200 if (ret == NULL)
William Lallemandbddd4fd2012-02-27 11:23:10 +01001201 goto out;
William Lallemand1d705562012-03-12 12:46:41 +01001202 tmplog = ret;
William Lallemandbddd4fd2012-02-27 11:23:10 +01001203 last_isspace = 0;
1204 break;
1205
Willy Tarreauc5259fd2012-12-20 15:38:04 +01001206 case LOG_FMT_BYTES_UP: // %U
Willy Tarreauc5259fd2012-12-20 15:38:04 +01001207 ret = lltoa(s->logs.bytes_in, tmplog, dst + maxsize - tmplog);
1208 if (ret == NULL)
1209 goto out;
1210 tmplog = ret;
1211 last_isspace = 0;
1212 break;
1213
Willy Tarreau2beef582012-12-20 17:22:52 +01001214 case LOG_FMT_CCLIENT: // %CC
William Lallemandbddd4fd2012-02-27 11:23:10 +01001215 src = txn->cli_cookie;
William Lallemand5f232402012-04-05 18:02:55 +02001216 ret = lf_text(tmplog, src, dst + maxsize - tmplog, tmp);
William Lallemand1d705562012-03-12 12:46:41 +01001217 if (ret == NULL)
William Lallemand51b5dca2012-03-26 17:52:55 +02001218 goto out;
William Lallemand1d705562012-03-12 12:46:41 +01001219 tmplog = ret;
William Lallemandbddd4fd2012-02-27 11:23:10 +01001220 last_isspace = 0;
1221 break;
1222
Willy Tarreau2beef582012-12-20 17:22:52 +01001223 case LOG_FMT_CSERVER: // %CS
William Lallemandbddd4fd2012-02-27 11:23:10 +01001224 src = txn->srv_cookie;
William Lallemand5f232402012-04-05 18:02:55 +02001225 ret = lf_text(tmplog, src, dst + maxsize - tmplog, tmp);
William Lallemand1d705562012-03-12 12:46:41 +01001226 if (ret == NULL)
William Lallemand51b5dca2012-03-26 17:52:55 +02001227 goto out;
William Lallemand1d705562012-03-12 12:46:41 +01001228 tmplog = ret;
William Lallemandbddd4fd2012-02-27 11:23:10 +01001229 last_isspace = 0;
1230 break;
1231
William Lallemand1d705562012-03-12 12:46:41 +01001232 case LOG_FMT_TERMSTATE: // %ts
Willy Tarreau6580c062012-03-12 15:09:42 +01001233 LOGCHAR(sess_term_cond[(s->flags & SN_ERR_MASK) >> SN_ERR_SHIFT]);
1234 LOGCHAR(sess_fin_state[(s->flags & SN_FINST_MASK) >> SN_FINST_SHIFT]);
1235 *tmplog = '\0';
1236 last_isspace = 0;
1237 break;
William Lallemandbddd4fd2012-02-27 11:23:10 +01001238
William Lallemand1d705562012-03-12 12:46:41 +01001239 case LOG_FMT_TERMSTATE_CK: // %tsc, same as TS with cookie state (for mode HTTP)
William Lallemandbddd4fd2012-02-27 11:23:10 +01001240 LOGCHAR(sess_term_cond[(s->flags & SN_ERR_MASK) >> SN_ERR_SHIFT]);
1241 LOGCHAR(sess_fin_state[(s->flags & SN_FINST_MASK) >> SN_FINST_SHIFT]);
Willy Tarreau67402132012-05-31 20:40:20 +02001242 LOGCHAR((be->ck_opts & PR_CK_ANY) ? sess_cookie[(txn->flags & TX_CK_MASK) >> TX_CK_SHIFT] : '-');
1243 LOGCHAR((be->ck_opts & PR_CK_ANY) ? sess_set_cookie[(txn->flags & TX_SCK_MASK) >> TX_SCK_SHIFT] : '-');
William Lallemandbddd4fd2012-02-27 11:23:10 +01001244 last_isspace = 0;
1245 break;
1246
William Lallemand1d705562012-03-12 12:46:41 +01001247 case LOG_FMT_ACTCONN: // %ac
William Lallemand5f232402012-04-05 18:02:55 +02001248 ret = ltoa_o(actconn, tmplog, dst + maxsize - tmplog);
William Lallemand1d705562012-03-12 12:46:41 +01001249 if (ret == NULL)
William Lallemandbddd4fd2012-02-27 11:23:10 +01001250 goto out;
William Lallemand1d705562012-03-12 12:46:41 +01001251 tmplog = ret;
William Lallemandbddd4fd2012-02-27 11:23:10 +01001252 last_isspace = 0;
1253 break;
1254
William Lallemand1d705562012-03-12 12:46:41 +01001255 case LOG_FMT_FECONN: // %fc
William Lallemand5f232402012-04-05 18:02:55 +02001256 ret = ltoa_o(fe->feconn, tmplog, dst + maxsize - tmplog);
William Lallemand1d705562012-03-12 12:46:41 +01001257 if (ret == NULL)
William Lallemandbddd4fd2012-02-27 11:23:10 +01001258 goto out;
William Lallemand1d705562012-03-12 12:46:41 +01001259 tmplog = ret;
William Lallemandbddd4fd2012-02-27 11:23:10 +01001260 last_isspace = 0;
1261 break;
1262
William Lallemand1d705562012-03-12 12:46:41 +01001263 case LOG_FMT_BECONN: // %bc
William Lallemand5f232402012-04-05 18:02:55 +02001264 ret = ltoa_o(be->beconn, tmplog, dst + maxsize - tmplog);
William Lallemand1d705562012-03-12 12:46:41 +01001265 if (ret == NULL)
William Lallemandbddd4fd2012-02-27 11:23:10 +01001266 goto out;
William Lallemand1d705562012-03-12 12:46:41 +01001267 tmplog = ret;
William Lallemandbddd4fd2012-02-27 11:23:10 +01001268 last_isspace = 0;
1269 break;
1270
William Lallemand1d705562012-03-12 12:46:41 +01001271 case LOG_FMT_SRVCONN: // %sc
Willy Tarreau54a08d32012-11-12 01:14:56 +01001272 ret = ultoa_o(objt_server(s->target) ?
Willy Tarreau3fdb3662012-11-12 00:42:33 +01001273 objt_server(s->target)->cur_sess :
William Lallemand5f232402012-04-05 18:02:55 +02001274 0, tmplog, dst + maxsize - tmplog);
William Lallemand1d705562012-03-12 12:46:41 +01001275 if (ret == NULL)
William Lallemandbddd4fd2012-02-27 11:23:10 +01001276 goto out;
William Lallemand1d705562012-03-12 12:46:41 +01001277 tmplog = ret;
William Lallemandbddd4fd2012-02-27 11:23:10 +01001278 last_isspace = 0;
1279 break;
1280
William Lallemand1d705562012-03-12 12:46:41 +01001281 case LOG_FMT_RETRIES: // %rq
William Lallemandbddd4fd2012-02-27 11:23:10 +01001282 if (s->flags & SN_REDISP)
William Lallemand1d705562012-03-12 12:46:41 +01001283 LOGCHAR('+');
1284 ret = ltoa_o((s->req->cons->conn_retries>0) ?
1285 (be->conn_retries - s->req->cons->conn_retries) :
William Lallemand5f232402012-04-05 18:02:55 +02001286 be->conn_retries, tmplog, dst + maxsize - tmplog);
William Lallemand1d705562012-03-12 12:46:41 +01001287 if (ret == NULL)
William Lallemand51b5dca2012-03-26 17:52:55 +02001288 goto out;
William Lallemand1d705562012-03-12 12:46:41 +01001289 tmplog = ret;
William Lallemandbddd4fd2012-02-27 11:23:10 +01001290 last_isspace = 0;
1291 break;
1292
William Lallemand1d705562012-03-12 12:46:41 +01001293 case LOG_FMT_SRVQUEUE: // %sq
William Lallemand5f232402012-04-05 18:02:55 +02001294 ret = ltoa_o(s->logs.srv_queue_size, tmplog, dst + maxsize - tmplog);
William Lallemand1d705562012-03-12 12:46:41 +01001295 if (ret == NULL)
William Lallemandbddd4fd2012-02-27 11:23:10 +01001296 goto out;
William Lallemand1d705562012-03-12 12:46:41 +01001297 tmplog = ret;
William Lallemandbddd4fd2012-02-27 11:23:10 +01001298 last_isspace = 0;
1299 break;
1300
William Lallemand1d705562012-03-12 12:46:41 +01001301 case LOG_FMT_BCKQUEUE: // %bq
William Lallemand5f232402012-04-05 18:02:55 +02001302 ret = ltoa_o(s->logs.prx_queue_size, tmplog, dst + maxsize - tmplog);
William Lallemand1d705562012-03-12 12:46:41 +01001303 if (ret == NULL)
William Lallemandbddd4fd2012-02-27 11:23:10 +01001304 goto out;
William Lallemand1d705562012-03-12 12:46:41 +01001305 tmplog = ret;
William Lallemandbddd4fd2012-02-27 11:23:10 +01001306 last_isspace = 0;
1307 break;
1308
William Lallemand1d705562012-03-12 12:46:41 +01001309 case LOG_FMT_HDRREQUEST: // %hr
William Lallemandbddd4fd2012-02-27 11:23:10 +01001310 /* request header */
Willy Tarreaud79a3b22012-12-28 09:40:16 +01001311 if (fe->nb_req_cap && txn->req.cap) {
William Lallemandbddd4fd2012-02-27 11:23:10 +01001312 if (tmp->options & LOG_OPT_QUOTE)
1313 LOGCHAR('"');
1314 LOGCHAR('{');
1315 for (hdr = 0; hdr < fe->nb_req_cap; hdr++) {
1316 if (hdr)
1317 LOGCHAR('|');
William Lallemand51b5dca2012-03-26 17:52:55 +02001318 if (txn->req.cap[hdr] != NULL) {
William Lallemand1d705562012-03-12 12:46:41 +01001319 ret = encode_string(tmplog, dst + maxsize,
William Lallemandbddd4fd2012-02-27 11:23:10 +01001320 '#', hdr_encode_map, txn->req.cap[hdr]);
William Lallemand1d705562012-03-12 12:46:41 +01001321 if (ret == NULL || *ret != '\0')
William Lallemand51b5dca2012-03-26 17:52:55 +02001322 goto out;
William Lallemand1d705562012-03-12 12:46:41 +01001323 tmplog = ret;
William Lallemand51b5dca2012-03-26 17:52:55 +02001324 }
William Lallemandbddd4fd2012-02-27 11:23:10 +01001325 }
1326 LOGCHAR('}');
William Lallemand51b5dca2012-03-26 17:52:55 +02001327 if (tmp->options & LOG_OPT_QUOTE)
1328 LOGCHAR('"');
William Lallemandbddd4fd2012-02-27 11:23:10 +01001329 last_isspace = 0;
William Lallemand1d705562012-03-12 12:46:41 +01001330 if (tmp->options & LOG_OPT_QUOTE)
1331 LOGCHAR('"');
William Lallemandbddd4fd2012-02-27 11:23:10 +01001332 }
William Lallemandbddd4fd2012-02-27 11:23:10 +01001333 break;
1334
William Lallemand1d705562012-03-12 12:46:41 +01001335 case LOG_FMT_HDRREQUESTLIST: // %hrl
William Lallemandbddd4fd2012-02-27 11:23:10 +01001336 /* request header list */
Willy Tarreaud79a3b22012-12-28 09:40:16 +01001337 if (fe->nb_req_cap && txn->req.cap) {
William Lallemandbddd4fd2012-02-27 11:23:10 +01001338 for (hdr = 0; hdr < fe->nb_req_cap; hdr++) {
1339 if (hdr > 0)
1340 LOGCHAR(' ');
1341 if (tmp->options & LOG_OPT_QUOTE)
1342 LOGCHAR('"');
1343 if (txn->req.cap[hdr] != NULL) {
William Lallemand1d705562012-03-12 12:46:41 +01001344 ret = encode_string(tmplog, dst + maxsize,
William Lallemandbddd4fd2012-02-27 11:23:10 +01001345 '#', hdr_encode_map, txn->req.cap[hdr]);
William Lallemand1d705562012-03-12 12:46:41 +01001346 if (ret == NULL || *ret != '\0')
William Lallemand51b5dca2012-03-26 17:52:55 +02001347 goto out;
William Lallemand1d705562012-03-12 12:46:41 +01001348 tmplog = ret;
William Lallemandbddd4fd2012-02-27 11:23:10 +01001349 } else if (!(tmp->options & LOG_OPT_QUOTE))
1350 LOGCHAR('-');
1351 if (tmp->options & LOG_OPT_QUOTE)
1352 LOGCHAR('"');
William Lallemandbddd4fd2012-02-27 11:23:10 +01001353 last_isspace = 0;
1354 }
1355 }
1356 break;
Willy Tarreaubaaee002006-06-26 02:48:02 +02001357
William Lallemand1d705562012-03-12 12:46:41 +01001358
1359 case LOG_FMT_HDRRESPONS: // %hs
William Lallemandbddd4fd2012-02-27 11:23:10 +01001360 /* response header */
Willy Tarreaud79a3b22012-12-28 09:40:16 +01001361 if (fe->nb_rsp_cap && txn->rsp.cap) {
William Lallemandbddd4fd2012-02-27 11:23:10 +01001362 if (tmp->options & LOG_OPT_QUOTE)
1363 LOGCHAR('"');
1364 LOGCHAR('{');
1365 for (hdr = 0; hdr < fe->nb_rsp_cap; hdr++) {
1366 if (hdr)
1367 LOGCHAR('|');
William Lallemand51b5dca2012-03-26 17:52:55 +02001368 if (txn->rsp.cap[hdr] != NULL) {
William Lallemand1d705562012-03-12 12:46:41 +01001369 ret = encode_string(tmplog, dst + maxsize,
1370 '#', hdr_encode_map, txn->rsp.cap[hdr]);
1371 if (ret == NULL || *ret != '\0')
William Lallemand51b5dca2012-03-26 17:52:55 +02001372 goto out;
William Lallemand1d705562012-03-12 12:46:41 +01001373 tmplog = ret;
William Lallemand51b5dca2012-03-26 17:52:55 +02001374 }
William Lallemandbddd4fd2012-02-27 11:23:10 +01001375 }
1376 LOGCHAR('}');
1377 last_isspace = 0;
1378 if (tmp->options & LOG_OPT_QUOTE)
1379 LOGCHAR('"');
1380 }
William Lallemandbddd4fd2012-02-27 11:23:10 +01001381 break;
1382
William Lallemand1d705562012-03-12 12:46:41 +01001383 case LOG_FMT_HDRRESPONSLIST: // %hsl
William Lallemandbddd4fd2012-02-27 11:23:10 +01001384 /* response header list */
Willy Tarreaud79a3b22012-12-28 09:40:16 +01001385 if (fe->nb_rsp_cap && txn->rsp.cap) {
William Lallemandbddd4fd2012-02-27 11:23:10 +01001386 for (hdr = 0; hdr < fe->nb_rsp_cap; hdr++) {
1387 if (hdr > 0)
1388 LOGCHAR(' ');
1389 if (tmp->options & LOG_OPT_QUOTE)
1390 LOGCHAR('"');
1391 if (txn->rsp.cap[hdr] != NULL) {
William Lallemand1d705562012-03-12 12:46:41 +01001392 ret = encode_string(tmplog, dst + maxsize,
1393 '#', hdr_encode_map, txn->rsp.cap[hdr]);
1394 if (ret == NULL || *ret != '\0')
William Lallemand51b5dca2012-03-26 17:52:55 +02001395 goto out;
William Lallemand1d705562012-03-12 12:46:41 +01001396 tmplog = ret;
William Lallemandbddd4fd2012-02-27 11:23:10 +01001397 } else if (!(tmp->options & LOG_OPT_QUOTE))
1398 LOGCHAR('-');
1399 if (tmp->options & LOG_OPT_QUOTE)
1400 LOGCHAR('"');
William Lallemandbddd4fd2012-02-27 11:23:10 +01001401 last_isspace = 0;
1402 }
1403 }
1404 break;
1405
William Lallemand1d705562012-03-12 12:46:41 +01001406 case LOG_FMT_REQ: // %r
William Lallemandbddd4fd2012-02-27 11:23:10 +01001407 /* Request */
1408 if (tmp->options & LOG_OPT_QUOTE)
1409 LOGCHAR('"');
1410 uri = txn->uri ? txn->uri : "<BADREQ>";
William Lallemand1d705562012-03-12 12:46:41 +01001411 ret = encode_string(tmplog, dst + maxsize,
William Lallemandbddd4fd2012-02-27 11:23:10 +01001412 '#', url_encode_map, uri);
William Lallemand1d705562012-03-12 12:46:41 +01001413 if (ret == NULL || *ret != '\0')
William Lallemand51b5dca2012-03-26 17:52:55 +02001414 goto out;
William Lallemand1d705562012-03-12 12:46:41 +01001415 tmplog = ret;
William Lallemandbddd4fd2012-02-27 11:23:10 +01001416 if (tmp->options & LOG_OPT_QUOTE)
1417 LOGCHAR('"');
William Lallemandbddd4fd2012-02-27 11:23:10 +01001418 last_isspace = 0;
1419 break;
William Lallemand5f232402012-04-05 18:02:55 +02001420
1421 case LOG_FMT_COUNTER: // %rt
1422 if (tmp->options & LOG_OPT_HEXA) {
1423 iret = snprintf(tmplog, dst + maxsize - tmplog, "%04X", global.req_count);
1424 if (iret < 0 || iret > dst + maxsize - tmplog)
1425 goto out;
1426 last_isspace = 0;
1427 tmplog += iret;
1428 } else {
1429 ret = ltoa_o(global.req_count, tmplog, dst + maxsize - tmplog);
1430 if (ret == NULL)
1431 goto out;
1432 tmplog = ret;
1433 last_isspace = 0;
1434 }
1435 break;
1436
1437 case LOG_FMT_HOSTNAME: // %H
1438 src = hostname;
1439 ret = lf_text(tmplog, src, dst + maxsize - tmplog, tmp);
1440 if (ret == NULL)
1441 goto out;
1442 tmplog = ret;
1443 last_isspace = 0;
1444 break;
1445
1446 case LOG_FMT_PID: // %pid
1447 if (tmp->options & LOG_OPT_HEXA) {
1448 iret = snprintf(tmplog, dst + maxsize - tmplog, "%04X", pid);
1449 if (iret < 0 || iret > dst + maxsize - tmplog)
1450 goto out;
1451 last_isspace = 0;
1452 tmplog += iret;
1453 } else {
1454 ret = ltoa_o(pid, tmplog, dst + maxsize - tmplog);
1455 if (ret == NULL)
1456 goto out;
1457 tmplog = ret;
1458 last_isspace = 0;
1459 }
1460 break;
William Lallemanda73203e2012-03-12 12:48:57 +01001461
1462 case LOG_FMT_UNIQUEID: // %ID
1463 src = s->unique_id;
1464 ret = lf_text(tmplog, src, maxsize - (tmplog - dst), tmp);
1465 if (ret == NULL)
1466 goto out;
1467 tmplog = ret;
1468 last_isspace = 0;
1469 break;
1470
William Lallemandbddd4fd2012-02-27 11:23:10 +01001471 }
1472 }
1473
1474out:
William Lallemand1d705562012-03-12 12:46:41 +01001475 /* *tmplog is a unused character */
1476 *tmplog = '\0';
Willy Tarreaudf974472012-12-28 02:44:01 +01001477 return tmplog - dst;
William Lallemandbddd4fd2012-02-27 11:23:10 +01001478
Willy Tarreaubaaee002006-06-26 02:48:02 +02001479}
1480
William Lallemand1d705562012-03-12 12:46:41 +01001481/*
1482 * send a log for the session when we have enough info about it.
1483 * Will not log if the frontend has no log defined.
1484 */
1485void sess_log(struct session *s)
1486{
1487 char *tmplog;
1488 int size, err, level;
1489
1490 /* if we don't want to log normal traffic, return now */
1491 err = (s->flags & (SN_ERR_MASK | SN_REDISP)) ||
1492 (s->req->cons->conn_retries != s->be->conn_retries) ||
1493 ((s->fe->mode == PR_MODE_HTTP) && s->txn.status >= 500);
Willy Tarreaubaaee002006-06-26 02:48:02 +02001494
William Lallemand1d705562012-03-12 12:46:41 +01001495 if (!err && (s->fe->options2 & PR_O2_NOLOGNORM))
1496 return;
William Lallemandbddd4fd2012-02-27 11:23:10 +01001497
William Lallemand1d705562012-03-12 12:46:41 +01001498 if (LIST_ISEMPTY(&s->fe->logsrvs))
1499 return;
William Lallemandbddd4fd2012-02-27 11:23:10 +01001500
William Lallemand1d705562012-03-12 12:46:41 +01001501 level = LOG_INFO;
1502 if (err && (s->fe->options2 & PR_O2_LOGERRORS))
1503 level = LOG_ERR;
1504
1505 tmplog = update_log_hdr();
1506 size = tmplog - logline;
1507 size += build_logline(s, tmplog, sizeof(logline) - size, &s->fe->logformat);
1508 if (size > 0) {
Willy Tarreaudf974472012-12-28 02:44:01 +01001509 __send_log(s->fe, level, logline, size + 1);
William Lallemand1d705562012-03-12 12:46:41 +01001510 s->logs.logwait = 0;
1511 }
1512}
William Lallemandbddd4fd2012-02-27 11:23:10 +01001513
Willy Tarreaubaaee002006-06-26 02:48:02 +02001514/*
1515 * Local variables:
1516 * c-indent-level: 8
1517 * c-basic-offset: 8
1518 * End:
1519 */