blob: 3bcfaa56b9bdf63ac9de93cab8039deb458b47b2 [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 Tarreauc8f24f82007-11-30 18:38:35 +010013#include <fcntl.h>
Willy Tarreaubaaee002006-06-26 02:48:02 +020014#include <stdarg.h>
15#include <stdio.h>
16#include <stdlib.h>
17#include <string.h>
18#include <syslog.h>
19#include <time.h>
20#include <unistd.h>
Robert Tsai81ae1952007-12-05 10:47:29 +010021#include <errno.h>
Willy Tarreaubaaee002006-06-26 02:48:02 +020022
23#include <sys/time.h>
24
Willy Tarreaue3ba5f02006-06-29 18:54:54 +020025#include <common/config.h>
Willy Tarreaud6d06902009-08-19 11:22:33 +020026#include <common/compat.h>
Willy Tarreau2dd0d472006-06-29 17:53:05 +020027#include <common/standard.h>
Willy Tarreaufb278672006-10-15 15:38:50 +020028#include <common/time.h>
Willy Tarreaubaaee002006-06-26 02:48:02 +020029
Willy Tarreaubaaee002006-06-26 02:48:02 +020030#include <types/global.h>
William Lallemand723b73a2012-02-08 16:37:49 +010031#include <types/log.h>
Willy Tarreauec6c5df2008-07-15 00:22:45 +020032
33#include <proto/log.h>
Willy Tarreau827aee92011-03-10 16:55:02 +010034#include <proto/stream_interface.h>
Willy Tarreaubaaee002006-06-26 02:48:02 +020035
Willy Tarreaubaaee002006-06-26 02:48:02 +020036const char *log_facilities[NB_LOG_FACILITIES] = {
37 "kern", "user", "mail", "daemon",
38 "auth", "syslog", "lpr", "news",
39 "uucp", "cron", "auth2", "ftp",
40 "ntp", "audit", "alert", "cron2",
41 "local0", "local1", "local2", "local3",
42 "local4", "local5", "local6", "local7"
43};
44
45
46const char *log_levels[NB_LOG_LEVELS] = {
47 "emerg", "alert", "crit", "err",
48 "warning", "notice", "info", "debug"
49};
50
Willy Tarreaua2a64e92011-09-07 23:01:56 +020051const char sess_term_cond[10] = "-cCsSPRIDK"; /* normal, CliTo, CliErr, SrvTo, SrvErr, PxErr, Resource, Internal, Down, Killed */
Willy Tarreaub8750a82006-09-03 09:56:00 +020052const char sess_fin_state[8] = "-RCHDLQT"; /* cliRequest, srvConnect, srvHeader, Data, Last, Queue, Tarpit */
Willy Tarreaubaaee002006-06-26 02:48:02 +020053
William Lallemand723b73a2012-02-08 16:37:49 +010054
55/* log_format */
56struct logformat_type {
57 char *name;
58 int type;
William Lallemandbddd4fd2012-02-27 11:23:10 +010059 int mode;
William Lallemand723b73a2012-02-08 16:37:49 +010060};
61
62/* log_format variable names */
63static const struct logformat_type logformat_keywords[] = {
William Lallemandbddd4fd2012-02-27 11:23:10 +010064 { "o", LOG_GLOBAL, PR_MODE_TCP }, /* global option */
65 { "Ci", LOG_CLIENTIP, PR_MODE_TCP }, /* client ip */
66 { "Cp", LOG_CLIENTPORT, PR_MODE_TCP }, /* client port */
67 { "t", LOG_DATE, PR_MODE_TCP }, /* date */
68 { "T", LOG_DATEGMT, PR_MODE_TCP }, /* date GMT */
69 { "ms", LOG_MS, PR_MODE_TCP }, /* accept date millisecond */
70 { "f", LOG_FRONTEND, PR_MODE_TCP }, /* frontend */
71 { "b", LOG_BACKEND, PR_MODE_TCP }, /* backend */
72 { "s", LOG_SERVER, PR_MODE_TCP }, /* server */
73 { "B", LOG_BYTES, PR_MODE_TCP }, /* bytes read */
74 { "Tq", LOG_TQ, PR_MODE_HTTP }, /* Tq */
75 { "Tw", LOG_TW, PR_MODE_TCP }, /* Tw */
76 { "Tc", LOG_TC, PR_MODE_TCP }, /* Tc */
77 { "Tr", LOG_TR, PR_MODE_HTTP }, /* Tr */
78 { "Tt", LOG_TT, PR_MODE_TCP }, /* Tt */
79 { "st", LOG_STATUS, PR_MODE_HTTP }, /* status code */
80 { "cc", LOG_CCLIENT, PR_MODE_HTTP }, /* client cookie */
81 { "cs", LOG_CSERVER, PR_MODE_HTTP }, /* server cookie */
82 { "ts", LOG_TERMSTATE, PR_MODE_TCP },/* terminaison state */
83 { "ac", LOG_ACTCONN, PR_MODE_TCP }, /* actconn */
84 { "fc", LOG_FECONN, PR_MODE_TCP }, /* feconn */
85 { "bc", LOG_BECONN, PR_MODE_TCP }, /* beconn */
86 { "sc", LOG_SRVCONN, PR_MODE_TCP }, /* srv_conn */
87 { "rc", LOG_RETRIES, PR_MODE_TCP }, /* retries */
88 { "sq", LOG_SRVQUEUE, PR_MODE_TCP }, /* srv_queue */
89 { "bq", LOG_BCKQUEUE, PR_MODE_TCP }, /* backend_queue */
90 { "hr", LOG_HDRREQUEST, PR_MODE_HTTP }, /* header request */
91 { "hs", LOG_HDRRESPONS, PR_MODE_HTTP }, /* header response */
92 { "hrl", LOG_HDRREQUESTLIST, PR_MODE_HTTP }, /* header request list */
93 { "hsl", LOG_HDRRESPONSLIST, PR_MODE_HTTP }, /* header response list */
94 { "r", LOG_REQ, PR_MODE_HTTP }, /* request */
William Lallemand723b73a2012-02-08 16:37:49 +010095 { 0, 0 }
96};
97
98char default_http_log_format[] = "%Ci:%Cp [%t] %f %b/%s %Tq/%Tw/%Tc/%Tr/%Tt %st %B %cc %cs %ts %ac/%fc/%bc/%sc/%rc %sq/%bq %hr %hs %{+Q}r"; // default format
99char clf_http_log_format[] = "%{+Q}o %{-Q}Ci - - [%T] %r %st %B \"\" \"\" %Cp %ms %f %b %s %Tq %Tw %Tc %Tr %Tt %ts %ac %fc %bc %sc %rc %sq %bq %cc %cs %hrl %hsl";
William Lallemandbddd4fd2012-02-27 11:23:10 +0100100char default_tcp_log_format[] = "%Ci:%Cp [%t] %f %b/%s %Tw/%Tc/%Tt %B %ts %ac/%fc/%bc/%sc/%rc %sq/%bq";
William Lallemand723b73a2012-02-08 16:37:49 +0100101char *log_format = NULL;
102
103struct logformat_var_args {
104 char *name;
105 int mask;
106};
107
108struct logformat_var_args var_args_list[] = {
109// global
110 { "M", LOG_OPT_MANDATORY },
111 { "Q", LOG_OPT_QUOTE },
112 { 0, 0 }
113};
114
115/*
116 * Parse args in a logformat_var
117 */
118int parse_logformat_var_args(char *args, struct logformat_node *node)
119{
120 int i = 0;
121 int end = 0;
122 int flags = 0; // 1 = + 2 = -
123 char *sp = NULL; // start pointer
124
125 if (args == NULL)
126 return 1;
127
128 while (1) {
129 if (*args == '\0')
130 end = 1;
131
132 if (*args == '+') {
133 // add flag
134 sp = args + 1;
135 flags = 1;
136 }
137 if (*args == '-') {
138 // delete flag
139 sp = args + 1;
140 flags = 2;
141 }
142
143 if (*args == '\0' || *args == ',') {
144 *args = '\0';
145 for (i = 0; var_args_list[i].name; i++) {
146 if (strcmp(sp, var_args_list[i].name) == 0) {
147 if (flags == 1) {
148 node->options |= var_args_list[i].mask;
149 break;
150 } else if (flags == 2) {
151 node->options &= ~var_args_list[i].mask;
152 break;
153 }
154 }
155 }
156 sp = NULL;
157 if (end)
158 break;
159 }
160 args++;
161 }
162 return 0;
163}
164
165/*
166 * Parse a variable '%varname' or '%{args}varname' in logformat
167 *
168 */
169int parse_logformat_var(char *str, size_t len, struct proxy *curproxy)
170{
171 int i, j;
172 char *arg = NULL; // arguments
173 int fparam = 0;
174 char *name = NULL;
175 struct logformat_node *node = NULL;
176 char varname[255] = { 0 }; // variable name
177 int logformat_options = 0x00000000;
178
William Lallemand723b73a2012-02-08 16:37:49 +0100179 for (i = 1; i < len; i++) { // escape first char %
180 if (!arg && str[i] == '{') {
181 arg = str + i;
182 fparam = 1;
183 } else if (arg && str[i] == '}') {
184 char *tmp = arg;
185 arg = calloc(str + i - tmp, 1); // without {}
186 strncpy(arg, tmp + 1, str + i - tmp - 1); // copy without { and }
187 arg[str + i - tmp - 1] = '\0';
188 fparam = 0;
189 } else if (!name && !fparam) {
190 strncpy(varname, str + i, len - i + 1);
191 varname[len - i] = '\0';
192 for (j = 0; logformat_keywords[j].name; j++) { // search a log type
193 if (strcmp(varname, logformat_keywords[j].name) == 0) {
William Lallemandbddd4fd2012-02-27 11:23:10 +0100194 if (!((logformat_keywords[j].mode == PR_MODE_HTTP) && (curproxy->mode == PR_MODE_TCP))) {
195 node = calloc(1, sizeof(struct logformat_node));
196 node->type = logformat_keywords[j].type;
197 node->options = logformat_options;
198 node->arg = arg;
199 parse_logformat_var_args(node->arg, node);
200 if (node->type == LOG_GLOBAL) {
201 logformat_options = node->options;
202 free(node);
203 } else {
204 LIST_ADDQ(&curproxy->logformat, &node->list);
205 }
206 return 0;
William Lallemand723b73a2012-02-08 16:37:49 +0100207 } else {
William Lallemandbddd4fd2012-02-27 11:23:10 +0100208 Warning("Warning: No such variable name '%s' in this log mode\n", varname);
209 if (arg)
210 free(arg);
211 return -1;
William Lallemand723b73a2012-02-08 16:37:49 +0100212 }
William Lallemand723b73a2012-02-08 16:37:49 +0100213 }
214 }
215 Warning("Warning: No such variable name '%s' in logformat\n", varname);
216 if (arg)
217 free(arg);
218 return -1;
219 }
220 }
221 return -1;
222}
223
224/*
225 * push to the logformat linked list
226 *
227 * start: start pointer
228 * end: end text pointer
229 * type: string type
230 *
231 * LOG_TEXT: copy chars from start to end excluding end.
232 *
233*/
234void add_to_logformat_list(char *start, char *end, int type, struct proxy *curproxy)
235{
236 char *str;
237
238 if (type == LOG_TEXT) { /* type text */
239 struct logformat_node *node = calloc(1, sizeof(struct logformat_node));
240
241 str = calloc(end - start + 1, 1);
242 strncpy(str, start, end - start);
243
244 str[end - start] = '\0';
245 node->arg = str;
246 node->type = LOG_TEXT; // type string
247 LIST_ADDQ(&curproxy->logformat, &node->list);
248 } else if (type == LOG_VARIABLE) { /* type variable */
249 parse_logformat_var(start, end - start, curproxy);
250 } else if (type == LOG_SEPARATOR) {
251 struct logformat_node *node = calloc(1, sizeof(struct logformat_node));
252 node->type = LOG_SEPARATOR;
253 LIST_ADDQ(&curproxy->logformat, &node->list);
254 }
255}
256
257/*
258 * Parse the log_format string and fill a linked list.
259 * Variable name are preceded by % and composed by characters [a-zA-Z0-9]* : %varname
260 * You can set arguments using { } : %{many arguments}varname
261 */
262void parse_logformat_string(char *str, struct proxy *curproxy)
263{
264 char *sp = str; /* start pointer */
265 int cformat = -1; /* current token format : LOG_TEXT, LOG_SEPARATOR, LOG_VARIABLE */
266 int pformat = -1; /* previous token format */
267 struct logformat_node *tmplf, *back;
268
269 /* flush the list first. */
270 list_for_each_entry_safe(tmplf, back, &curproxy->logformat, list) {
271 LIST_DEL(&tmplf->list);
272 free(tmplf);
273 }
274
275 while (1) {
276
277 // push the variable only if formats are different, not
278 // within a variable, and not the first iteration
279 if ((cformat != pformat && cformat != -1 && pformat != -1) || *str == '\0') {
280 if (((pformat != LF_STARTVAR && cformat != LF_VAR) &&
281 (pformat != LF_STARTVAR && cformat != LF_STARG) &&
282 (pformat != LF_STARG && cformat != LF_VAR)) || *str == '\0') {
283 if (pformat > LF_VAR) // unfinished string
284 pformat = LF_TEXT;
285 add_to_logformat_list(sp, str, pformat, curproxy);
286 sp = str;
287 if (*str == '\0')
288 break;
289 }
290 }
291
292 if (cformat != -1)
293 str++; // consume the string, except on the first tour
294
295 pformat = cformat;
296
297 if (*str == '\0') {
298 cformat = LF_STARTVAR; // for breaking in all cases
299 continue;
300 }
301
302 if (pformat == LF_STARTVAR) { // after a %
303 if ( (*str >= 'a' && *str <= 'z') || // parse varname
304 (*str >= 'A' && *str <= 'Z') ||
305 (*str >= '0' && *str <= '9')) {
306 cformat = LF_VAR; // varname
307 continue;
308 } else if (*str == '{') {
309 cformat = LF_STARG; // variable arguments
310 continue;
311 } else { // another unexpected token
312 pformat = LF_TEXT; // redefine the format of the previous token to TEXT
313 cformat = LF_TEXT;
314 continue;
315 }
316
317 } else if (pformat == LF_VAR) { // after a varname
318 if ( (*str >= 'a' && *str <= 'z') || // parse varname
319 (*str >= 'A' && *str <= 'Z') ||
320 (*str >= '0' && *str <= '9')) {
321 cformat = LF_VAR;
322 continue;
323 }
324 } else if (pformat == LF_STARG) { // inside variable arguments
325 if (*str == '}') { // end of varname
326 cformat = LF_EDARG;
327 continue;
328 } else { // all tokens are acceptable within { }
329 cformat = LF_STARG;
330 continue;
331 }
332 } else if (pformat == LF_EDARG) { // after arguments
333 if ( (*str >= 'a' && *str <= 'z') || // parse a varname
334 (*str >= 'A' && *str <= 'Z') ||
335 (*str >= '0' && *str <= '9')) {
336 cformat = LF_VAR;
337 continue;
338 } else { // if no varname after arguments, transform in TEXT
339 pformat = LF_TEXT;
340 cformat = LF_TEXT;
341 }
342 }
343
344 // others tokens that don't match previous conditions
345 if (*str == '%') {
346 cformat = LF_STARTVAR;
347 } else if (*str == ' ') {
348 cformat = LF_SEPARATOR;
349 } else {
350 cformat = LF_TEXT;
351 }
352 }
353}
354
Willy Tarreaubaaee002006-06-26 02:48:02 +0200355/*
356 * Displays the message on stderr with the date and pid. Overrides the quiet
357 * mode during startup.
358 */
Willy Tarreaub17916e2006-10-15 15:17:57 +0200359void Alert(const char *fmt, ...)
Willy Tarreaubaaee002006-06-26 02:48:02 +0200360{
361 va_list argp;
Willy Tarreaufe944602007-10-25 10:34:16 +0200362 struct tm tm;
Willy Tarreaubaaee002006-06-26 02:48:02 +0200363
364 if (!(global.mode & MODE_QUIET) || (global.mode & (MODE_VERBOSE | MODE_STARTING))) {
365 va_start(argp, fmt);
366
Willy Tarreaub7f694f2008-06-22 17:18:02 +0200367 get_localtime(date.tv_sec, &tm);
Willy Tarreaubaaee002006-06-26 02:48:02 +0200368 fprintf(stderr, "[ALERT] %03d/%02d%02d%02d (%d) : ",
Willy Tarreaufe944602007-10-25 10:34:16 +0200369 tm.tm_yday, tm.tm_hour, tm.tm_min, tm.tm_sec, (int)getpid());
Willy Tarreaubaaee002006-06-26 02:48:02 +0200370 vfprintf(stderr, fmt, argp);
371 fflush(stderr);
372 va_end(argp);
373 }
374}
375
376
377/*
378 * Displays the message on stderr with the date and pid.
379 */
Willy Tarreaub17916e2006-10-15 15:17:57 +0200380void Warning(const char *fmt, ...)
Willy Tarreaubaaee002006-06-26 02:48:02 +0200381{
382 va_list argp;
Willy Tarreaufe944602007-10-25 10:34:16 +0200383 struct tm tm;
Willy Tarreaubaaee002006-06-26 02:48:02 +0200384
385 if (!(global.mode & MODE_QUIET) || (global.mode & MODE_VERBOSE)) {
386 va_start(argp, fmt);
387
Willy Tarreaub7f694f2008-06-22 17:18:02 +0200388 get_localtime(date.tv_sec, &tm);
Willy Tarreaubaaee002006-06-26 02:48:02 +0200389 fprintf(stderr, "[WARNING] %03d/%02d%02d%02d (%d) : ",
Willy Tarreaufe944602007-10-25 10:34:16 +0200390 tm.tm_yday, tm.tm_hour, tm.tm_min, tm.tm_sec, (int)getpid());
Willy Tarreaubaaee002006-06-26 02:48:02 +0200391 vfprintf(stderr, fmt, argp);
392 fflush(stderr);
393 va_end(argp);
394 }
395}
396
397/*
398 * Displays the message on <out> only if quiet mode is not set.
399 */
Willy Tarreaub17916e2006-10-15 15:17:57 +0200400void qfprintf(FILE *out, const char *fmt, ...)
Willy Tarreaubaaee002006-06-26 02:48:02 +0200401{
402 va_list argp;
403
404 if (!(global.mode & MODE_QUIET) || (global.mode & MODE_VERBOSE)) {
405 va_start(argp, fmt);
406 vfprintf(out, fmt, argp);
407 fflush(out);
408 va_end(argp);
409 }
410}
411
412/*
413 * returns log level for <lev> or -1 if not found.
414 */
415int get_log_level(const char *lev)
416{
417 int level;
418
419 level = NB_LOG_LEVELS - 1;
420 while (level >= 0 && strcmp(log_levels[level], lev))
421 level--;
422
423 return level;
424}
425
426
427/*
428 * returns log facility for <fac> or -1 if not found.
429 */
430int get_log_facility(const char *fac)
431{
432 int facility;
433
434 facility = NB_LOG_FACILITIES - 1;
435 while (facility >= 0 && strcmp(log_facilities[facility], fac))
436 facility--;
William Lallemand2a4a44f2012-02-06 16:00:33 +0100437
Willy Tarreaubaaee002006-06-26 02:48:02 +0200438 return facility;
439}
440
William Lallemanda1cc3812012-02-08 16:38:44 +0100441/*
442 * Write a string in the log string
443 * Take cares of mandatory and quote options
444 *
445 * Return the adress of the \0 character, or NULL on error
446 */
447char *logformat_write_string(char *dst, char *src, size_t size, struct logformat_node *node)
448{
William Lallemandbddd4fd2012-02-27 11:23:10 +0100449 char *orig = dst;
William Lallemanda1cc3812012-02-08 16:38:44 +0100450
William Lallemandbddd4fd2012-02-27 11:23:10 +0100451 if (src == NULL || *src == '\0') {
452 if (node->options & LOG_OPT_QUOTE) {
453 if (size > 2) {
454 *(dst++) = '"';
455 *(dst++) = '"';
456 *dst = '\0';
457 node->options |= LOG_OPT_WRITTEN;
458 } else {
459 dst = NULL;
460 return dst;
461 }
462 } else {
463 if (size > 1) {
464 *(dst++) = '-';
465 *dst = '\0';
466 node->options |= LOG_OPT_WRITTEN;
467 } else { // error no space available
468 dst = NULL;
469 return dst;
470 }
471 }
472 } else {
473 if (node->options & LOG_OPT_QUOTE) {
474 if (size-- > 1 ) {
475 *(dst++) = '"';
476 } else {
477 dst = NULL;
478 return NULL;
479 }
480 dst += strlcpy2(dst, src, size);
481 size -= orig - dst + 1;
482 if (size > 1) {
483 *(dst++) = '"';
484 *dst = '\0';
485 } else {
486 dst = NULL;
487 }
488 } else {
489 dst += strlcpy2(dst, src, size);
490 }
491 }
492 return dst;
William Lallemanda1cc3812012-02-08 16:38:44 +0100493}
494
William Lallemand2a4a44f2012-02-06 16:00:33 +0100495/* generate the syslog header once a second */
496char *hdr_log(char *dst)
Willy Tarreaubaaee002006-06-26 02:48:02 +0200497{
William Lallemand2a4a44f2012-02-06 16:00:33 +0100498 int hdr_len = 0;
Willy Tarreaubaaee002006-06-26 02:48:02 +0200499 static long tvsec = -1; /* to force the string to be initialized */
Willy Tarreaubaaee002006-06-26 02:48:02 +0200500 static char *dataptr = NULL;
Willy Tarreaubaaee002006-06-26 02:48:02 +0200501
Willy Tarreaub7f694f2008-06-22 17:18:02 +0200502 if (unlikely(date.tv_sec != tvsec || dataptr == NULL)) {
Willy Tarreaubaaee002006-06-26 02:48:02 +0200503 /* this string is rebuild only once a second */
Willy Tarreaufe944602007-10-25 10:34:16 +0200504 struct tm tm;
505
Willy Tarreaub7f694f2008-06-22 17:18:02 +0200506 tvsec = date.tv_sec;
Willy Tarreaufe944602007-10-25 10:34:16 +0200507 get_localtime(tvsec, &tm);
Willy Tarreaubaaee002006-06-26 02:48:02 +0200508
William Lallemand2a4a44f2012-02-06 16:00:33 +0100509 hdr_len = snprintf(dst, MAX_SYSLOG_LEN,
Joe Williamsdf5b38f2010-12-29 17:05:48 +0100510 "<<<<>%s %2d %02d:%02d:%02d %s%s[%d]: ",
Willy Tarreaufe944602007-10-25 10:34:16 +0200511 monthname[tm.tm_mon],
512 tm.tm_mday, tm.tm_hour, tm.tm_min, tm.tm_sec,
Joe Williamsdf5b38f2010-12-29 17:05:48 +0100513 global.log_send_hostname ? global.log_send_hostname : "",
Kevinm48936af2010-12-22 16:08:21 +0000514 global.log_tag, pid);
Willy Tarreaubaaee002006-06-26 02:48:02 +0200515 /* WARNING: depending upon implementations, snprintf may return
516 * either -1 or the number of bytes that would be needed to store
517 * the total message. In both cases, we must adjust it.
518 */
William Lallemand2a4a44f2012-02-06 16:00:33 +0100519 if (hdr_len < 0 || hdr_len > MAX_SYSLOG_LEN)
520 hdr_len = MAX_SYSLOG_LEN;
Willy Tarreaubaaee002006-06-26 02:48:02 +0200521
William Lallemand2a4a44f2012-02-06 16:00:33 +0100522 dataptr = dst + hdr_len;
Willy Tarreaubaaee002006-06-26 02:48:02 +0200523 }
524
William Lallemand2a4a44f2012-02-06 16:00:33 +0100525 return dataptr;
526}
527
528/*
529 * This function adds a header to the message and sends the syslog message
Willy Tarreau53bf6af2012-02-24 11:46:54 +0100530 * using a printf format string. It expects an LF-terminated message.
William Lallemand2a4a44f2012-02-06 16:00:33 +0100531 */
532void send_log(struct proxy *p, int level, const char *format, ...)
533{
534 va_list argp;
535 static char logmsg[MAX_SYSLOG_LEN];
536 static char *dataptr = NULL;
537 int data_len = 0;
538
539 if (level < 0 || format == NULL)
540 return;
541
542 dataptr = hdr_log(logmsg); /* create header */
543 data_len = dataptr - logmsg;
544
545 va_start(argp, format);
546 data_len += vsnprintf(dataptr, MAX_SYSLOG_LEN, format, argp);
547 if (data_len < 0 || data_len > MAX_SYSLOG_LEN)
548 data_len = MAX_SYSLOG_LEN;
Willy Tarreaubaaee002006-06-26 02:48:02 +0200549 va_end(argp);
William Lallemand2a4a44f2012-02-06 16:00:33 +0100550
551 __send_log(p, level, logmsg, data_len);
552}
553
554/*
555 * This function sends a syslog message.
556 * It doesn't care about errors nor does it report them.
Willy Tarreau53bf6af2012-02-24 11:46:54 +0100557 * It overrides the last byte (message[size-1]) with an LF character.
William Lallemand2a4a44f2012-02-06 16:00:33 +0100558 */
559void __send_log(struct proxy *p, int level, char *message, size_t size)
560{
561 static int logfdunix = -1; /* syslog to AF_UNIX socket */
562 static int logfdinet = -1; /* syslog to AF_INET socket */
563 static char *dataptr = NULL;
564 int fac_level;
565 struct list *logsrvs = NULL;
566 struct logsrv *tmp = NULL;
567 int nblogger;
568 char *log_ptr;
569
570 dataptr = message;
Willy Tarreaubaaee002006-06-26 02:48:02 +0200571
572 if (p == NULL) {
William Lallemand0f99e342011-10-12 17:50:54 +0200573 if (!LIST_ISEMPTY(&global.logsrvs)) {
574 logsrvs = &global.logsrvs;
Willy Tarreaubaaee002006-06-26 02:48:02 +0200575 }
576 } else {
William Lallemand0f99e342011-10-12 17:50:54 +0200577 if (!LIST_ISEMPTY(&p->logsrvs)) {
578 logsrvs = &p->logsrvs;
Willy Tarreaubaaee002006-06-26 02:48:02 +0200579 }
Robert Tsai81ae1952007-12-05 10:47:29 +0100580 }
581
William Lallemand0f99e342011-10-12 17:50:54 +0200582 if (!logsrvs)
583 return;
584
William Lallemand2a4a44f2012-02-06 16:00:33 +0100585 message[size - 1] = '\n';
586
Robert Tsai81ae1952007-12-05 10:47:29 +0100587 /* Lazily set up syslog sockets for protocol families of configured
588 * syslog servers. */
William Lallemand0f99e342011-10-12 17:50:54 +0200589 nblogger = 0;
590 list_for_each_entry(tmp, logsrvs, list) {
591 const struct logsrv *logsrv = tmp;
Robert Tsai81ae1952007-12-05 10:47:29 +0100592 int proto, *plogfd;
William Lallemand0f99e342011-10-12 17:50:54 +0200593
David du Colombier11bcb6c2011-03-24 12:23:00 +0100594 if (logsrv->addr.ss_family == AF_UNIX) {
Robert Tsai81ae1952007-12-05 10:47:29 +0100595 proto = 0;
596 plogfd = &logfdunix;
597 } else {
Robert Tsai81ae1952007-12-05 10:47:29 +0100598 proto = IPPROTO_UDP;
599 plogfd = &logfdinet;
600 }
601 if (*plogfd >= 0) {
602 /* socket already created. */
603 continue;
604 }
David du Colombier11bcb6c2011-03-24 12:23:00 +0100605 if ((*plogfd = socket(logsrv->addr.ss_family, SOCK_DGRAM,
Robert Tsai81ae1952007-12-05 10:47:29 +0100606 proto)) < 0) {
607 Alert("socket for logger #%d failed: %s (errno=%d)\n",
608 nblogger + 1, strerror(errno), errno);
609 return;
610 }
611 /* we don't want to receive anything on this socket */
612 setsockopt(*plogfd, SOL_SOCKET, SO_RCVBUF, &zero, sizeof(zero));
613 /* does nothing under Linux, maybe needed for others */
614 shutdown(*plogfd, SHUT_RD);
William Lallemand0f99e342011-10-12 17:50:54 +0200615 nblogger++;
Willy Tarreaubaaee002006-06-26 02:48:02 +0200616 }
617
Robert Tsai81ae1952007-12-05 10:47:29 +0100618 /* Send log messages to syslog server. */
William Lallemand0f99e342011-10-12 17:50:54 +0200619 nblogger = 0;
620 list_for_each_entry(tmp, logsrvs, list) {
621 const struct logsrv *logsrv = tmp;
David du Colombier11bcb6c2011-03-24 12:23:00 +0100622 int *plogfd = logsrv->addr.ss_family == AF_UNIX ?
Robert Tsai81ae1952007-12-05 10:47:29 +0100623 &logfdunix : &logfdinet;
624 int sent;
625
Willy Tarreaubaaee002006-06-26 02:48:02 +0200626 /* we can filter the level of the messages that are sent to each logger */
William Lallemand0f99e342011-10-12 17:50:54 +0200627 if (level > logsrv->level)
Willy Tarreaubaaee002006-06-26 02:48:02 +0200628 continue;
William Lallemandbddd4fd2012-02-27 11:23:10 +0100629
Willy Tarreaubaaee002006-06-26 02:48:02 +0200630 /* For each target, we may have a different facility.
631 * We can also have a different log level for each message.
632 * This induces variations in the message header length.
633 * Since we don't want to recompute it each time, nor copy it every
634 * time, we only change the facility in the pre-computed header,
635 * and we change the pointer to the header accordingly.
636 */
William Lallemand0f99e342011-10-12 17:50:54 +0200637 fac_level = (logsrv->facility << 3) + MAX(level, logsrv->minlvl);
William Lallemand2a4a44f2012-02-06 16:00:33 +0100638 log_ptr = dataptr + 3; /* last digit of the log level */
Willy Tarreaubaaee002006-06-26 02:48:02 +0200639 do {
640 *log_ptr = '0' + fac_level % 10;
641 fac_level /= 10;
642 log_ptr--;
William Lallemand2a4a44f2012-02-06 16:00:33 +0100643 } while (fac_level && log_ptr > dataptr);
Willy Tarreaubaaee002006-06-26 02:48:02 +0200644 *log_ptr = '<';
William Lallemand2a4a44f2012-02-06 16:00:33 +0100645
646 sent = sendto(*plogfd, log_ptr, size,
Willy Tarreau1b4b7ce2011-04-05 16:56:50 +0200647 MSG_DONTWAIT | MSG_NOSIGNAL,
648 (struct sockaddr *)&logsrv->addr, get_addr_len(&logsrv->addr));
Robert Tsai81ae1952007-12-05 10:47:29 +0100649 if (sent < 0) {
650 Alert("sendto logger #%d failed: %s (errno=%d)\n",
651 nblogger, strerror(errno), errno);
652 }
William Lallemand0f99e342011-10-12 17:50:54 +0200653 nblogger++;
Willy Tarreaubaaee002006-06-26 02:48:02 +0200654 }
655}
656
William Lallemandbddd4fd2012-02-27 11:23:10 +0100657extern fd_set hdr_encode_map[];
658extern fd_set url_encode_map[];
659
Willy Tarreaubaaee002006-06-26 02:48:02 +0200660
William Lallemandbddd4fd2012-02-27 11:23:10 +0100661const char sess_cookie[8] = "NIDVEO67"; /* No cookie, Invalid cookie, cookie for a Down server, Valid cookie, Expired cookie, Old cookie, unknown */
662const char sess_set_cookie[8] = "NPDIRU67"; /* No set-cookie, Set-cookie found and left unchanged (passive),
663 Set-cookie Deleted, Set-Cookie Inserted, Set-cookie Rewritten,
664 Set-cookie Updated, unknown, unknown */
665
666#define LOGCHAR(x) do { \
667 if (MAX_SYSLOG_LEN - (tmplog - logline) > 1) { \
668 *(tmplog++) = (x); \
669 } else { \
670 goto out; \
671 } \
672 } while(0)
673
Willy Tarreaubaaee002006-06-26 02:48:02 +0200674/*
William Lallemandbddd4fd2012-02-27 11:23:10 +0100675 * send a log for the session when we have enough info about it.
676 * Will not log if the frontend has no log defined.
Willy Tarreaubaaee002006-06-26 02:48:02 +0200677 */
William Lallemandbddd4fd2012-02-27 11:23:10 +0100678void sess_log(struct session *s)
Willy Tarreaubaaee002006-06-26 02:48:02 +0200679{
Cyril Bontéacd7d632010-11-01 19:26:02 +0100680 char pn[INET6_ADDRSTRLEN];
Willy Tarreau73de9892006-11-30 11:40:23 +0100681 struct proxy *fe = s->fe;
Willy Tarreauddb358d2006-12-17 22:55:52 +0100682 struct proxy *be = s->be;
683 struct proxy *prx_log;
William Lallemandbddd4fd2012-02-27 11:23:10 +0100684 struct http_txn *txn = &s->txn;
Willy Tarreauc9bd0cc2009-05-10 11:57:02 +0200685 int tolog, level, err;
William Lallemandbddd4fd2012-02-27 11:23:10 +0100686 char *uri;
687 const char *svid;
Willy Tarreaufe944602007-10-25 10:34:16 +0200688 struct tm tm;
William Lallemandbddd4fd2012-02-27 11:23:10 +0100689 int t_request;
690 int hdr;
691 int last_isspace = 1;
692 static char logline[MAX_SYSLOG_LEN] = { 0 };
693 static char *tmplog;
694 struct logformat_node *tmp;
Willy Tarreaubaaee002006-06-26 02:48:02 +0200695
Willy Tarreauc9bd0cc2009-05-10 11:57:02 +0200696 /* if we don't want to log normal traffic, return now */
William Lallemandbddd4fd2012-02-27 11:23:10 +0100697 err = (s->flags & (SN_ERR_MASK | SN_REDISP)) ||
698 (s->req->cons->conn_retries != be->conn_retries) ||
699 ((s->fe->mode == PR_MODE_HTTP) && txn->status >= 500);
Willy Tarreauc9bd0cc2009-05-10 11:57:02 +0200700 if (!err && (fe->options2 & PR_O2_NOLOGNORM))
701 return;
702
William Lallemandbddd4fd2012-02-27 11:23:10 +0100703 if (LIST_ISEMPTY(&fe->logsrvs))
Willy Tarreaue7ded1f2009-08-09 10:11:45 +0200704 return;
Willy Tarreaue7ded1f2009-08-09 10:11:45 +0200705 prx_log = fe;
William Lallemandbddd4fd2012-02-27 11:23:10 +0100706
707 if (addr_to_str(&s->req->prod->addr.from, pn, sizeof(pn)) == AF_UNIX)
708 snprintf(pn, sizeof(pn), "unix:%d", s->listener->luid);
709
710 /* FIXME: let's limit ourselves to frontend logging for now. */
Willy Tarreau42250582007-04-01 01:30:43 +0200711 tolog = fe->to_log;
Willy Tarreau71904a42011-02-13 14:30:26 +0100712
713 if (!(tolog & LW_SVID))
714 svid = "-";
Willy Tarreau7b7a8e92011-03-27 19:53:06 +0200715 else switch (s->target.type) {
Willy Tarreau71904a42011-02-13 14:30:26 +0100716 case TARG_TYPE_SERVER:
Willy Tarreau7b7a8e92011-03-27 19:53:06 +0200717 svid = s->target.ptr.s->id;
Willy Tarreau71904a42011-02-13 14:30:26 +0100718 break;
719 case TARG_TYPE_APPLET:
Willy Tarreau7b7a8e92011-03-27 19:53:06 +0200720 svid = s->target.ptr.a->name;
Willy Tarreau71904a42011-02-13 14:30:26 +0100721 break;
722 default:
723 svid = "<NOSRV>";
724 break;
725 }
Willy Tarreaubaaee002006-06-26 02:48:02 +0200726
William Lallemandbddd4fd2012-02-27 11:23:10 +0100727 t_request = -1;
728 if (tv_isge(&s->logs.tv_request, &s->logs.tv_accept))
729 t_request = tv_ms_elapsed(&s->logs.tv_accept, &s->logs.tv_request);
730
Willy Tarreauc9bd0cc2009-05-10 11:57:02 +0200731 level = LOG_INFO;
732 if (err && (fe->options2 & PR_O2_LOGERRORS))
733 level = LOG_ERR;
734
William Lallemandbddd4fd2012-02-27 11:23:10 +0100735 /* fill logbuffer */
736
737 tmplog = logline;
738 tmplog = hdr_log(tmplog);
739
740 list_for_each_entry(tmp, &fe->logformat, list) {
741 char *src = NULL;
742 switch (tmp->type) {
743
744 case LOG_SEPARATOR:
745 if (!last_isspace) {
746 LOGCHAR(' ');
747 last_isspace = 1;
748 *tmplog = '\0';
749 }
750 break;
751
752 case LOG_TEXT: // text
753 src = tmp->arg;
754 tmplog += strlcpy2(tmplog, src, MAX_SYSLOG_LEN - (tmplog - logline));
755 if (!tmplog)
756 goto out;
757 last_isspace = 0;
758 break;
759
760 case LOG_CLIENTIP: // %Ci
761 src = (s->req->prod->addr.from.ss_family == AF_UNIX) ? "unix" : pn;
762 tmplog = logformat_write_string(tmplog, src, MAX_SYSLOG_LEN - (tmplog - logline), tmp);
763
764 if (!tmplog)
765 goto out;
766 last_isspace = 0;
767 break;
768
769 case LOG_CLIENTPORT: // %Cp
770 tmplog = ltoa_o((s->req->prod->addr.from.ss_family == AF_UNIX) ? s->listener->luid : get_host_port(&s->req->prod->addr.from),
771 tmplog, MAX_SYSLOG_LEN - (tmplog - logline));
772 if (!tmplog)
773 goto out;
774 last_isspace = 0;
775 break;
776
777 case LOG_DATE: // %t
778 get_localtime(s->logs.accept_date.tv_sec, &tm);
779 tmplog = date2str_log(tmplog, &tm, &(s->logs.accept_date), MAX_SYSLOG_LEN - (tmplog - logline));
780 if (!tmplog)
781 goto out;
782 last_isspace = 0;
783 break;
784
785 case LOG_DATEGMT: // %T
786 get_gmtime(s->logs.accept_date.tv_sec, &tm);
787 tmplog = gmt2str_log(tmplog, &tm, MAX_SYSLOG_LEN - (tmplog - logline));
788 if (!tmplog)
789 goto out;
790 last_isspace = 0;
791 break;
792
793 case LOG_MS: // %ms
794 if ((MAX_SYSLOG_LEN - (tmplog - logline)) < 4) {
795 tmplog = NULL;
796 goto out;
797 }
798 tmplog = utoa_pad((unsigned int)s->logs.accept_date.tv_usec/1000,
799 tmplog, 4);
800 last_isspace = 0;
801
802 break;
803
804 case LOG_FRONTEND: // %f
805 src = fe->id;
806 tmplog = logformat_write_string(tmplog, src, MAX_SYSLOG_LEN - (tmplog - logline), tmp);
807 if (!tmplog)
808 goto out;
809 last_isspace = 0 ;
810 break;
811
812 case LOG_BACKEND: // %b
813 src = be->id;
814 tmplog = logformat_write_string(tmplog, src, MAX_SYSLOG_LEN - (tmplog - logline), tmp);
815 if (!tmplog)
816 goto out;
817 last_isspace = 0 ;
818 break;
819
820 case LOG_SERVER: // %s
821 src = (char *)svid;
822 tmplog = logformat_write_string(tmplog, src, MAX_SYSLOG_LEN - (tmplog - logline), tmp);
823 if (!tmplog)
824 goto out;
825 last_isspace = 0;
826 break;
827
828 case LOG_TQ: // %Tq
829 tmplog = ltoa_o(t_request, tmplog, MAX_SYSLOG_LEN - (tmplog - logline));
830 if (!tmplog)
831 goto out;
832 last_isspace = 0;
833 break;
834
835 case LOG_TW: // %Tw
836 tmplog = ltoa_o((s->logs.t_queue >= 0) ? s->logs.t_queue - t_request : -1, tmplog, MAX_SYSLOG_LEN - (tmplog - logline));
837 if (!tmplog)
838 goto out;
839 last_isspace = 0;
840 break;
841
842 case LOG_TC: // %Tc
843 tmplog = ltoa_o((s->logs.t_connect >= 0) ? s->logs.t_connect - s->logs.t_queue : -1, tmplog, MAX_SYSLOG_LEN - (tmplog - logline));
844 if (!tmplog)
845 goto out;
846 last_isspace = 0;
847 break;
848
849 case LOG_TR: // %Tr
850 tmplog = ltoa_o((s->logs.t_data >= 0) ? s->logs.t_data - s->logs.t_connect : -1, tmplog, MAX_SYSLOG_LEN - (tmplog - logline));
851 if (!tmplog)
852 goto out;
853 last_isspace = 0;
854 break;
855
856 case LOG_TT: // %Tt
857 if (!(tolog & LW_BYTES))
858 *(tmplog++) = '+';
859 tmplog = ltoa_o(s->logs.t_close, tmplog, MAX_SYSLOG_LEN - (tmplog - logline));
860 if (!tmplog)
861 goto out;
862 last_isspace = 0;
863 break;
864
865 case LOG_STATUS: // %st
866 tmplog = ultoa_o(txn->status, tmplog, MAX_SYSLOG_LEN - (tmplog - logline));
867 if (!tmplog)
868 goto out;
869 last_isspace = 0;
870 break;
871
872 case LOG_BYTES: // %B
873 if (!(tolog & LW_BYTES))
874 *(tmplog++) = '+';
875 tmplog = lltoa(s->logs.bytes_out, tmplog, MAX_SYSLOG_LEN - (tmplog - logline));
876 if (!tmplog)
877 goto out;
878 last_isspace = 0;
879 break;
880
881 case LOG_CCLIENT: // %cc
882 src = txn->cli_cookie;
883 tmplog = logformat_write_string(tmplog, src, MAX_SYSLOG_LEN - (tmplog - logline), tmp);
884 last_isspace = 0;
885 break;
886
887 case LOG_CSERVER: // %cs
888 src = txn->srv_cookie;
889 tmplog = logformat_write_string(tmplog, src, MAX_SYSLOG_LEN - (tmplog - logline), tmp);
890 last_isspace = 0;
891 break;
892
893 case LOG_TERMSTATE: // %ts
894
895 LOGCHAR(sess_term_cond[(s->flags & SN_ERR_MASK) >> SN_ERR_SHIFT]);
896 LOGCHAR(sess_fin_state[(s->flags & SN_FINST_MASK) >> SN_FINST_SHIFT]);
897 if (fe->mode == PR_MODE_HTTP) {
898 LOGCHAR((be->options & PR_O_COOK_ANY) ? sess_cookie[(txn->flags & TX_CK_MASK) >> TX_CK_SHIFT] : '-');
899 LOGCHAR((be->options & PR_O_COOK_ANY) ? sess_set_cookie[(txn->flags & TX_SCK_MASK) >> TX_SCK_SHIFT] : '-');
900 }
901 *tmplog = '\0';
902 last_isspace = 0;
903 break;
904
905 case LOG_ACTCONN: // %ac
906 tmplog = ltoa_o(actconn, tmplog, MAX_SYSLOG_LEN - (tmplog - logline));
907 if (!tmplog)
908 goto out;
909 last_isspace = 0;
910 break;
911
912 case LOG_FECONN: // %fc
913 tmplog = ltoa_o(fe->feconn, tmplog, MAX_SYSLOG_LEN - (tmplog - logline));
914 if (!tmplog)
915 goto out;
916 last_isspace = 0;
917 break;
918
919 case LOG_BECONN: // %bc
920 tmplog = ltoa_o(be->beconn, tmplog, MAX_SYSLOG_LEN - (tmplog - logline));
921 if (!tmplog)
922 goto out;
923 last_isspace = 0;
924 break;
925
926 case LOG_SRVCONN: // %sc
927 tmplog = ultoa_o(target_srv(&s->target) ? target_srv(&s->target)->cur_sess : 0, tmplog, MAX_SYSLOG_LEN - (tmplog - logline));
928 if (!tmplog)
929 goto out;
930 last_isspace = 0;
931 break;
932
933 case LOG_RETRIES: // %rq
934 if (s->flags & SN_REDISP)
935 *(tmplog++) = '+';
936 tmplog = ltoa_o((s->req->cons->conn_retries>0)?(be->conn_retries - s->req->cons->conn_retries):be->conn_retries, tmplog, MAX_SYSLOG_LEN - (tmplog - logline));
937 last_isspace = 0;
938 break;
939
940 case LOG_SRVQUEUE: // %sq
941 tmplog = ltoa_o(s->logs.srv_queue_size, tmplog, MAX_SYSLOG_LEN - (tmplog - logline));
942 if (!tmplog)
943 goto out;
944 last_isspace = 0;
945 break;
946
947 case LOG_BCKQUEUE: // %bq
948 tmplog = ltoa_o(s->logs.prx_queue_size, tmplog, MAX_SYSLOG_LEN - (tmplog - logline));
949 if (!tmplog)
950 goto out;
951 last_isspace = 0;
952 break;
953
954 case LOG_HDRREQUEST: // %hr
955 /* request header */
956 if (fe->to_log & LW_REQHDR && txn->req.cap) {
957 if (tmp->options & LOG_OPT_QUOTE)
958 LOGCHAR('"');
959 LOGCHAR('{');
960 for (hdr = 0; hdr < fe->nb_req_cap; hdr++) {
961 if (hdr)
962 LOGCHAR('|');
963 if (txn->req.cap[hdr] != NULL)
964 tmplog = encode_string(tmplog, logline + MAX_SYSLOG_LEN,
965 '#', hdr_encode_map, txn->req.cap[hdr]);
966 }
967 LOGCHAR('}');
968 last_isspace = 0;
969 }
970 *tmplog = '\0';
971 break;
972
973 case LOG_HDRREQUESTLIST: // %hrl
974 /* request header list */
975 if (fe->to_log & LW_REQHDR && txn->req.cap) {
976 for (hdr = 0; hdr < fe->nb_req_cap; hdr++) {
977 if (hdr > 0)
978 LOGCHAR(' ');
979 if (tmp->options & LOG_OPT_QUOTE)
980 LOGCHAR('"');
981 if (txn->req.cap[hdr] != NULL) {
982 tmplog = encode_string(tmplog, logline + MAX_SYSLOG_LEN,
983 '#', hdr_encode_map, txn->req.cap[hdr]);
984 } else if (!(tmp->options & LOG_OPT_QUOTE))
985 LOGCHAR('-');
986 if (tmp->options & LOG_OPT_QUOTE)
987 LOGCHAR('"');
988 *tmplog = '\0';
989 last_isspace = 0;
990 }
991 }
992 break;
Willy Tarreaubaaee002006-06-26 02:48:02 +0200993
William Lallemandbddd4fd2012-02-27 11:23:10 +0100994 case LOG_HDRRESPONS: // %hs
995 /* response header */
996 if (fe->to_log & LW_RSPHDR &&
997 txn->rsp.cap) {
998 if (tmp->options & LOG_OPT_QUOTE)
999 LOGCHAR('"');
1000 LOGCHAR('{');
1001 for (hdr = 0; hdr < fe->nb_rsp_cap; hdr++) {
1002 if (hdr)
1003 LOGCHAR('|');
1004 if (txn->rsp.cap[hdr] != NULL)
1005 tmplog = encode_string(tmplog, logline + MAX_SYSLOG_LEN,
1006 '#', hdr_encode_map, txn->rsp.cap[hdr]);
1007 }
1008 LOGCHAR('}');
1009 last_isspace = 0;
1010 if (tmp->options & LOG_OPT_QUOTE)
1011 LOGCHAR('"');
1012 }
1013 *tmplog = '\0';
1014 break;
1015
1016 case LOG_HDRRESPONSLIST: // %hsl
1017 /* response header list */
1018 if (fe->to_log & LW_RSPHDR && txn->rsp.cap) {
1019 for (hdr = 0; hdr < fe->nb_rsp_cap; hdr++) {
1020 if (hdr > 0)
1021 LOGCHAR(' ');
1022 if (tmp->options & LOG_OPT_QUOTE)
1023 LOGCHAR('"');
1024 if (txn->rsp.cap[hdr] != NULL) {
1025 tmplog = encode_string(tmplog, logline + MAX_SYSLOG_LEN,
1026 '#', hdr_encode_map, txn->rsp.cap[hdr]);
1027 } else if (!(tmp->options & LOG_OPT_QUOTE))
1028 LOGCHAR('-');
1029 if (tmp->options & LOG_OPT_QUOTE)
1030 LOGCHAR('"');
1031 *tmplog = '\0';
1032 last_isspace = 0;
1033 }
1034 }
1035 break;
1036
1037 case LOG_REQ: // %r
1038 /* Request */
1039 if (tmp->options & LOG_OPT_QUOTE)
1040 LOGCHAR('"');
1041 uri = txn->uri ? txn->uri : "<BADREQ>";
1042 tmplog = encode_string(tmplog, logline + MAX_SYSLOG_LEN,
1043 '#', url_encode_map, uri);
1044 if (tmp->options & LOG_OPT_QUOTE)
1045 LOGCHAR('"');
1046 *tmplog = '\0';
1047 last_isspace = 0;
1048 break;
1049 }
1050 }
1051
1052out:
1053
1054 if (tmplog == NULL) // if previous error
1055 tmplog = logline + MAX_SYSLOG_LEN - 1;
1056
1057 __send_log(prx_log, level, logline, tmplog - logline + 1);
Willy Tarreaubaaee002006-06-26 02:48:02 +02001058 s->logs.logwait = 0;
William Lallemandbddd4fd2012-02-27 11:23:10 +01001059
Willy Tarreaubaaee002006-06-26 02:48:02 +02001060}
1061
Willy Tarreaubaaee002006-06-26 02:48:02 +02001062
William Lallemandbddd4fd2012-02-27 11:23:10 +01001063
1064
1065
Willy Tarreaubaaee002006-06-26 02:48:02 +02001066/*
1067 * Local variables:
1068 * c-indent-level: 8
1069 * c-basic-offset: 8
1070 * End:
1071 */