Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1 | /* |
| 2 | * General logging functions. |
| 3 | * |
Willy Tarreau | b7f694f | 2008-06-22 17:18:02 +0200 | [diff] [blame] | 4 | * Copyright 2000-2008 Willy Tarreau <w@1wt.eu> |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5 | * |
| 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 Tarreau | 8a3f52f | 2012-12-20 21:23:42 +0100 | [diff] [blame] | 13 | #include <ctype.h> |
Willy Tarreau | c8f24f8 | 2007-11-30 18:38:35 +0100 | [diff] [blame] | 14 | #include <fcntl.h> |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 15 | #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 Tsai | 81ae195 | 2007-12-05 10:47:29 +0100 | [diff] [blame] | 22 | #include <errno.h> |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 23 | |
| 24 | #include <sys/time.h> |
| 25 | |
Willy Tarreau | e3ba5f0 | 2006-06-29 18:54:54 +0200 | [diff] [blame] | 26 | #include <common/config.h> |
Willy Tarreau | d6d0690 | 2009-08-19 11:22:33 +0200 | [diff] [blame] | 27 | #include <common/compat.h> |
Willy Tarreau | 2dd0d47 | 2006-06-29 17:53:05 +0200 | [diff] [blame] | 28 | #include <common/standard.h> |
Willy Tarreau | fb27867 | 2006-10-15 15:38:50 +0200 | [diff] [blame] | 29 | #include <common/time.h> |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 30 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 31 | #include <types/global.h> |
William Lallemand | 723b73a | 2012-02-08 16:37:49 +0100 | [diff] [blame] | 32 | #include <types/log.h> |
Willy Tarreau | ec6c5df | 2008-07-15 00:22:45 +0200 | [diff] [blame] | 33 | |
William Lallemand | 5f23240 | 2012-04-05 18:02:55 +0200 | [diff] [blame] | 34 | #include <proto/frontend.h> |
Willy Tarreau | ec6c5df | 2008-07-15 00:22:45 +0200 | [diff] [blame] | 35 | #include <proto/log.h> |
Willy Tarreau | c836845 | 2012-12-21 00:09:23 +0100 | [diff] [blame] | 36 | #include <proto/sample.h> |
Willy Tarreau | 827aee9 | 2011-03-10 16:55:02 +0100 | [diff] [blame] | 37 | #include <proto/stream_interface.h> |
Willy Tarreau | 773d65f | 2012-10-12 14:56:11 +0200 | [diff] [blame] | 38 | #ifdef USE_OPENSSL |
| 39 | #include <proto/ssl_sock.h> |
| 40 | #endif |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 41 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 42 | const 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 | |
| 52 | const char *log_levels[NB_LOG_LEVELS] = { |
| 53 | "emerg", "alert", "crit", "err", |
| 54 | "warning", "notice", "info", "debug" |
| 55 | }; |
| 56 | |
Willy Tarreau | 570f221 | 2013-06-10 16:42:09 +0200 | [diff] [blame] | 57 | const char sess_term_cond[16] = "-LcCsSPRIDKUIIII"; /* normal, Local, CliTo, CliErr, SrvTo, SrvErr, PxErr, Resource, Internal, Down, Killed, Up, -- */ |
Willy Tarreau | b8750a8 | 2006-09-03 09:56:00 +0200 | [diff] [blame] | 58 | const char sess_fin_state[8] = "-RCHDLQT"; /* cliRequest, srvConnect, srvHeader, Data, Last, Queue, Tarpit */ |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 59 | |
William Lallemand | 723b73a | 2012-02-08 16:37:49 +0100 | [diff] [blame] | 60 | |
| 61 | /* log_format */ |
| 62 | struct logformat_type { |
| 63 | char *name; |
| 64 | int type; |
William Lallemand | bddd4fd | 2012-02-27 11:23:10 +0100 | [diff] [blame] | 65 | int mode; |
William Lallemand | 5e19a28 | 2012-04-02 16:22:10 +0200 | [diff] [blame] | 66 | int lw; /* logwait bitsfield */ |
William Lallemand | b7ff6a3 | 2012-03-02 14:35:21 +0100 | [diff] [blame] | 67 | int (*config_callback)(struct logformat_node *node, struct proxy *curproxy); |
Willy Tarreau | 2beef58 | 2012-12-20 17:22:52 +0100 | [diff] [blame] | 68 | const char *replace_by; /* new option to use instead of old one */ |
William Lallemand | 723b73a | 2012-02-08 16:37:49 +0100 | [diff] [blame] | 69 | }; |
| 70 | |
William Lallemand | b7ff6a3 | 2012-03-02 14:35:21 +0100 | [diff] [blame] | 71 | int prepare_addrsource(struct logformat_node *node, struct proxy *curproxy); |
| 72 | |
William Lallemand | 723b73a | 2012-02-08 16:37:49 +0100 | [diff] [blame] | 73 | /* log_format variable names */ |
| 74 | static const struct logformat_type logformat_keywords[] = { |
William Lallemand | 5e19a28 | 2012-04-02 16:22:10 +0200 | [diff] [blame] | 75 | { "o", LOG_FMT_GLOBAL, PR_MODE_TCP, 0, NULL }, /* global option */ |
Willy Tarreau | 2beef58 | 2012-12-20 17:22:52 +0100 | [diff] [blame] | 76 | |
| 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 */ |
Willy Tarreau | 4bf9963 | 2014-06-13 12:21:40 +0200 | [diff] [blame] | 83 | { "ST", LOG_FMT_STATUS, PR_MODE_TCP, LW_RESP, NULL }, /* status code */ |
William Lallemand | 5e19a28 | 2012-04-02 16:22:10 +0200 | [diff] [blame] | 84 | { "T", LOG_FMT_DATEGMT, PR_MODE_TCP, LW_INIT, NULL }, /* date GMT */ |
Willy Tarreau | 2beef58 | 2012-12-20 17:22:52 +0100 | [diff] [blame] | 85 | { "Tc", LOG_FMT_TC, PR_MODE_TCP, LW_BYTES, NULL }, /* Tc */ |
Yuxans Yao | 4e25b01 | 2012-10-19 10:36:09 +0800 | [diff] [blame] | 86 | { "Tl", LOG_FMT_DATELOCAL, PR_MODE_TCP, LW_INIT, NULL }, /* date local timezone */ |
William Lallemand | 5e19a28 | 2012-04-02 16:22:10 +0200 | [diff] [blame] | 87 | { "Tq", LOG_FMT_TQ, PR_MODE_HTTP, LW_BYTES, NULL }, /* Tq */ |
William Lallemand | 5e19a28 | 2012-04-02 16:22:10 +0200 | [diff] [blame] | 88 | { "Tr", LOG_FMT_TR, PR_MODE_HTTP, LW_BYTES, NULL }, /* Tr */ |
Willy Tarreau | 2beef58 | 2012-12-20 17:22:52 +0100 | [diff] [blame] | 89 | { "Ts", LOG_FMT_TS, PR_MODE_TCP, LW_INIT, NULL }, /* timestamp GMT */ |
William Lallemand | 5e19a28 | 2012-04-02 16:22:10 +0200 | [diff] [blame] | 90 | { "Tt", LOG_FMT_TT, PR_MODE_TCP, LW_BYTES, NULL }, /* Tt */ |
Willy Tarreau | 2beef58 | 2012-12-20 17:22:52 +0100 | [diff] [blame] | 91 | { "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 Lallemand | 5e19a28 | 2012-04-02 16:22:10 +0200 | [diff] [blame] | 93 | { "ac", LOG_FMT_ACTCONN, PR_MODE_TCP, LW_BYTES, NULL }, /* actconn */ |
Willy Tarreau | 2beef58 | 2012-12-20 17:22:52 +0100 | [diff] [blame] | 94 | { "b", LOG_FMT_BACKEND, PR_MODE_TCP, LW_INIT, NULL }, /* backend */ |
William Lallemand | 5e19a28 | 2012-04-02 16:22:10 +0200 | [diff] [blame] | 95 | { "bc", LOG_FMT_BECONN, PR_MODE_TCP, LW_BYTES, NULL }, /* beconn */ |
Willy Tarreau | 2beef58 | 2012-12-20 17:22:52 +0100 | [diff] [blame] | 96 | { "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 Lallemand | 5e19a28 | 2012-04-02 16:22:10 +0200 | [diff] [blame] | 98 | { "bq", LOG_FMT_BCKQUEUE, PR_MODE_TCP, LW_BYTES, NULL }, /* backend_queue */ |
Willy Tarreau | 2beef58 | 2012-12-20 17:22:52 +0100 | [diff] [blame] | 99 | { "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 */ |
Willy Tarreau | d9ed3d2 | 2014-06-13 12:23:06 +0200 | [diff] [blame] | 106 | { "hr", LOG_FMT_HDRREQUEST, PR_MODE_TCP, LW_REQHDR, NULL }, /* header request */ |
| 107 | { "hrl", LOG_FMT_HDRREQUESTLIST, PR_MODE_TCP, LW_REQHDR, NULL }, /* header request list */ |
| 108 | { "hs", LOG_FMT_HDRRESPONS, PR_MODE_TCP, LW_RSPHDR, NULL }, /* header response */ |
| 109 | { "hsl", LOG_FMT_HDRRESPONSLIST, PR_MODE_TCP, LW_RSPHDR, NULL }, /* header response list */ |
Willy Tarreau | 2beef58 | 2012-12-20 17:22:52 +0100 | [diff] [blame] | 110 | { "ms", LOG_FMT_MS, PR_MODE_TCP, LW_INIT, NULL }, /* accept date millisecond */ |
William Lallemand | 5e19a28 | 2012-04-02 16:22:10 +0200 | [diff] [blame] | 111 | { "pid", LOG_FMT_PID, PR_MODE_TCP, LW_INIT, NULL }, /* log pid */ |
Willy Tarreau | 2beef58 | 2012-12-20 17:22:52 +0100 | [diff] [blame] | 112 | { "r", LOG_FMT_REQ, PR_MODE_HTTP, LW_REQ, NULL }, /* request */ |
| 113 | { "rc", LOG_FMT_RETRIES, PR_MODE_TCP, LW_BYTES, NULL }, /* retries */ |
Willy Tarreau | 1f0da24 | 2014-01-25 11:01:50 +0100 | [diff] [blame] | 114 | { "rt", LOG_FMT_COUNTER, PR_MODE_TCP, LW_REQ, NULL }, /* request counter (HTTP or TCP session) */ |
Willy Tarreau | 2beef58 | 2012-12-20 17:22:52 +0100 | [diff] [blame] | 115 | { "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 Tarreau | ffc3fcd | 2012-10-12 20:17:54 +0200 | [diff] [blame] | 120 | { "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 Tarreau | 2beef58 | 2012-12-20 17:22:52 +0100 | [diff] [blame] | 122 | { "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 Lallemand | 5e19a28 | 2012-04-02 16:22:10 +0200 | [diff] [blame] | 138 | { 0, 0, 0, 0, NULL } |
William Lallemand | 723b73a | 2012-02-08 16:37:49 +0100 | [diff] [blame] | 139 | }; |
| 140 | |
Willy Tarreau | 2beef58 | 2012-12-20 17:22:52 +0100 | [diff] [blame] | 141 | char 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 |
| 142 | char 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"; |
| 143 | char default_tcp_log_format[] = "%ci:%cp [%t] %ft %b/%s %Tw/%Tc/%Tt %B %ts %ac/%fc/%bc/%sc/%rc %sq/%bq"; |
William Lallemand | 723b73a | 2012-02-08 16:37:49 +0100 | [diff] [blame] | 144 | char *log_format = NULL; |
| 145 | |
Willy Tarreau | b1a2faf | 2012-03-19 16:51:53 +0100 | [diff] [blame] | 146 | /* 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 | */ |
| 149 | static char logline[MAX_SYSLOG_LEN]; |
| 150 | |
William Lallemand | 723b73a | 2012-02-08 16:37:49 +0100 | [diff] [blame] | 151 | struct logformat_var_args { |
| 152 | char *name; |
| 153 | int mask; |
| 154 | }; |
| 155 | |
| 156 | struct logformat_var_args var_args_list[] = { |
| 157 | // global |
| 158 | { "M", LOG_OPT_MANDATORY }, |
| 159 | { "Q", LOG_OPT_QUOTE }, |
William Lallemand | 5f23240 | 2012-04-05 18:02:55 +0200 | [diff] [blame] | 160 | { "X", LOG_OPT_HEXA }, |
William Lallemand | 723b73a | 2012-02-08 16:37:49 +0100 | [diff] [blame] | 161 | { 0, 0 } |
| 162 | }; |
| 163 | |
Willy Tarreau | b1f3af2 | 2013-04-12 18:30:32 +0200 | [diff] [blame] | 164 | /* return the name of the directive used in the current proxy for which we're |
| 165 | * currently parsing a header, when it is known. |
| 166 | */ |
| 167 | static inline const char *fmt_directive(const struct proxy *curproxy) |
| 168 | { |
Willy Tarreau | bf0addb | 2013-12-02 12:24:54 +0100 | [diff] [blame] | 169 | switch (curproxy->conf.args.ctx) { |
| 170 | case ARGC_UIF: |
Willy Tarreau | b1f3af2 | 2013-04-12 18:30:32 +0200 | [diff] [blame] | 171 | return "unique-id-format"; |
Willy Tarreau | bf0addb | 2013-12-02 12:24:54 +0100 | [diff] [blame] | 172 | case ARGC_HRQ: |
Thierry FOURNIER | 1c0054f | 2013-11-20 15:09:52 +0100 | [diff] [blame] | 173 | return "http-request"; |
Willy Tarreau | bf0addb | 2013-12-02 12:24:54 +0100 | [diff] [blame] | 174 | case ARGC_HRS: |
Thierry FOURNIER | 1c0054f | 2013-11-20 15:09:52 +0100 | [diff] [blame] | 175 | return "http-response"; |
Willy Tarreau | bf0addb | 2013-12-02 12:24:54 +0100 | [diff] [blame] | 176 | case ARGC_STK: |
| 177 | return "stick"; |
| 178 | case ARGC_TRK: |
| 179 | return "track-sc"; break; |
Thierry FOURNIER | d18cd0f | 2013-11-29 12:15:45 +0100 | [diff] [blame] | 180 | case ARGC_RDR: |
| 181 | return "redirect"; break; |
Willy Tarreau | bf0addb | 2013-12-02 12:24:54 +0100 | [diff] [blame] | 182 | case ARGC_ACL: |
| 183 | return "acl"; break; |
| 184 | default: |
Willy Tarreau | b1f3af2 | 2013-04-12 18:30:32 +0200 | [diff] [blame] | 185 | return "log-format"; |
Willy Tarreau | bf0addb | 2013-12-02 12:24:54 +0100 | [diff] [blame] | 186 | } |
Willy Tarreau | b1f3af2 | 2013-04-12 18:30:32 +0200 | [diff] [blame] | 187 | } |
| 188 | |
William Lallemand | 723b73a | 2012-02-08 16:37:49 +0100 | [diff] [blame] | 189 | /* |
William Lallemand | b7ff6a3 | 2012-03-02 14:35:21 +0100 | [diff] [blame] | 190 | * callback used to configure addr source retrieval |
| 191 | */ |
| 192 | int prepare_addrsource(struct logformat_node *node, struct proxy *curproxy) |
| 193 | { |
| 194 | curproxy->options2 |= PR_O2_SRC_ADDR; |
| 195 | |
| 196 | return 0; |
| 197 | } |
| 198 | |
| 199 | |
| 200 | /* |
William Lallemand | 723b73a | 2012-02-08 16:37:49 +0100 | [diff] [blame] | 201 | * Parse args in a logformat_var |
| 202 | */ |
| 203 | int parse_logformat_var_args(char *args, struct logformat_node *node) |
| 204 | { |
| 205 | int i = 0; |
| 206 | int end = 0; |
| 207 | int flags = 0; // 1 = + 2 = - |
| 208 | char *sp = NULL; // start pointer |
| 209 | |
| 210 | if (args == NULL) |
| 211 | return 1; |
| 212 | |
| 213 | while (1) { |
| 214 | if (*args == '\0') |
| 215 | end = 1; |
| 216 | |
| 217 | if (*args == '+') { |
| 218 | // add flag |
| 219 | sp = args + 1; |
| 220 | flags = 1; |
| 221 | } |
| 222 | if (*args == '-') { |
| 223 | // delete flag |
| 224 | sp = args + 1; |
| 225 | flags = 2; |
| 226 | } |
| 227 | |
| 228 | if (*args == '\0' || *args == ',') { |
| 229 | *args = '\0'; |
Willy Tarreau | 254d44c | 2012-12-20 18:19:26 +0100 | [diff] [blame] | 230 | for (i = 0; sp && var_args_list[i].name; i++) { |
William Lallemand | 723b73a | 2012-02-08 16:37:49 +0100 | [diff] [blame] | 231 | if (strcmp(sp, var_args_list[i].name) == 0) { |
| 232 | if (flags == 1) { |
| 233 | node->options |= var_args_list[i].mask; |
| 234 | break; |
| 235 | } else if (flags == 2) { |
| 236 | node->options &= ~var_args_list[i].mask; |
| 237 | break; |
| 238 | } |
| 239 | } |
| 240 | } |
| 241 | sp = NULL; |
| 242 | if (end) |
| 243 | break; |
| 244 | } |
Willy Tarreau | 254d44c | 2012-12-20 18:19:26 +0100 | [diff] [blame] | 245 | args++; |
William Lallemand | 723b73a | 2012-02-08 16:37:49 +0100 | [diff] [blame] | 246 | } |
| 247 | return 0; |
| 248 | } |
| 249 | |
| 250 | /* |
Willy Tarreau | 8a3f52f | 2012-12-20 21:23:42 +0100 | [diff] [blame] | 251 | * Parse a variable '%varname' or '%{args}varname' in log-format. The caller |
| 252 | * must pass the args part in the <arg> pointer with its length in <arg_len>, |
| 253 | * and varname with its length in <var> and <var_len> respectively. <arg> is |
| 254 | * ignored when arg_len is 0. Neither <var> nor <var_len> may be null. |
William Lallemand | 723b73a | 2012-02-08 16:37:49 +0100 | [diff] [blame] | 255 | */ |
Willy Tarreau | 8a3f52f | 2012-12-20 21:23:42 +0100 | [diff] [blame] | 256 | int parse_logformat_var(char *arg, int arg_len, char *var, int var_len, struct proxy *curproxy, struct list *list_format, int *defoptions) |
William Lallemand | 723b73a | 2012-02-08 16:37:49 +0100 | [diff] [blame] | 257 | { |
Willy Tarreau | 8a3f52f | 2012-12-20 21:23:42 +0100 | [diff] [blame] | 258 | int j; |
| 259 | struct logformat_node *node; |
William Lallemand | 723b73a | 2012-02-08 16:37:49 +0100 | [diff] [blame] | 260 | |
Willy Tarreau | 8a3f52f | 2012-12-20 21:23:42 +0100 | [diff] [blame] | 261 | for (j = 0; logformat_keywords[j].name; j++) { // search a log type |
| 262 | if (strlen(logformat_keywords[j].name) == var_len && |
| 263 | strncmp(var, logformat_keywords[j].name, var_len) == 0) { |
| 264 | if (logformat_keywords[j].mode != PR_MODE_HTTP || curproxy->mode == PR_MODE_HTTP) { |
| 265 | node = calloc(1, sizeof(struct logformat_node)); |
| 266 | node->type = logformat_keywords[j].type; |
| 267 | node->options = *defoptions; |
| 268 | if (arg_len) { |
| 269 | node->arg = my_strndup(arg, arg_len); |
| 270 | parse_logformat_var_args(node->arg, node); |
| 271 | } |
| 272 | if (node->type == LOG_FMT_GLOBAL) { |
| 273 | *defoptions = node->options; |
| 274 | free(node->arg); |
| 275 | free(node); |
| 276 | } else { |
| 277 | if (logformat_keywords[j].config_callback && |
| 278 | logformat_keywords[j].config_callback(node, curproxy) != 0) { |
William Lallemand | bddd4fd | 2012-02-27 11:23:10 +0100 | [diff] [blame] | 279 | return -1; |
William Lallemand | 723b73a | 2012-02-08 16:37:49 +0100 | [diff] [blame] | 280 | } |
Willy Tarreau | 8a3f52f | 2012-12-20 21:23:42 +0100 | [diff] [blame] | 281 | curproxy->to_log |= logformat_keywords[j].lw; |
| 282 | LIST_ADDQ(list_format, &node->list); |
William Lallemand | 723b73a | 2012-02-08 16:37:49 +0100 | [diff] [blame] | 283 | } |
Willy Tarreau | 8a3f52f | 2012-12-20 21:23:42 +0100 | [diff] [blame] | 284 | if (logformat_keywords[j].replace_by) |
Willy Tarreau | 06d97f9 | 2013-12-02 17:45:48 +0100 | [diff] [blame] | 285 | Warning("parsing [%s:%d] : deprecated variable '%s' in '%s', please replace it with '%s'.\n", |
Willy Tarreau | b1f3af2 | 2013-04-12 18:30:32 +0200 | [diff] [blame] | 286 | curproxy->conf.args.file, curproxy->conf.args.line, |
| 287 | logformat_keywords[j].name, fmt_directive(curproxy), logformat_keywords[j].replace_by); |
Willy Tarreau | 8a3f52f | 2012-12-20 21:23:42 +0100 | [diff] [blame] | 288 | return 0; |
| 289 | } else { |
Willy Tarreau | 06d97f9 | 2013-12-02 17:45:48 +0100 | [diff] [blame] | 290 | Warning("parsing [%s:%d] : '%s' : format variable '%s' is reserved for HTTP mode.\n", |
Willy Tarreau | b1f3af2 | 2013-04-12 18:30:32 +0200 | [diff] [blame] | 291 | curproxy->conf.args.file, curproxy->conf.args.line, fmt_directive(curproxy), |
| 292 | logformat_keywords[j].name); |
Willy Tarreau | 8a3f52f | 2012-12-20 21:23:42 +0100 | [diff] [blame] | 293 | return -1; |
William Lallemand | 723b73a | 2012-02-08 16:37:49 +0100 | [diff] [blame] | 294 | } |
William Lallemand | 723b73a | 2012-02-08 16:37:49 +0100 | [diff] [blame] | 295 | } |
| 296 | } |
Willy Tarreau | 8a3f52f | 2012-12-20 21:23:42 +0100 | [diff] [blame] | 297 | |
| 298 | j = var[var_len]; |
| 299 | var[var_len] = 0; |
Willy Tarreau | 06d97f9 | 2013-12-02 17:45:48 +0100 | [diff] [blame] | 300 | Warning("parsing [%s:%d] : no such format variable '%s' in '%s'. If you wanted to emit the '%%' character verbatim, you need to use '%%%%' in log-format expressions.\n", |
Willy Tarreau | b1f3af2 | 2013-04-12 18:30:32 +0200 | [diff] [blame] | 301 | curproxy->conf.args.file, curproxy->conf.args.line, var, fmt_directive(curproxy)); |
Willy Tarreau | 8a3f52f | 2012-12-20 21:23:42 +0100 | [diff] [blame] | 302 | var[var_len] = j; |
William Lallemand | 723b73a | 2012-02-08 16:37:49 +0100 | [diff] [blame] | 303 | return -1; |
| 304 | } |
| 305 | |
| 306 | /* |
| 307 | * push to the logformat linked list |
| 308 | * |
| 309 | * start: start pointer |
| 310 | * end: end text pointer |
| 311 | * type: string type |
William Lallemand | 1d70556 | 2012-03-12 12:46:41 +0100 | [diff] [blame] | 312 | * list_format: destination list |
William Lallemand | 723b73a | 2012-02-08 16:37:49 +0100 | [diff] [blame] | 313 | * |
| 314 | * LOG_TEXT: copy chars from start to end excluding end. |
| 315 | * |
| 316 | */ |
William Lallemand | 1d70556 | 2012-03-12 12:46:41 +0100 | [diff] [blame] | 317 | void add_to_logformat_list(char *start, char *end, int type, struct list *list_format) |
William Lallemand | 723b73a | 2012-02-08 16:37:49 +0100 | [diff] [blame] | 318 | { |
| 319 | char *str; |
| 320 | |
Willy Tarreau | a357166 | 2012-12-20 21:59:12 +0100 | [diff] [blame] | 321 | if (type == LF_TEXT) { /* type text */ |
William Lallemand | 723b73a | 2012-02-08 16:37:49 +0100 | [diff] [blame] | 322 | struct logformat_node *node = calloc(1, sizeof(struct logformat_node)); |
William Lallemand | 723b73a | 2012-02-08 16:37:49 +0100 | [diff] [blame] | 323 | str = calloc(end - start + 1, 1); |
| 324 | strncpy(str, start, end - start); |
William Lallemand | 723b73a | 2012-02-08 16:37:49 +0100 | [diff] [blame] | 325 | str[end - start] = '\0'; |
| 326 | node->arg = str; |
William Lallemand | 1d70556 | 2012-03-12 12:46:41 +0100 | [diff] [blame] | 327 | node->type = LOG_FMT_TEXT; // type string |
| 328 | LIST_ADDQ(list_format, &node->list); |
Willy Tarreau | a357166 | 2012-12-20 21:59:12 +0100 | [diff] [blame] | 329 | } else if (type == LF_SEPARATOR) { |
William Lallemand | 723b73a | 2012-02-08 16:37:49 +0100 | [diff] [blame] | 330 | struct logformat_node *node = calloc(1, sizeof(struct logformat_node)); |
William Lallemand | 1d70556 | 2012-03-12 12:46:41 +0100 | [diff] [blame] | 331 | node->type = LOG_FMT_SEPARATOR; |
| 332 | LIST_ADDQ(list_format, &node->list); |
William Lallemand | 723b73a | 2012-02-08 16:37:49 +0100 | [diff] [blame] | 333 | } |
| 334 | } |
| 335 | |
| 336 | /* |
Willy Tarreau | c836845 | 2012-12-21 00:09:23 +0100 | [diff] [blame] | 337 | * Parse the sample fetch expression <text> and add a node to <list_format> upon |
| 338 | * success. At the moment, sample converters are not yet supported but fetch arguments |
Willy Tarreau | a4312fa | 2013-04-02 16:34:32 +0200 | [diff] [blame] | 339 | * should work. The curpx->conf.args.ctx must be set by the caller. |
Willy Tarreau | c836845 | 2012-12-21 00:09:23 +0100 | [diff] [blame] | 340 | */ |
Thierry FOURNIER | eeaa951 | 2014-02-11 14:00:19 +0100 | [diff] [blame] | 341 | void add_sample_to_logformat_list(char *text, char *arg, int arg_len, struct proxy *curpx, struct list *list_format, int options, int cap, const char *file, int line) |
Willy Tarreau | c836845 | 2012-12-21 00:09:23 +0100 | [diff] [blame] | 342 | { |
| 343 | char *cmd[2]; |
| 344 | struct sample_expr *expr; |
| 345 | struct logformat_node *node; |
| 346 | int cmd_arg; |
Willy Tarreau | 975c178 | 2013-12-12 23:16:54 +0100 | [diff] [blame] | 347 | char *errmsg = NULL; |
Willy Tarreau | c836845 | 2012-12-21 00:09:23 +0100 | [diff] [blame] | 348 | |
| 349 | cmd[0] = text; |
| 350 | cmd[1] = ""; |
| 351 | cmd_arg = 0; |
| 352 | |
Thierry FOURNIER | eeaa951 | 2014-02-11 14:00:19 +0100 | [diff] [blame] | 353 | expr = sample_parse_expr(cmd, &cmd_arg, file, line, &errmsg, &curpx->conf.args); |
Willy Tarreau | c836845 | 2012-12-21 00:09:23 +0100 | [diff] [blame] | 354 | if (!expr) { |
Willy Tarreau | b1f3af2 | 2013-04-12 18:30:32 +0200 | [diff] [blame] | 355 | Warning("parsing [%s:%d] : '%s' : sample fetch <%s> failed with : %s\n", |
| 356 | curpx->conf.args.file, curpx->conf.args.line, fmt_directive(curpx), |
Willy Tarreau | 975c178 | 2013-12-12 23:16:54 +0100 | [diff] [blame] | 357 | text, errmsg); |
Willy Tarreau | c836845 | 2012-12-21 00:09:23 +0100 | [diff] [blame] | 358 | return; |
| 359 | } |
| 360 | |
| 361 | node = calloc(1, sizeof(struct logformat_node)); |
| 362 | node->type = LOG_FMT_EXPR; |
| 363 | node->expr = expr; |
| 364 | node->options = options; |
| 365 | |
| 366 | if (arg_len) { |
| 367 | node->arg = my_strndup(arg, arg_len); |
| 368 | parse_logformat_var_args(node->arg, node); |
| 369 | } |
Willy Tarreau | 434c57c | 2013-01-08 01:10:24 +0100 | [diff] [blame] | 370 | if (expr->fetch->val & cap & SMP_VAL_REQUEST) |
Willy Tarreau | c836845 | 2012-12-21 00:09:23 +0100 | [diff] [blame] | 371 | node->options |= LOG_OPT_REQ_CAP; /* fetch method is request-compatible */ |
| 372 | |
Willy Tarreau | 434c57c | 2013-01-08 01:10:24 +0100 | [diff] [blame] | 373 | if (expr->fetch->val & cap & SMP_VAL_RESPONSE) |
Willy Tarreau | c836845 | 2012-12-21 00:09:23 +0100 | [diff] [blame] | 374 | node->options |= LOG_OPT_RES_CAP; /* fetch method is response-compatible */ |
| 375 | |
Willy Tarreau | 434c57c | 2013-01-08 01:10:24 +0100 | [diff] [blame] | 376 | if (!(expr->fetch->val & cap)) |
Willy Tarreau | b1f3af2 | 2013-04-12 18:30:32 +0200 | [diff] [blame] | 377 | Warning("parsing [%s:%d] : '%s' : sample fetch <%s> may not be reliably used here because it needs '%s' which is not available here.\n", |
| 378 | curpx->conf.args.file, curpx->conf.args.line, fmt_directive(curpx), |
| 379 | text, sample_src_names(expr->fetch->use)); |
Willy Tarreau | 434c57c | 2013-01-08 01:10:24 +0100 | [diff] [blame] | 380 | |
Willy Tarreau | c836845 | 2012-12-21 00:09:23 +0100 | [diff] [blame] | 381 | /* check if we need to allocate an hdr_idx struct for HTTP parsing */ |
| 382 | /* Note, we may also need to set curpx->to_log with certain fetches */ |
Willy Tarreau | 25320b2 | 2013-03-24 07:22:08 +0100 | [diff] [blame] | 383 | curpx->http_needed |= !!(expr->fetch->use & SMP_USE_HTTP_ANY); |
Willy Tarreau | c836845 | 2012-12-21 00:09:23 +0100 | [diff] [blame] | 384 | |
William Lallemand | 65ad6e1 | 2014-01-31 15:08:02 +0100 | [diff] [blame] | 385 | /* FIXME: temporary workaround for missing LW_XPRT and LW_REQ flags |
| 386 | * needed with some sample fetches (eg: ssl*). We always set it for |
| 387 | * now on, but this will leave with sample capabilities soon. |
Willy Tarreau | 1f31c73 | 2013-01-10 16:22:27 +0100 | [diff] [blame] | 388 | */ |
| 389 | curpx->to_log |= LW_XPRT; |
William Lallemand | 65ad6e1 | 2014-01-31 15:08:02 +0100 | [diff] [blame] | 390 | curpx->to_log |= LW_REQ; |
Willy Tarreau | c836845 | 2012-12-21 00:09:23 +0100 | [diff] [blame] | 391 | LIST_ADDQ(list_format, &node->list); |
| 392 | } |
| 393 | |
| 394 | /* |
William Lallemand | 723b73a | 2012-02-08 16:37:49 +0100 | [diff] [blame] | 395 | * Parse the log_format string and fill a linked list. |
| 396 | * Variable name are preceded by % and composed by characters [a-zA-Z0-9]* : %varname |
Willy Tarreau | a4312fa | 2013-04-02 16:34:32 +0200 | [diff] [blame] | 397 | * You can set arguments using { } : %{many arguments}varname. |
| 398 | * The curproxy->conf.args.ctx must be set by the caller. |
William Lallemand | 1d70556 | 2012-03-12 12:46:41 +0100 | [diff] [blame] | 399 | * |
| 400 | * str: the string to parse |
| 401 | * curproxy: the proxy affected |
| 402 | * list_format: the destination list |
Willy Tarreau | 6cbbdbf | 2013-02-05 18:52:25 +0100 | [diff] [blame] | 403 | * options: LOG_OPT_* to force on every node |
Willy Tarreau | 434c57c | 2013-01-08 01:10:24 +0100 | [diff] [blame] | 404 | * cap: all SMP_VAL_* flags supported by the consumer |
William Lallemand | 723b73a | 2012-02-08 16:37:49 +0100 | [diff] [blame] | 405 | */ |
Thierry FOURNIER | eeaa951 | 2014-02-11 14:00:19 +0100 | [diff] [blame] | 406 | void parse_logformat_string(const char *fmt, struct proxy *curproxy, struct list *list_format, int options, int cap, const char *file, int line) |
William Lallemand | 723b73a | 2012-02-08 16:37:49 +0100 | [diff] [blame] | 407 | { |
Willy Tarreau | b83bc1e | 2012-12-24 12:36:33 +0100 | [diff] [blame] | 408 | char *sp, *str, *backfmt; /* start pointer for text parts */ |
Willy Tarreau | 8a3f52f | 2012-12-20 21:23:42 +0100 | [diff] [blame] | 409 | char *arg = NULL; /* start pointer for args */ |
| 410 | char *var = NULL; /* start pointer for vars */ |
| 411 | int arg_len = 0; |
| 412 | int var_len = 0; |
| 413 | int cformat; /* current token format */ |
| 414 | int pformat; /* previous token format */ |
William Lallemand | 723b73a | 2012-02-08 16:37:49 +0100 | [diff] [blame] | 415 | struct logformat_node *tmplf, *back; |
| 416 | |
Willy Tarreau | b83bc1e | 2012-12-24 12:36:33 +0100 | [diff] [blame] | 417 | sp = str = backfmt = strdup(fmt); |
William Lallemand | 1dc00ef | 2012-08-09 16:41:35 +0200 | [diff] [blame] | 418 | curproxy->to_log |= LW_INIT; |
William Lallemand | 5e19a28 | 2012-04-02 16:22:10 +0200 | [diff] [blame] | 419 | |
William Lallemand | 723b73a | 2012-02-08 16:37:49 +0100 | [diff] [blame] | 420 | /* flush the list first. */ |
William Lallemand | 1d70556 | 2012-03-12 12:46:41 +0100 | [diff] [blame] | 421 | list_for_each_entry_safe(tmplf, back, list_format, list) { |
William Lallemand | 723b73a | 2012-02-08 16:37:49 +0100 | [diff] [blame] | 422 | LIST_DEL(&tmplf->list); |
| 423 | free(tmplf); |
| 424 | } |
| 425 | |
Willy Tarreau | 8a3f52f | 2012-12-20 21:23:42 +0100 | [diff] [blame] | 426 | for (cformat = LF_INIT; cformat != LF_END; str++) { |
William Lallemand | 723b73a | 2012-02-08 16:37:49 +0100 | [diff] [blame] | 427 | pformat = cformat; |
| 428 | |
Willy Tarreau | 8a3f52f | 2012-12-20 21:23:42 +0100 | [diff] [blame] | 429 | if (!*str) |
| 430 | cformat = LF_END; // preset it to save all states from doing this |
William Lallemand | 723b73a | 2012-02-08 16:37:49 +0100 | [diff] [blame] | 431 | |
Willy Tarreau | 8a3f52f | 2012-12-20 21:23:42 +0100 | [diff] [blame] | 432 | /* The prinicple of the two-step state machine below is to first detect a change, and |
| 433 | * second have all common paths processed at one place. The common paths are the ones |
| 434 | * encountered in text areas (LF_INIT, LF_TEXT, LF_SEPARATOR) and at the end (LF_END). |
| 435 | * We use the common LF_INIT state to dispatch to the different final states. |
| 436 | */ |
| 437 | switch (pformat) { |
| 438 | case LF_STARTVAR: // text immediately following a '%' |
Willy Tarreau | c836845 | 2012-12-21 00:09:23 +0100 | [diff] [blame] | 439 | arg = NULL; var = NULL; |
Willy Tarreau | 8a3f52f | 2012-12-20 21:23:42 +0100 | [diff] [blame] | 440 | arg_len = var_len = 0; |
| 441 | if (*str == '{') { // optional argument |
| 442 | cformat = LF_STARG; |
| 443 | arg = str + 1; |
William Lallemand | 723b73a | 2012-02-08 16:37:49 +0100 | [diff] [blame] | 444 | } |
Willy Tarreau | c836845 | 2012-12-21 00:09:23 +0100 | [diff] [blame] | 445 | else if (*str == '[') { |
| 446 | cformat = LF_STEXPR; |
| 447 | var = str + 1; // store expr in variable name |
| 448 | } |
Willy Tarreau | 0f28f82 | 2013-12-16 01:38:33 +0100 | [diff] [blame] | 449 | else if (isalpha((unsigned char)*str)) { // variable name |
William Lallemand | 723b73a | 2012-02-08 16:37:49 +0100 | [diff] [blame] | 450 | cformat = LF_VAR; |
Willy Tarreau | 8a3f52f | 2012-12-20 21:23:42 +0100 | [diff] [blame] | 451 | var = str; |
William Lallemand | 723b73a | 2012-02-08 16:37:49 +0100 | [diff] [blame] | 452 | } |
Willy Tarreau | 8a3f52f | 2012-12-20 21:23:42 +0100 | [diff] [blame] | 453 | else if (*str == '%') |
| 454 | cformat = LF_TEXT; // convert this character to a litteral (useful for '%') |
Willy Tarreau | 0f28f82 | 2013-12-16 01:38:33 +0100 | [diff] [blame] | 455 | else if (isdigit((unsigned char)*str) || *str == ' ' || *str == '\t') { |
Willy Tarreau | 06d97f9 | 2013-12-02 17:45:48 +0100 | [diff] [blame] | 456 | /* single '%' followed by blank or digit, send them both */ |
| 457 | cformat = LF_TEXT; |
| 458 | pformat = LF_TEXT; /* finally we include the previous char as well */ |
| 459 | sp = str - 1; /* send both the '%' and the current char */ |
| 460 | Warning("parsing [%s:%d] : Fixed missing '%%' before '%c' at position %d in %s line : '%s'. Please use '%%%%' when you need the '%%' character in a log-format expression.\n", |
| 461 | curproxy->conf.args.file, curproxy->conf.args.line, *str, (int)(str - backfmt), fmt_directive(curproxy), fmt); |
| 462 | |
| 463 | } |
Willy Tarreau | 8a3f52f | 2012-12-20 21:23:42 +0100 | [diff] [blame] | 464 | else |
| 465 | cformat = LF_INIT; // handle other cases of litterals |
| 466 | break; |
| 467 | |
| 468 | case LF_STARG: // text immediately following '%{' |
| 469 | if (*str == '}') { // end of arg |
William Lallemand | 723b73a | 2012-02-08 16:37:49 +0100 | [diff] [blame] | 470 | cformat = LF_EDARG; |
Willy Tarreau | 8a3f52f | 2012-12-20 21:23:42 +0100 | [diff] [blame] | 471 | arg_len = str - arg; |
| 472 | *str = 0; // used for reporting errors |
William Lallemand | 723b73a | 2012-02-08 16:37:49 +0100 | [diff] [blame] | 473 | } |
Willy Tarreau | 8a3f52f | 2012-12-20 21:23:42 +0100 | [diff] [blame] | 474 | break; |
| 475 | |
| 476 | case LF_EDARG: // text immediately following '%{arg}' |
Willy Tarreau | c836845 | 2012-12-21 00:09:23 +0100 | [diff] [blame] | 477 | if (*str == '[') { |
| 478 | cformat = LF_STEXPR; |
| 479 | var = str + 1; // store expr in variable name |
| 480 | break; |
| 481 | } |
Willy Tarreau | 0f28f82 | 2013-12-16 01:38:33 +0100 | [diff] [blame] | 482 | else if (isalnum((unsigned char)*str)) { // variable name |
William Lallemand | 723b73a | 2012-02-08 16:37:49 +0100 | [diff] [blame] | 483 | cformat = LF_VAR; |
Willy Tarreau | 8a3f52f | 2012-12-20 21:23:42 +0100 | [diff] [blame] | 484 | var = str; |
| 485 | break; |
| 486 | } |
Willy Tarreau | b1f3af2 | 2013-04-12 18:30:32 +0200 | [diff] [blame] | 487 | Warning("parsing [%s:%d] : Skipping isolated argument in '%s' line : '%%{%s}'\n", |
| 488 | curproxy->conf.args.file, curproxy->conf.args.line, fmt_directive(curproxy), arg); |
Willy Tarreau | 8a3f52f | 2012-12-20 21:23:42 +0100 | [diff] [blame] | 489 | cformat = LF_INIT; |
| 490 | break; |
| 491 | |
Willy Tarreau | c836845 | 2012-12-21 00:09:23 +0100 | [diff] [blame] | 492 | case LF_STEXPR: // text immediately following '%[' |
| 493 | if (*str == ']') { // end of arg |
| 494 | cformat = LF_EDEXPR; |
| 495 | var_len = str - var; |
| 496 | *str = 0; // needed for parsing the expression |
| 497 | } |
| 498 | break; |
| 499 | |
Willy Tarreau | 8a3f52f | 2012-12-20 21:23:42 +0100 | [diff] [blame] | 500 | case LF_VAR: // text part of a variable name |
| 501 | var_len = str - var; |
Willy Tarreau | 0f28f82 | 2013-12-16 01:38:33 +0100 | [diff] [blame] | 502 | if (!isalnum((unsigned char)*str)) |
Willy Tarreau | 8a3f52f | 2012-12-20 21:23:42 +0100 | [diff] [blame] | 503 | cformat = LF_INIT; // not variable name anymore |
| 504 | break; |
| 505 | |
Willy Tarreau | c836845 | 2012-12-21 00:09:23 +0100 | [diff] [blame] | 506 | default: // LF_INIT, LF_TEXT, LF_SEPARATOR, LF_END, LF_EDEXPR |
Willy Tarreau | 8a3f52f | 2012-12-20 21:23:42 +0100 | [diff] [blame] | 507 | cformat = LF_INIT; |
| 508 | } |
| 509 | |
| 510 | if (cformat == LF_INIT) { /* resynchronize state to text/sep/startvar */ |
| 511 | switch (*str) { |
| 512 | case '%': cformat = LF_STARTVAR; break; |
| 513 | case ' ': cformat = LF_SEPARATOR; break; |
| 514 | case 0 : cformat = LF_END; break; |
| 515 | default : cformat = LF_TEXT; break; |
William Lallemand | 723b73a | 2012-02-08 16:37:49 +0100 | [diff] [blame] | 516 | } |
| 517 | } |
| 518 | |
Willy Tarreau | 8a3f52f | 2012-12-20 21:23:42 +0100 | [diff] [blame] | 519 | if (cformat != pformat || pformat == LF_SEPARATOR) { |
| 520 | switch (pformat) { |
| 521 | case LF_VAR: |
| 522 | parse_logformat_var(arg, arg_len, var, var_len, curproxy, list_format, &options); |
| 523 | break; |
Willy Tarreau | c836845 | 2012-12-21 00:09:23 +0100 | [diff] [blame] | 524 | case LF_STEXPR: |
Thierry FOURNIER | eeaa951 | 2014-02-11 14:00:19 +0100 | [diff] [blame] | 525 | add_sample_to_logformat_list(var, arg, arg_len, curproxy, list_format, options, cap, file, line); |
Willy Tarreau | c836845 | 2012-12-21 00:09:23 +0100 | [diff] [blame] | 526 | break; |
Willy Tarreau | 8a3f52f | 2012-12-20 21:23:42 +0100 | [diff] [blame] | 527 | case LF_TEXT: |
| 528 | case LF_SEPARATOR: |
| 529 | add_to_logformat_list(sp, str, pformat, list_format); |
| 530 | break; |
| 531 | } |
| 532 | sp = str; /* new start of text at every state switch and at every separator */ |
William Lallemand | 723b73a | 2012-02-08 16:37:49 +0100 | [diff] [blame] | 533 | } |
| 534 | } |
Willy Tarreau | 8a3f52f | 2012-12-20 21:23:42 +0100 | [diff] [blame] | 535 | |
Willy Tarreau | c836845 | 2012-12-21 00:09:23 +0100 | [diff] [blame] | 536 | if (pformat == LF_STARTVAR || pformat == LF_STARG || pformat == LF_STEXPR) |
Willy Tarreau | b1f3af2 | 2013-04-12 18:30:32 +0200 | [diff] [blame] | 537 | Warning("parsing [%s:%d] : Ignoring end of truncated '%s' line after '%s'\n", |
| 538 | curproxy->conf.args.file, curproxy->conf.args.line, fmt_directive(curproxy), |
| 539 | var ? var : arg ? arg : "%"); |
Willy Tarreau | 3ed22a4 | 2012-12-23 17:29:07 +0100 | [diff] [blame] | 540 | |
Willy Tarreau | b83bc1e | 2012-12-24 12:36:33 +0100 | [diff] [blame] | 541 | free(backfmt); |
William Lallemand | 723b73a | 2012-02-08 16:37:49 +0100 | [diff] [blame] | 542 | } |
| 543 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 544 | /* |
| 545 | * Displays the message on stderr with the date and pid. Overrides the quiet |
| 546 | * mode during startup. |
| 547 | */ |
Willy Tarreau | b17916e | 2006-10-15 15:17:57 +0200 | [diff] [blame] | 548 | void Alert(const char *fmt, ...) |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 549 | { |
| 550 | va_list argp; |
Willy Tarreau | fe94460 | 2007-10-25 10:34:16 +0200 | [diff] [blame] | 551 | struct tm tm; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 552 | |
| 553 | if (!(global.mode & MODE_QUIET) || (global.mode & (MODE_VERBOSE | MODE_STARTING))) { |
| 554 | va_start(argp, fmt); |
| 555 | |
Willy Tarreau | b7f694f | 2008-06-22 17:18:02 +0200 | [diff] [blame] | 556 | get_localtime(date.tv_sec, &tm); |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 557 | fprintf(stderr, "[ALERT] %03d/%02d%02d%02d (%d) : ", |
Willy Tarreau | fe94460 | 2007-10-25 10:34:16 +0200 | [diff] [blame] | 558 | tm.tm_yday, tm.tm_hour, tm.tm_min, tm.tm_sec, (int)getpid()); |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 559 | vfprintf(stderr, fmt, argp); |
| 560 | fflush(stderr); |
| 561 | va_end(argp); |
| 562 | } |
| 563 | } |
| 564 | |
| 565 | |
| 566 | /* |
| 567 | * Displays the message on stderr with the date and pid. |
| 568 | */ |
Willy Tarreau | b17916e | 2006-10-15 15:17:57 +0200 | [diff] [blame] | 569 | void Warning(const char *fmt, ...) |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 570 | { |
| 571 | va_list argp; |
Willy Tarreau | fe94460 | 2007-10-25 10:34:16 +0200 | [diff] [blame] | 572 | struct tm tm; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 573 | |
| 574 | if (!(global.mode & MODE_QUIET) || (global.mode & MODE_VERBOSE)) { |
| 575 | va_start(argp, fmt); |
| 576 | |
Willy Tarreau | b7f694f | 2008-06-22 17:18:02 +0200 | [diff] [blame] | 577 | get_localtime(date.tv_sec, &tm); |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 578 | fprintf(stderr, "[WARNING] %03d/%02d%02d%02d (%d) : ", |
Willy Tarreau | fe94460 | 2007-10-25 10:34:16 +0200 | [diff] [blame] | 579 | tm.tm_yday, tm.tm_hour, tm.tm_min, tm.tm_sec, (int)getpid()); |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 580 | vfprintf(stderr, fmt, argp); |
| 581 | fflush(stderr); |
| 582 | va_end(argp); |
| 583 | } |
| 584 | } |
| 585 | |
| 586 | /* |
| 587 | * Displays the message on <out> only if quiet mode is not set. |
| 588 | */ |
Willy Tarreau | b17916e | 2006-10-15 15:17:57 +0200 | [diff] [blame] | 589 | void qfprintf(FILE *out, const char *fmt, ...) |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 590 | { |
| 591 | va_list argp; |
| 592 | |
| 593 | if (!(global.mode & MODE_QUIET) || (global.mode & MODE_VERBOSE)) { |
| 594 | va_start(argp, fmt); |
| 595 | vfprintf(out, fmt, argp); |
| 596 | fflush(out); |
| 597 | va_end(argp); |
| 598 | } |
| 599 | } |
| 600 | |
| 601 | /* |
| 602 | * returns log level for <lev> or -1 if not found. |
| 603 | */ |
| 604 | int get_log_level(const char *lev) |
| 605 | { |
| 606 | int level; |
| 607 | |
| 608 | level = NB_LOG_LEVELS - 1; |
| 609 | while (level >= 0 && strcmp(log_levels[level], lev)) |
| 610 | level--; |
| 611 | |
| 612 | return level; |
| 613 | } |
| 614 | |
| 615 | |
| 616 | /* |
| 617 | * returns log facility for <fac> or -1 if not found. |
| 618 | */ |
| 619 | int get_log_facility(const char *fac) |
| 620 | { |
| 621 | int facility; |
| 622 | |
| 623 | facility = NB_LOG_FACILITIES - 1; |
| 624 | while (facility >= 0 && strcmp(log_facilities[facility], fac)) |
| 625 | facility--; |
William Lallemand | 2a4a44f | 2012-02-06 16:00:33 +0100 | [diff] [blame] | 626 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 627 | return facility; |
| 628 | } |
| 629 | |
William Lallemand | a1cc381 | 2012-02-08 16:38:44 +0100 | [diff] [blame] | 630 | /* |
| 631 | * Write a string in the log string |
William Lallemand | 5f23240 | 2012-04-05 18:02:55 +0200 | [diff] [blame] | 632 | * Take cares of quote options |
William Lallemand | a1cc381 | 2012-02-08 16:38:44 +0100 | [diff] [blame] | 633 | * |
| 634 | * Return the adress of the \0 character, or NULL on error |
| 635 | */ |
Willy Tarreau | 2b0108a | 2012-12-21 19:23:44 +0100 | [diff] [blame] | 636 | char *lf_text_len(char *dst, const char *src, size_t len, size_t size, struct logformat_node *node) |
William Lallemand | a1cc381 | 2012-02-08 16:38:44 +0100 | [diff] [blame] | 637 | { |
Willy Tarreau | 2b0108a | 2012-12-21 19:23:44 +0100 | [diff] [blame] | 638 | if (size < 2) |
| 639 | return NULL; |
William Lallemand | a1cc381 | 2012-02-08 16:38:44 +0100 | [diff] [blame] | 640 | |
Willy Tarreau | 2b0108a | 2012-12-21 19:23:44 +0100 | [diff] [blame] | 641 | if (node->options & LOG_OPT_QUOTE) { |
| 642 | *(dst++) = '"'; |
| 643 | size--; |
William Lallemand | bddd4fd | 2012-02-27 11:23:10 +0100 | [diff] [blame] | 644 | } |
Willy Tarreau | 2b0108a | 2012-12-21 19:23:44 +0100 | [diff] [blame] | 645 | |
Willy Tarreau | 6cbbdbf | 2013-02-05 18:52:25 +0100 | [diff] [blame] | 646 | if (src && len) { |
Willy Tarreau | 2b0108a | 2012-12-21 19:23:44 +0100 | [diff] [blame] | 647 | if (++len > size) |
| 648 | len = size; |
| 649 | len = strlcpy2(dst, src, len); |
| 650 | |
| 651 | size -= len; |
| 652 | dst += len; |
| 653 | } |
Willy Tarreau | 6cbbdbf | 2013-02-05 18:52:25 +0100 | [diff] [blame] | 654 | else if ((node->options & (LOG_OPT_QUOTE|LOG_OPT_MANDATORY)) == LOG_OPT_MANDATORY) { |
| 655 | if (size < 2) |
| 656 | return NULL; |
| 657 | *(dst++) = '-'; |
| 658 | } |
Willy Tarreau | 2b0108a | 2012-12-21 19:23:44 +0100 | [diff] [blame] | 659 | |
| 660 | if (node->options & LOG_OPT_QUOTE) { |
| 661 | if (size < 2) |
| 662 | return NULL; |
| 663 | *(dst++) = '"'; |
| 664 | } |
| 665 | |
| 666 | *dst = '\0'; |
William Lallemand | bddd4fd | 2012-02-27 11:23:10 +0100 | [diff] [blame] | 667 | return dst; |
William Lallemand | a1cc381 | 2012-02-08 16:38:44 +0100 | [diff] [blame] | 668 | } |
| 669 | |
Willy Tarreau | 2b0108a | 2012-12-21 19:23:44 +0100 | [diff] [blame] | 670 | static inline char *lf_text(char *dst, const char *src, size_t size, struct logformat_node *node) |
| 671 | { |
| 672 | return lf_text_len(dst, src, size, size, node); |
| 673 | } |
| 674 | |
William Lallemand | 5f23240 | 2012-04-05 18:02:55 +0200 | [diff] [blame] | 675 | /* |
| 676 | * Write a IP adress to the log string |
| 677 | * +X option write in hexadecimal notation, most signifant byte on the left |
| 678 | */ |
| 679 | char *lf_ip(char *dst, struct sockaddr *sockaddr, size_t size, struct logformat_node *node) |
| 680 | { |
| 681 | char *ret = dst; |
| 682 | int iret; |
| 683 | char pn[INET6_ADDRSTRLEN]; |
| 684 | |
| 685 | if (node->options & LOG_OPT_HEXA) { |
| 686 | const unsigned char *addr = (const unsigned char *)&((struct sockaddr_in *)sockaddr)->sin_addr.s_addr; |
| 687 | iret = snprintf(dst, size, "%02X%02X%02X%02X", addr[0], addr[1], addr[2], addr[3]); |
| 688 | if (iret < 0 || iret > size) |
| 689 | return NULL; |
| 690 | ret += iret; |
| 691 | } else { |
| 692 | addr_to_str((struct sockaddr_storage *)sockaddr, pn, sizeof(pn)); |
| 693 | ret = lf_text(dst, pn, size, node); |
| 694 | if (ret == NULL) |
| 695 | return NULL; |
| 696 | } |
| 697 | return ret; |
| 698 | } |
| 699 | |
| 700 | /* |
| 701 | * Write a port to the log |
| 702 | * +X option write in hexadecimal notation, most signifant byte on the left |
| 703 | */ |
| 704 | char *lf_port(char *dst, struct sockaddr *sockaddr, size_t size, struct logformat_node *node) |
| 705 | { |
| 706 | char *ret = dst; |
| 707 | int iret; |
| 708 | |
| 709 | if (node->options & LOG_OPT_HEXA) { |
| 710 | const unsigned char *port = (const unsigned char *)&((struct sockaddr_in *)sockaddr)->sin_port; |
| 711 | iret = snprintf(dst, size, "%02X%02X", port[0], port[1]); |
| 712 | if (iret < 0 || iret > size) |
| 713 | return NULL; |
| 714 | ret += iret; |
| 715 | } else { |
| 716 | ret = ltoa_o(get_host_port((struct sockaddr_storage *)sockaddr), dst, size); |
| 717 | if (ret == NULL) |
| 718 | return NULL; |
| 719 | } |
| 720 | return ret; |
| 721 | } |
| 722 | |
Willy Tarreau | b1a2faf | 2012-03-19 16:51:53 +0100 | [diff] [blame] | 723 | /* Re-generate the syslog header at the beginning of logline once a second and |
| 724 | * return the pointer to the first character after the header. |
| 725 | */ |
| 726 | static char *update_log_hdr() |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 727 | { |
Willy Tarreau | b1a2faf | 2012-03-19 16:51:53 +0100 | [diff] [blame] | 728 | static long tvsec; |
| 729 | static char *dataptr = NULL; /* backup of last end of header, NULL first time */ |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 730 | |
Willy Tarreau | b7f694f | 2008-06-22 17:18:02 +0200 | [diff] [blame] | 731 | if (unlikely(date.tv_sec != tvsec || dataptr == NULL)) { |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 732 | /* this string is rebuild only once a second */ |
Willy Tarreau | fe94460 | 2007-10-25 10:34:16 +0200 | [diff] [blame] | 733 | struct tm tm; |
Willy Tarreau | b1a2faf | 2012-03-19 16:51:53 +0100 | [diff] [blame] | 734 | int hdr_len; |
Willy Tarreau | fe94460 | 2007-10-25 10:34:16 +0200 | [diff] [blame] | 735 | |
Willy Tarreau | b7f694f | 2008-06-22 17:18:02 +0200 | [diff] [blame] | 736 | tvsec = date.tv_sec; |
Willy Tarreau | fe94460 | 2007-10-25 10:34:16 +0200 | [diff] [blame] | 737 | get_localtime(tvsec, &tm); |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 738 | |
Willy Tarreau | b1a2faf | 2012-03-19 16:51:53 +0100 | [diff] [blame] | 739 | hdr_len = snprintf(logline, MAX_SYSLOG_LEN, |
Joe Williams | df5b38f | 2010-12-29 17:05:48 +0100 | [diff] [blame] | 740 | "<<<<>%s %2d %02d:%02d:%02d %s%s[%d]: ", |
Willy Tarreau | fe94460 | 2007-10-25 10:34:16 +0200 | [diff] [blame] | 741 | monthname[tm.tm_mon], |
| 742 | tm.tm_mday, tm.tm_hour, tm.tm_min, tm.tm_sec, |
Joe Williams | df5b38f | 2010-12-29 17:05:48 +0100 | [diff] [blame] | 743 | global.log_send_hostname ? global.log_send_hostname : "", |
Kevinm | 48936af | 2010-12-22 16:08:21 +0000 | [diff] [blame] | 744 | global.log_tag, pid); |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 745 | /* WARNING: depending upon implementations, snprintf may return |
| 746 | * either -1 or the number of bytes that would be needed to store |
| 747 | * the total message. In both cases, we must adjust it. |
| 748 | */ |
William Lallemand | 2a4a44f | 2012-02-06 16:00:33 +0100 | [diff] [blame] | 749 | if (hdr_len < 0 || hdr_len > MAX_SYSLOG_LEN) |
| 750 | hdr_len = MAX_SYSLOG_LEN; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 751 | |
Willy Tarreau | b1a2faf | 2012-03-19 16:51:53 +0100 | [diff] [blame] | 752 | dataptr = logline + hdr_len; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 753 | } |
| 754 | |
William Lallemand | 2a4a44f | 2012-02-06 16:00:33 +0100 | [diff] [blame] | 755 | return dataptr; |
| 756 | } |
| 757 | |
| 758 | /* |
| 759 | * This function adds a header to the message and sends the syslog message |
Willy Tarreau | 53bf6af | 2012-02-24 11:46:54 +0100 | [diff] [blame] | 760 | * using a printf format string. It expects an LF-terminated message. |
William Lallemand | 2a4a44f | 2012-02-06 16:00:33 +0100 | [diff] [blame] | 761 | */ |
| 762 | void send_log(struct proxy *p, int level, const char *format, ...) |
| 763 | { |
| 764 | va_list argp; |
Willy Tarreau | b1a2faf | 2012-03-19 16:51:53 +0100 | [diff] [blame] | 765 | char *dataptr; |
| 766 | int data_len; |
William Lallemand | 2a4a44f | 2012-02-06 16:00:33 +0100 | [diff] [blame] | 767 | |
| 768 | if (level < 0 || format == NULL) |
| 769 | return; |
| 770 | |
Willy Tarreau | b1a2faf | 2012-03-19 16:51:53 +0100 | [diff] [blame] | 771 | dataptr = update_log_hdr(); /* update log header and skip it */ |
| 772 | data_len = dataptr - logline; |
William Lallemand | 2a4a44f | 2012-02-06 16:00:33 +0100 | [diff] [blame] | 773 | |
| 774 | va_start(argp, format); |
Willy Tarreau | b1a2faf | 2012-03-19 16:51:53 +0100 | [diff] [blame] | 775 | data_len += vsnprintf(dataptr, logline + sizeof(logline) - dataptr, format, argp); |
William Lallemand | 2a4a44f | 2012-02-06 16:00:33 +0100 | [diff] [blame] | 776 | if (data_len < 0 || data_len > MAX_SYSLOG_LEN) |
| 777 | data_len = MAX_SYSLOG_LEN; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 778 | va_end(argp); |
William Lallemand | 2a4a44f | 2012-02-06 16:00:33 +0100 | [diff] [blame] | 779 | |
Willy Tarreau | b1a2faf | 2012-03-19 16:51:53 +0100 | [diff] [blame] | 780 | __send_log(p, level, logline, data_len); |
William Lallemand | 2a4a44f | 2012-02-06 16:00:33 +0100 | [diff] [blame] | 781 | } |
| 782 | |
| 783 | /* |
| 784 | * This function sends a syslog message. |
| 785 | * It doesn't care about errors nor does it report them. |
Willy Tarreau | 53bf6af | 2012-02-24 11:46:54 +0100 | [diff] [blame] | 786 | * It overrides the last byte (message[size-1]) with an LF character. |
William Lallemand | 2a4a44f | 2012-02-06 16:00:33 +0100 | [diff] [blame] | 787 | */ |
| 788 | void __send_log(struct proxy *p, int level, char *message, size_t size) |
| 789 | { |
| 790 | static int logfdunix = -1; /* syslog to AF_UNIX socket */ |
| 791 | static int logfdinet = -1; /* syslog to AF_INET socket */ |
| 792 | static char *dataptr = NULL; |
| 793 | int fac_level; |
| 794 | struct list *logsrvs = NULL; |
| 795 | struct logsrv *tmp = NULL; |
| 796 | int nblogger; |
| 797 | char *log_ptr; |
| 798 | |
| 799 | dataptr = message; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 800 | |
| 801 | if (p == NULL) { |
William Lallemand | 0f99e34 | 2011-10-12 17:50:54 +0200 | [diff] [blame] | 802 | if (!LIST_ISEMPTY(&global.logsrvs)) { |
| 803 | logsrvs = &global.logsrvs; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 804 | } |
| 805 | } else { |
William Lallemand | 0f99e34 | 2011-10-12 17:50:54 +0200 | [diff] [blame] | 806 | if (!LIST_ISEMPTY(&p->logsrvs)) { |
| 807 | logsrvs = &p->logsrvs; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 808 | } |
Robert Tsai | 81ae195 | 2007-12-05 10:47:29 +0100 | [diff] [blame] | 809 | } |
| 810 | |
William Lallemand | 0f99e34 | 2011-10-12 17:50:54 +0200 | [diff] [blame] | 811 | if (!logsrvs) |
| 812 | return; |
| 813 | |
William Lallemand | 2a4a44f | 2012-02-06 16:00:33 +0100 | [diff] [blame] | 814 | message[size - 1] = '\n'; |
| 815 | |
Robert Tsai | 81ae195 | 2007-12-05 10:47:29 +0100 | [diff] [blame] | 816 | /* Send log messages to syslog server. */ |
William Lallemand | 0f99e34 | 2011-10-12 17:50:54 +0200 | [diff] [blame] | 817 | nblogger = 0; |
| 818 | list_for_each_entry(tmp, logsrvs, list) { |
| 819 | const struct logsrv *logsrv = tmp; |
David du Colombier | 11bcb6c | 2011-03-24 12:23:00 +0100 | [diff] [blame] | 820 | int *plogfd = logsrv->addr.ss_family == AF_UNIX ? |
Robert Tsai | 81ae195 | 2007-12-05 10:47:29 +0100 | [diff] [blame] | 821 | &logfdunix : &logfdinet; |
| 822 | int sent; |
| 823 | |
Willy Tarreau | 5304569 | 2014-06-23 18:07:15 +0200 | [diff] [blame] | 824 | nblogger++; |
| 825 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 826 | /* we can filter the level of the messages that are sent to each logger */ |
William Lallemand | 0f99e34 | 2011-10-12 17:50:54 +0200 | [diff] [blame] | 827 | if (level > logsrv->level) |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 828 | continue; |
William Lallemand | bddd4fd | 2012-02-27 11:23:10 +0100 | [diff] [blame] | 829 | |
Willy Tarreau | 5304569 | 2014-06-23 18:07:15 +0200 | [diff] [blame] | 830 | if (unlikely(*plogfd < 0)) { |
| 831 | /* socket not successfully initialized yet */ |
| 832 | int proto = logsrv->addr.ss_family == AF_UNIX ? 0 : IPPROTO_UDP; |
| 833 | |
| 834 | if ((*plogfd = socket(logsrv->addr.ss_family, SOCK_DGRAM, proto)) < 0) { |
| 835 | Alert("socket for logger #%d failed: %s (errno=%d)\n", |
| 836 | nblogger, strerror(errno), errno); |
| 837 | continue; |
| 838 | } |
| 839 | /* we don't want to receive anything on this socket */ |
| 840 | setsockopt(*plogfd, SOL_SOCKET, SO_RCVBUF, &zero, sizeof(zero)); |
| 841 | /* does nothing under Linux, maybe needed for others */ |
| 842 | shutdown(*plogfd, SHUT_RD); |
| 843 | } |
| 844 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 845 | /* For each target, we may have a different facility. |
| 846 | * We can also have a different log level for each message. |
| 847 | * This induces variations in the message header length. |
| 848 | * Since we don't want to recompute it each time, nor copy it every |
| 849 | * time, we only change the facility in the pre-computed header, |
| 850 | * and we change the pointer to the header accordingly. |
| 851 | */ |
William Lallemand | 0f99e34 | 2011-10-12 17:50:54 +0200 | [diff] [blame] | 852 | fac_level = (logsrv->facility << 3) + MAX(level, logsrv->minlvl); |
William Lallemand | 2a4a44f | 2012-02-06 16:00:33 +0100 | [diff] [blame] | 853 | log_ptr = dataptr + 3; /* last digit of the log level */ |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 854 | do { |
| 855 | *log_ptr = '0' + fac_level % 10; |
| 856 | fac_level /= 10; |
| 857 | log_ptr--; |
William Lallemand | 2a4a44f | 2012-02-06 16:00:33 +0100 | [diff] [blame] | 858 | } while (fac_level && log_ptr > dataptr); |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 859 | *log_ptr = '<'; |
William Lallemand | 2a4a44f | 2012-02-06 16:00:33 +0100 | [diff] [blame] | 860 | |
William Lallemand | afeb987 | 2013-08-30 14:17:46 +0200 | [diff] [blame] | 861 | sent = sendto(*plogfd, log_ptr, size - (log_ptr - dataptr), |
Willy Tarreau | 1b4b7ce | 2011-04-05 16:56:50 +0200 | [diff] [blame] | 862 | MSG_DONTWAIT | MSG_NOSIGNAL, |
| 863 | (struct sockaddr *)&logsrv->addr, get_addr_len(&logsrv->addr)); |
Robert Tsai | 81ae195 | 2007-12-05 10:47:29 +0100 | [diff] [blame] | 864 | if (sent < 0) { |
| 865 | Alert("sendto logger #%d failed: %s (errno=%d)\n", |
| 866 | nblogger, strerror(errno), errno); |
| 867 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 868 | } |
| 869 | } |
| 870 | |
William Lallemand | bddd4fd | 2012-02-27 11:23:10 +0100 | [diff] [blame] | 871 | extern fd_set hdr_encode_map[]; |
| 872 | extern fd_set url_encode_map[]; |
Thierry FOURNIER | d048d8b | 2014-03-13 16:46:18 +0100 | [diff] [blame] | 873 | extern fd_set http_encode_map[]; |
William Lallemand | bddd4fd | 2012-02-27 11:23:10 +0100 | [diff] [blame] | 874 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 875 | |
Willy Tarreau | c89ccb6 | 2012-04-05 21:18:22 +0200 | [diff] [blame] | 876 | const char sess_cookie[8] = "NIDVEOU7"; /* No cookie, Invalid cookie, cookie for a Down server, Valid cookie, Expired cookie, Old cookie, Unused, unknown */ |
William Lallemand | bddd4fd | 2012-02-27 11:23:10 +0100 | [diff] [blame] | 877 | const char sess_set_cookie[8] = "NPDIRU67"; /* No set-cookie, Set-cookie found and left unchanged (passive), |
| 878 | Set-cookie Deleted, Set-Cookie Inserted, Set-cookie Rewritten, |
| 879 | Set-cookie Updated, unknown, unknown */ |
| 880 | |
William Lallemand | 1d70556 | 2012-03-12 12:46:41 +0100 | [diff] [blame] | 881 | /* |
| 882 | * try to write a character if there is enough space, or goto out |
| 883 | */ |
William Lallemand | bddd4fd | 2012-02-27 11:23:10 +0100 | [diff] [blame] | 884 | #define LOGCHAR(x) do { \ |
William Lallemand | 1d70556 | 2012-03-12 12:46:41 +0100 | [diff] [blame] | 885 | if (tmplog < dst + maxsize - 1) { \ |
William Lallemand | bddd4fd | 2012-02-27 11:23:10 +0100 | [diff] [blame] | 886 | *(tmplog++) = (x); \ |
| 887 | } else { \ |
| 888 | goto out; \ |
| 889 | } \ |
| 890 | } while(0) |
| 891 | |
William Lallemand | 1d70556 | 2012-03-12 12:46:41 +0100 | [diff] [blame] | 892 | |
Willy Tarreau | df97447 | 2012-12-28 02:44:01 +0100 | [diff] [blame] | 893 | /* Builds a log line in <dst> based on <list_format>, and stops before reaching |
| 894 | * <maxsize> characters. Returns the size of the output string in characters, |
| 895 | * not counting the trailing zero which is always added if the resulting size |
| 896 | * is not zero. |
| 897 | */ |
William Lallemand | 1d70556 | 2012-03-12 12:46:41 +0100 | [diff] [blame] | 898 | int build_logline(struct session *s, char *dst, size_t maxsize, struct list *list_format) |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 899 | { |
Willy Tarreau | 73de989 | 2006-11-30 11:40:23 +0100 | [diff] [blame] | 900 | struct proxy *fe = s->fe; |
Willy Tarreau | ddb358d | 2006-12-17 22:55:52 +0100 | [diff] [blame] | 901 | struct proxy *be = s->be; |
William Lallemand | bddd4fd | 2012-02-27 11:23:10 +0100 | [diff] [blame] | 902 | struct http_txn *txn = &s->txn; |
William Lallemand | bddd4fd | 2012-02-27 11:23:10 +0100 | [diff] [blame] | 903 | char *uri; |
Willy Tarreau | fe94460 | 2007-10-25 10:34:16 +0200 | [diff] [blame] | 904 | struct tm tm; |
William Lallemand | bddd4fd | 2012-02-27 11:23:10 +0100 | [diff] [blame] | 905 | int t_request; |
| 906 | int hdr; |
| 907 | int last_isspace = 1; |
Willy Tarreau | b1a2faf | 2012-03-19 16:51:53 +0100 | [diff] [blame] | 908 | char *tmplog; |
William Lallemand | 1d70556 | 2012-03-12 12:46:41 +0100 | [diff] [blame] | 909 | char *ret; |
| 910 | int iret; |
William Lallemand | bddd4fd | 2012-02-27 11:23:10 +0100 | [diff] [blame] | 911 | struct logformat_node *tmp; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 912 | |
William Lallemand | bddd4fd | 2012-02-27 11:23:10 +0100 | [diff] [blame] | 913 | /* FIXME: let's limit ourselves to frontend logging for now. */ |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 914 | |
William Lallemand | bddd4fd | 2012-02-27 11:23:10 +0100 | [diff] [blame] | 915 | t_request = -1; |
| 916 | if (tv_isge(&s->logs.tv_request, &s->logs.tv_accept)) |
| 917 | t_request = tv_ms_elapsed(&s->logs.tv_accept, &s->logs.tv_request); |
| 918 | |
William Lallemand | 1d70556 | 2012-03-12 12:46:41 +0100 | [diff] [blame] | 919 | tmplog = dst; |
Willy Tarreau | c9bd0cc | 2009-05-10 11:57:02 +0200 | [diff] [blame] | 920 | |
William Lallemand | bddd4fd | 2012-02-27 11:23:10 +0100 | [diff] [blame] | 921 | /* fill logbuffer */ |
William Lallemand | 1d70556 | 2012-03-12 12:46:41 +0100 | [diff] [blame] | 922 | if (LIST_ISEMPTY(list_format)) |
| 923 | return 0; |
William Lallemand | bddd4fd | 2012-02-27 11:23:10 +0100 | [diff] [blame] | 924 | |
William Lallemand | 1d70556 | 2012-03-12 12:46:41 +0100 | [diff] [blame] | 925 | list_for_each_entry(tmp, list_format, list) { |
Willy Tarreau | b363a1f | 2013-10-01 10:45:07 +0200 | [diff] [blame] | 926 | struct connection *conn; |
Willy Tarreau | 4f65356 | 2012-10-12 19:48:16 +0200 | [diff] [blame] | 927 | const char *src = NULL; |
Willy Tarreau | c836845 | 2012-12-21 00:09:23 +0100 | [diff] [blame] | 928 | struct sample *key; |
Thierry FOURNIER | d048d8b | 2014-03-13 16:46:18 +0100 | [diff] [blame] | 929 | const struct chunk empty = { NULL, 0, 0 }; |
William Lallemand | bddd4fd | 2012-02-27 11:23:10 +0100 | [diff] [blame] | 930 | |
Willy Tarreau | c836845 | 2012-12-21 00:09:23 +0100 | [diff] [blame] | 931 | switch (tmp->type) { |
William Lallemand | 1d70556 | 2012-03-12 12:46:41 +0100 | [diff] [blame] | 932 | case LOG_FMT_SEPARATOR: |
William Lallemand | bddd4fd | 2012-02-27 11:23:10 +0100 | [diff] [blame] | 933 | if (!last_isspace) { |
| 934 | LOGCHAR(' '); |
| 935 | last_isspace = 1; |
William Lallemand | bddd4fd | 2012-02-27 11:23:10 +0100 | [diff] [blame] | 936 | } |
| 937 | break; |
| 938 | |
William Lallemand | 1d70556 | 2012-03-12 12:46:41 +0100 | [diff] [blame] | 939 | case LOG_FMT_TEXT: // text |
William Lallemand | bddd4fd | 2012-02-27 11:23:10 +0100 | [diff] [blame] | 940 | src = tmp->arg; |
William Lallemand | 5f23240 | 2012-04-05 18:02:55 +0200 | [diff] [blame] | 941 | iret = strlcpy2(tmplog, src, dst + maxsize - tmplog); |
William Lallemand | 1d70556 | 2012-03-12 12:46:41 +0100 | [diff] [blame] | 942 | if (iret == 0) |
William Lallemand | bddd4fd | 2012-02-27 11:23:10 +0100 | [diff] [blame] | 943 | goto out; |
William Lallemand | 1d70556 | 2012-03-12 12:46:41 +0100 | [diff] [blame] | 944 | tmplog += iret; |
William Lallemand | bddd4fd | 2012-02-27 11:23:10 +0100 | [diff] [blame] | 945 | last_isspace = 0; |
| 946 | break; |
| 947 | |
Willy Tarreau | c836845 | 2012-12-21 00:09:23 +0100 | [diff] [blame] | 948 | case LOG_FMT_EXPR: // sample expression, may be request or response |
| 949 | key = NULL; |
| 950 | if (tmp->options & LOG_OPT_REQ_CAP) |
| 951 | key = sample_fetch_string(be, s, txn, SMP_OPT_DIR_REQ|SMP_OPT_FINAL, tmp->expr); |
| 952 | if (!key && (tmp->options & LOG_OPT_RES_CAP)) |
| 953 | key = sample_fetch_string(be, s, txn, SMP_OPT_DIR_RES|SMP_OPT_FINAL, tmp->expr); |
Thierry FOURNIER | d048d8b | 2014-03-13 16:46:18 +0100 | [diff] [blame] | 954 | if (tmp->options & LOG_OPT_HTTP) |
| 955 | ret = encode_chunk(tmplog, dst + maxsize, |
| 956 | '%', http_encode_map, key ? &key->data.str : &empty); |
| 957 | else |
| 958 | ret = lf_text_len(tmplog, key ? key->data.str.str : NULL, key ? key->data.str.len : 0, dst + maxsize - tmplog, tmp); |
Willy Tarreau | c836845 | 2012-12-21 00:09:23 +0100 | [diff] [blame] | 959 | if (ret == 0) |
| 960 | goto out; |
| 961 | tmplog = ret; |
| 962 | last_isspace = 0; |
| 963 | break; |
| 964 | |
Willy Tarreau | 2beef58 | 2012-12-20 17:22:52 +0100 | [diff] [blame] | 965 | case LOG_FMT_CLIENTIP: // %ci |
Willy Tarreau | b363a1f | 2013-10-01 10:45:07 +0200 | [diff] [blame] | 966 | conn = objt_conn(s->req->prod->end); |
| 967 | if (conn) |
| 968 | ret = lf_ip(tmplog, (struct sockaddr *)&conn->addr.from, dst + maxsize - tmplog, tmp); |
| 969 | else |
| 970 | ret = lf_text_len(tmplog, NULL, 0, dst + maxsize - tmplog, tmp); |
William Lallemand | 1d70556 | 2012-03-12 12:46:41 +0100 | [diff] [blame] | 971 | if (ret == NULL) |
William Lallemand | bddd4fd | 2012-02-27 11:23:10 +0100 | [diff] [blame] | 972 | goto out; |
William Lallemand | 1d70556 | 2012-03-12 12:46:41 +0100 | [diff] [blame] | 973 | tmplog = ret; |
William Lallemand | bddd4fd | 2012-02-27 11:23:10 +0100 | [diff] [blame] | 974 | last_isspace = 0; |
| 975 | break; |
| 976 | |
Willy Tarreau | 2beef58 | 2012-12-20 17:22:52 +0100 | [diff] [blame] | 977 | case LOG_FMT_CLIENTPORT: // %cp |
Willy Tarreau | b363a1f | 2013-10-01 10:45:07 +0200 | [diff] [blame] | 978 | conn = objt_conn(s->req->prod->end); |
| 979 | if (conn) { |
| 980 | if (conn->addr.from.ss_family == AF_UNIX) { |
| 981 | ret = ltoa_o(s->listener->luid, tmplog, dst + maxsize - tmplog); |
| 982 | } else { |
| 983 | ret = lf_port(tmplog, (struct sockaddr *)&conn->addr.from, |
| 984 | dst + maxsize - tmplog, tmp); |
| 985 | } |
William Lallemand | 5f23240 | 2012-04-05 18:02:55 +0200 | [diff] [blame] | 986 | } |
Willy Tarreau | b363a1f | 2013-10-01 10:45:07 +0200 | [diff] [blame] | 987 | else |
| 988 | ret = lf_text_len(tmplog, NULL, 0, dst + maxsize - tmplog, tmp); |
| 989 | |
William Lallemand | 5f23240 | 2012-04-05 18:02:55 +0200 | [diff] [blame] | 990 | if (ret == NULL) |
| 991 | goto out; |
| 992 | tmplog = ret; |
| 993 | last_isspace = 0; |
| 994 | break; |
| 995 | |
Willy Tarreau | 2beef58 | 2012-12-20 17:22:52 +0100 | [diff] [blame] | 996 | case LOG_FMT_FRONTENDIP: // %fi |
Willy Tarreau | b363a1f | 2013-10-01 10:45:07 +0200 | [diff] [blame] | 997 | conn = objt_conn(s->req->prod->end); |
| 998 | if (conn) { |
| 999 | conn_get_to_addr(conn); |
| 1000 | ret = lf_ip(tmplog, (struct sockaddr *)&conn->addr.to, dst + maxsize - tmplog, tmp); |
| 1001 | } |
| 1002 | else |
| 1003 | ret = lf_text_len(tmplog, NULL, 0, dst + maxsize - tmplog, tmp); |
| 1004 | |
William Lallemand | 1d70556 | 2012-03-12 12:46:41 +0100 | [diff] [blame] | 1005 | if (ret == NULL) |
William Lallemand | bddd4fd | 2012-02-27 11:23:10 +0100 | [diff] [blame] | 1006 | goto out; |
William Lallemand | 1d70556 | 2012-03-12 12:46:41 +0100 | [diff] [blame] | 1007 | tmplog = ret; |
William Lallemand | bddd4fd | 2012-02-27 11:23:10 +0100 | [diff] [blame] | 1008 | last_isspace = 0; |
| 1009 | break; |
| 1010 | |
Willy Tarreau | 2beef58 | 2012-12-20 17:22:52 +0100 | [diff] [blame] | 1011 | case LOG_FMT_FRONTENDPORT: // %fp |
Willy Tarreau | b363a1f | 2013-10-01 10:45:07 +0200 | [diff] [blame] | 1012 | conn = objt_conn(s->req->prod->end); |
| 1013 | if (conn) { |
| 1014 | conn_get_to_addr(conn); |
| 1015 | if (conn->addr.to.ss_family == AF_UNIX) |
| 1016 | ret = ltoa_o(s->listener->luid, tmplog, dst + maxsize - tmplog); |
| 1017 | else |
| 1018 | ret = lf_port(tmplog, (struct sockaddr *)&conn->addr.to, dst + maxsize - tmplog, tmp); |
William Lallemand | 5f23240 | 2012-04-05 18:02:55 +0200 | [diff] [blame] | 1019 | } |
Willy Tarreau | b363a1f | 2013-10-01 10:45:07 +0200 | [diff] [blame] | 1020 | else |
| 1021 | ret = lf_text_len(tmplog, NULL, 0, dst + maxsize - tmplog, tmp); |
| 1022 | |
William Lallemand | 5f23240 | 2012-04-05 18:02:55 +0200 | [diff] [blame] | 1023 | if (ret == NULL) |
| 1024 | goto out; |
| 1025 | tmplog = ret; |
| 1026 | last_isspace = 0; |
| 1027 | break; |
| 1028 | |
Willy Tarreau | 2beef58 | 2012-12-20 17:22:52 +0100 | [diff] [blame] | 1029 | case LOG_FMT_BACKENDIP: // %bi |
Willy Tarreau | b363a1f | 2013-10-01 10:45:07 +0200 | [diff] [blame] | 1030 | conn = objt_conn(s->req->cons->end); |
| 1031 | if (conn) |
| 1032 | ret = lf_ip(tmplog, (struct sockaddr *)&conn->addr.from, dst + maxsize - tmplog, tmp); |
| 1033 | else |
| 1034 | ret = lf_text_len(tmplog, NULL, 0, dst + maxsize - tmplog, tmp); |
| 1035 | |
William Lallemand | 1d70556 | 2012-03-12 12:46:41 +0100 | [diff] [blame] | 1036 | if (ret == NULL) |
William Lallemand | b7ff6a3 | 2012-03-02 14:35:21 +0100 | [diff] [blame] | 1037 | goto out; |
William Lallemand | 1d70556 | 2012-03-12 12:46:41 +0100 | [diff] [blame] | 1038 | tmplog = ret; |
William Lallemand | b7ff6a3 | 2012-03-02 14:35:21 +0100 | [diff] [blame] | 1039 | last_isspace = 0; |
| 1040 | break; |
| 1041 | |
Willy Tarreau | 2beef58 | 2012-12-20 17:22:52 +0100 | [diff] [blame] | 1042 | case LOG_FMT_BACKENDPORT: // %bp |
Willy Tarreau | b363a1f | 2013-10-01 10:45:07 +0200 | [diff] [blame] | 1043 | conn = objt_conn(s->req->cons->end); |
| 1044 | if (conn) |
| 1045 | ret = lf_port(tmplog, (struct sockaddr *)&conn->addr.from, dst + maxsize - tmplog, tmp); |
| 1046 | else |
| 1047 | ret = lf_text_len(tmplog, NULL, 0, dst + maxsize - tmplog, tmp); |
| 1048 | |
William Lallemand | 5f23240 | 2012-04-05 18:02:55 +0200 | [diff] [blame] | 1049 | if (ret == NULL) |
| 1050 | goto out; |
| 1051 | tmplog = ret; |
| 1052 | last_isspace = 0; |
| 1053 | break; |
| 1054 | |
Willy Tarreau | 2beef58 | 2012-12-20 17:22:52 +0100 | [diff] [blame] | 1055 | case LOG_FMT_SERVERIP: // %si |
Willy Tarreau | b363a1f | 2013-10-01 10:45:07 +0200 | [diff] [blame] | 1056 | conn = objt_conn(s->req->cons->end); |
| 1057 | if (conn) |
| 1058 | ret = lf_ip(tmplog, (struct sockaddr *)&conn->addr.to, dst + maxsize - tmplog, tmp); |
| 1059 | else |
| 1060 | ret = lf_text_len(tmplog, NULL, 0, dst + maxsize - tmplog, tmp); |
| 1061 | |
William Lallemand | 5f23240 | 2012-04-05 18:02:55 +0200 | [diff] [blame] | 1062 | if (ret == NULL) |
| 1063 | goto out; |
| 1064 | tmplog = ret; |
| 1065 | last_isspace = 0; |
| 1066 | break; |
| 1067 | |
Willy Tarreau | 2beef58 | 2012-12-20 17:22:52 +0100 | [diff] [blame] | 1068 | case LOG_FMT_SERVERPORT: // %sp |
Willy Tarreau | b363a1f | 2013-10-01 10:45:07 +0200 | [diff] [blame] | 1069 | conn = objt_conn(s->req->cons->end); |
| 1070 | if (conn) |
| 1071 | ret = lf_port(tmplog, (struct sockaddr *)&conn->addr.to, dst + maxsize - tmplog, tmp); |
| 1072 | else |
| 1073 | ret = lf_text_len(tmplog, NULL, 0, dst + maxsize - tmplog, tmp); |
| 1074 | |
William Lallemand | 1d70556 | 2012-03-12 12:46:41 +0100 | [diff] [blame] | 1075 | if (ret == NULL) |
William Lallemand | b7ff6a3 | 2012-03-02 14:35:21 +0100 | [diff] [blame] | 1076 | goto out; |
William Lallemand | 1d70556 | 2012-03-12 12:46:41 +0100 | [diff] [blame] | 1077 | tmplog = ret; |
William Lallemand | b7ff6a3 | 2012-03-02 14:35:21 +0100 | [diff] [blame] | 1078 | last_isspace = 0; |
| 1079 | break; |
| 1080 | |
William Lallemand | 1d70556 | 2012-03-12 12:46:41 +0100 | [diff] [blame] | 1081 | case LOG_FMT_DATE: // %t |
William Lallemand | bddd4fd | 2012-02-27 11:23:10 +0100 | [diff] [blame] | 1082 | get_localtime(s->logs.accept_date.tv_sec, &tm); |
William Lallemand | 5f23240 | 2012-04-05 18:02:55 +0200 | [diff] [blame] | 1083 | ret = date2str_log(tmplog, &tm, &(s->logs.accept_date), |
| 1084 | dst + maxsize - tmplog); |
William Lallemand | 1d70556 | 2012-03-12 12:46:41 +0100 | [diff] [blame] | 1085 | if (ret == NULL) |
William Lallemand | bddd4fd | 2012-02-27 11:23:10 +0100 | [diff] [blame] | 1086 | goto out; |
William Lallemand | 1d70556 | 2012-03-12 12:46:41 +0100 | [diff] [blame] | 1087 | tmplog = ret; |
William Lallemand | bddd4fd | 2012-02-27 11:23:10 +0100 | [diff] [blame] | 1088 | last_isspace = 0; |
| 1089 | break; |
| 1090 | |
William Lallemand | 1d70556 | 2012-03-12 12:46:41 +0100 | [diff] [blame] | 1091 | case LOG_FMT_DATEGMT: // %T |
William Lallemand | bddd4fd | 2012-02-27 11:23:10 +0100 | [diff] [blame] | 1092 | get_gmtime(s->logs.accept_date.tv_sec, &tm); |
William Lallemand | 5f23240 | 2012-04-05 18:02:55 +0200 | [diff] [blame] | 1093 | ret = gmt2str_log(tmplog, &tm, dst + maxsize - tmplog); |
William Lallemand | 1d70556 | 2012-03-12 12:46:41 +0100 | [diff] [blame] | 1094 | if (ret == NULL) |
William Lallemand | bddd4fd | 2012-02-27 11:23:10 +0100 | [diff] [blame] | 1095 | goto out; |
William Lallemand | 1d70556 | 2012-03-12 12:46:41 +0100 | [diff] [blame] | 1096 | tmplog = ret; |
William Lallemand | bddd4fd | 2012-02-27 11:23:10 +0100 | [diff] [blame] | 1097 | last_isspace = 0; |
| 1098 | break; |
| 1099 | |
Yuxans Yao | 4e25b01 | 2012-10-19 10:36:09 +0800 | [diff] [blame] | 1100 | case LOG_FMT_DATELOCAL: // %Tl |
| 1101 | get_localtime(s->logs.accept_date.tv_sec, &tm); |
| 1102 | ret = localdate2str_log(tmplog, &tm, dst + maxsize - tmplog); |
| 1103 | if (ret == NULL) |
| 1104 | goto out; |
| 1105 | tmplog = ret; |
| 1106 | last_isspace = 0; |
| 1107 | break; |
| 1108 | |
William Lallemand | 5f23240 | 2012-04-05 18:02:55 +0200 | [diff] [blame] | 1109 | case LOG_FMT_TS: // %Ts |
| 1110 | get_gmtime(s->logs.accept_date.tv_sec, &tm); |
| 1111 | if (tmp->options & LOG_OPT_HEXA) { |
| 1112 | iret = snprintf(tmplog, dst + maxsize - tmplog, "%04X", (unsigned int)s->logs.accept_date.tv_sec); |
| 1113 | if (iret < 0 || iret > dst + maxsize - tmplog) |
| 1114 | goto out; |
| 1115 | last_isspace = 0; |
| 1116 | tmplog += iret; |
| 1117 | } else { |
| 1118 | ret = ltoa_o(s->logs.accept_date.tv_sec, tmplog, dst + maxsize - tmplog); |
| 1119 | if (ret == NULL) |
| 1120 | goto out; |
| 1121 | tmplog = ret; |
| 1122 | last_isspace = 0; |
| 1123 | } |
| 1124 | break; |
| 1125 | |
William Lallemand | 1d70556 | 2012-03-12 12:46:41 +0100 | [diff] [blame] | 1126 | case LOG_FMT_MS: // %ms |
William Lallemand | 5f23240 | 2012-04-05 18:02:55 +0200 | [diff] [blame] | 1127 | if (tmp->options & LOG_OPT_HEXA) { |
| 1128 | iret = snprintf(tmplog, dst + maxsize - tmplog, "%02X",(unsigned int)s->logs.accept_date.tv_usec/1000); |
| 1129 | if (iret < 0 || iret > dst + maxsize - tmplog) |
| 1130 | goto out; |
| 1131 | last_isspace = 0; |
| 1132 | tmplog += iret; |
| 1133 | } else { |
| 1134 | if ((dst + maxsize - tmplog) < 4) |
William Lallemand | bddd4fd | 2012-02-27 11:23:10 +0100 | [diff] [blame] | 1135 | goto out; |
Willy Tarreau | 9e60cd8 | 2013-01-24 01:18:16 +0100 | [diff] [blame] | 1136 | ret = utoa_pad((unsigned int)s->logs.accept_date.tv_usec/1000, |
| 1137 | tmplog, 4); |
| 1138 | if (ret == NULL) |
William Lallemand | 51b5dca | 2012-03-26 17:52:55 +0200 | [diff] [blame] | 1139 | goto out; |
Willy Tarreau | 9e60cd8 | 2013-01-24 01:18:16 +0100 | [diff] [blame] | 1140 | tmplog = ret; |
William Lallemand | bddd4fd | 2012-02-27 11:23:10 +0100 | [diff] [blame] | 1141 | last_isspace = 0; |
William Lallemand | 5f23240 | 2012-04-05 18:02:55 +0200 | [diff] [blame] | 1142 | } |
| 1143 | break; |
William Lallemand | bddd4fd | 2012-02-27 11:23:10 +0100 | [diff] [blame] | 1144 | |
William Lallemand | 1d70556 | 2012-03-12 12:46:41 +0100 | [diff] [blame] | 1145 | case LOG_FMT_FRONTEND: // %f |
William Lallemand | bddd4fd | 2012-02-27 11:23:10 +0100 | [diff] [blame] | 1146 | src = fe->id; |
William Lallemand | 5f23240 | 2012-04-05 18:02:55 +0200 | [diff] [blame] | 1147 | ret = lf_text(tmplog, src, dst + maxsize - tmplog, tmp); |
William Lallemand | 1d70556 | 2012-03-12 12:46:41 +0100 | [diff] [blame] | 1148 | if (ret == NULL) |
William Lallemand | bddd4fd | 2012-02-27 11:23:10 +0100 | [diff] [blame] | 1149 | goto out; |
William Lallemand | 1d70556 | 2012-03-12 12:46:41 +0100 | [diff] [blame] | 1150 | tmplog = ret; |
William Lallemand | 51b5dca | 2012-03-26 17:52:55 +0200 | [diff] [blame] | 1151 | last_isspace = 0; |
William Lallemand | bddd4fd | 2012-02-27 11:23:10 +0100 | [diff] [blame] | 1152 | break; |
| 1153 | |
Willy Tarreau | 773d65f | 2012-10-12 14:56:11 +0200 | [diff] [blame] | 1154 | case LOG_FMT_FRONTEND_XPRT: // %ft |
| 1155 | src = fe->id; |
| 1156 | if (tmp->options & LOG_OPT_QUOTE) |
| 1157 | LOGCHAR('"'); |
| 1158 | iret = strlcpy2(tmplog, src, dst + maxsize - tmplog); |
| 1159 | if (iret == 0) |
| 1160 | goto out; |
| 1161 | tmplog += iret; |
| 1162 | #ifdef USE_OPENSSL |
| 1163 | if (s->listener->xprt == &ssl_sock) |
| 1164 | LOGCHAR('~'); |
| 1165 | #endif |
| 1166 | if (tmp->options & LOG_OPT_QUOTE) |
| 1167 | LOGCHAR('"'); |
| 1168 | last_isspace = 0; |
| 1169 | break; |
Willy Tarreau | ffc3fcd | 2012-10-12 20:17:54 +0200 | [diff] [blame] | 1170 | #ifdef USE_OPENSSL |
| 1171 | case LOG_FMT_SSL_CIPHER: // %sslc |
| 1172 | src = NULL; |
Willy Tarreau | b363a1f | 2013-10-01 10:45:07 +0200 | [diff] [blame] | 1173 | conn = objt_conn(s->si[0].end); |
| 1174 | if (conn) { |
| 1175 | if (s->listener->xprt == &ssl_sock) |
| 1176 | src = ssl_sock_get_cipher_name(conn); |
| 1177 | } |
Willy Tarreau | ffc3fcd | 2012-10-12 20:17:54 +0200 | [diff] [blame] | 1178 | ret = lf_text(tmplog, src, dst + maxsize - tmplog, tmp); |
| 1179 | if (ret == NULL) |
| 1180 | goto out; |
| 1181 | tmplog = ret; |
| 1182 | last_isspace = 0; |
| 1183 | break; |
Willy Tarreau | 773d65f | 2012-10-12 14:56:11 +0200 | [diff] [blame] | 1184 | |
Willy Tarreau | ffc3fcd | 2012-10-12 20:17:54 +0200 | [diff] [blame] | 1185 | case LOG_FMT_SSL_VERSION: // %sslv |
| 1186 | src = NULL; |
Willy Tarreau | b363a1f | 2013-10-01 10:45:07 +0200 | [diff] [blame] | 1187 | conn = objt_conn(s->si[0].end); |
| 1188 | if (conn) { |
| 1189 | if (s->listener->xprt == &ssl_sock) |
| 1190 | src = ssl_sock_get_proto_version(conn); |
| 1191 | } |
Willy Tarreau | ffc3fcd | 2012-10-12 20:17:54 +0200 | [diff] [blame] | 1192 | ret = lf_text(tmplog, src, dst + maxsize - tmplog, tmp); |
| 1193 | if (ret == NULL) |
| 1194 | goto out; |
| 1195 | tmplog = ret; |
| 1196 | last_isspace = 0; |
| 1197 | break; |
| 1198 | #endif |
William Lallemand | 1d70556 | 2012-03-12 12:46:41 +0100 | [diff] [blame] | 1199 | case LOG_FMT_BACKEND: // %b |
William Lallemand | bddd4fd | 2012-02-27 11:23:10 +0100 | [diff] [blame] | 1200 | src = be->id; |
William Lallemand | 5f23240 | 2012-04-05 18:02:55 +0200 | [diff] [blame] | 1201 | ret = lf_text(tmplog, src, dst + maxsize - tmplog, tmp); |
William Lallemand | 1d70556 | 2012-03-12 12:46:41 +0100 | [diff] [blame] | 1202 | if (ret == NULL) |
William Lallemand | bddd4fd | 2012-02-27 11:23:10 +0100 | [diff] [blame] | 1203 | goto out; |
William Lallemand | 1d70556 | 2012-03-12 12:46:41 +0100 | [diff] [blame] | 1204 | tmplog = ret; |
William Lallemand | 51b5dca | 2012-03-26 17:52:55 +0200 | [diff] [blame] | 1205 | last_isspace = 0; |
William Lallemand | bddd4fd | 2012-02-27 11:23:10 +0100 | [diff] [blame] | 1206 | break; |
| 1207 | |
William Lallemand | 1d70556 | 2012-03-12 12:46:41 +0100 | [diff] [blame] | 1208 | case LOG_FMT_SERVER: // %s |
Willy Tarreau | d79a3b2 | 2012-12-28 09:40:16 +0100 | [diff] [blame] | 1209 | switch (obj_type(s->target)) { |
| 1210 | case OBJ_TYPE_SERVER: |
| 1211 | src = objt_server(s->target)->id; |
| 1212 | break; |
| 1213 | case OBJ_TYPE_APPLET: |
| 1214 | src = objt_applet(s->target)->name; |
| 1215 | break; |
| 1216 | default: |
| 1217 | src = "<NOSRV>"; |
| 1218 | break; |
| 1219 | } |
William Lallemand | 5f23240 | 2012-04-05 18:02:55 +0200 | [diff] [blame] | 1220 | ret = lf_text(tmplog, src, dst + maxsize - tmplog, tmp); |
William Lallemand | 1d70556 | 2012-03-12 12:46:41 +0100 | [diff] [blame] | 1221 | if (ret == NULL) |
William Lallemand | bddd4fd | 2012-02-27 11:23:10 +0100 | [diff] [blame] | 1222 | goto out; |
William Lallemand | 1d70556 | 2012-03-12 12:46:41 +0100 | [diff] [blame] | 1223 | tmplog = ret; |
William Lallemand | bddd4fd | 2012-02-27 11:23:10 +0100 | [diff] [blame] | 1224 | last_isspace = 0; |
| 1225 | break; |
| 1226 | |
William Lallemand | 1d70556 | 2012-03-12 12:46:41 +0100 | [diff] [blame] | 1227 | case LOG_FMT_TQ: // %Tq |
William Lallemand | 5f23240 | 2012-04-05 18:02:55 +0200 | [diff] [blame] | 1228 | ret = ltoa_o(t_request, tmplog, dst + maxsize - tmplog); |
William Lallemand | 1d70556 | 2012-03-12 12:46:41 +0100 | [diff] [blame] | 1229 | if (ret == NULL) |
William Lallemand | bddd4fd | 2012-02-27 11:23:10 +0100 | [diff] [blame] | 1230 | goto out; |
William Lallemand | 1d70556 | 2012-03-12 12:46:41 +0100 | [diff] [blame] | 1231 | tmplog = ret; |
William Lallemand | bddd4fd | 2012-02-27 11:23:10 +0100 | [diff] [blame] | 1232 | last_isspace = 0; |
| 1233 | break; |
| 1234 | |
William Lallemand | 1d70556 | 2012-03-12 12:46:41 +0100 | [diff] [blame] | 1235 | case LOG_FMT_TW: // %Tw |
| 1236 | ret = ltoa_o((s->logs.t_queue >= 0) ? s->logs.t_queue - t_request : -1, |
William Lallemand | 5f23240 | 2012-04-05 18:02:55 +0200 | [diff] [blame] | 1237 | tmplog, dst + maxsize - tmplog); |
William Lallemand | 1d70556 | 2012-03-12 12:46:41 +0100 | [diff] [blame] | 1238 | if (ret == NULL) |
William Lallemand | bddd4fd | 2012-02-27 11:23:10 +0100 | [diff] [blame] | 1239 | goto out; |
William Lallemand | 1d70556 | 2012-03-12 12:46:41 +0100 | [diff] [blame] | 1240 | tmplog = ret; |
William Lallemand | bddd4fd | 2012-02-27 11:23:10 +0100 | [diff] [blame] | 1241 | last_isspace = 0; |
| 1242 | break; |
| 1243 | |
William Lallemand | 1d70556 | 2012-03-12 12:46:41 +0100 | [diff] [blame] | 1244 | case LOG_FMT_TC: // %Tc |
| 1245 | ret = ltoa_o((s->logs.t_connect >= 0) ? s->logs.t_connect - s->logs.t_queue : -1, |
William Lallemand | 5f23240 | 2012-04-05 18:02:55 +0200 | [diff] [blame] | 1246 | tmplog, dst + maxsize - tmplog); |
William Lallemand | 1d70556 | 2012-03-12 12:46:41 +0100 | [diff] [blame] | 1247 | if (ret == NULL) |
William Lallemand | bddd4fd | 2012-02-27 11:23:10 +0100 | [diff] [blame] | 1248 | goto out; |
William Lallemand | 1d70556 | 2012-03-12 12:46:41 +0100 | [diff] [blame] | 1249 | tmplog = ret; |
William Lallemand | bddd4fd | 2012-02-27 11:23:10 +0100 | [diff] [blame] | 1250 | last_isspace = 0; |
| 1251 | break; |
| 1252 | |
William Lallemand | 1d70556 | 2012-03-12 12:46:41 +0100 | [diff] [blame] | 1253 | case LOG_FMT_TR: // %Tr |
| 1254 | ret = ltoa_o((s->logs.t_data >= 0) ? s->logs.t_data - s->logs.t_connect : -1, |
William Lallemand | 5f23240 | 2012-04-05 18:02:55 +0200 | [diff] [blame] | 1255 | tmplog, dst + maxsize - tmplog); |
William Lallemand | 1d70556 | 2012-03-12 12:46:41 +0100 | [diff] [blame] | 1256 | if (ret == NULL) |
William Lallemand | bddd4fd | 2012-02-27 11:23:10 +0100 | [diff] [blame] | 1257 | goto out; |
William Lallemand | 1d70556 | 2012-03-12 12:46:41 +0100 | [diff] [blame] | 1258 | tmplog = ret; |
William Lallemand | bddd4fd | 2012-02-27 11:23:10 +0100 | [diff] [blame] | 1259 | last_isspace = 0; |
| 1260 | break; |
| 1261 | |
William Lallemand | 1d70556 | 2012-03-12 12:46:41 +0100 | [diff] [blame] | 1262 | case LOG_FMT_TT: // %Tt |
Willy Tarreau | d79a3b2 | 2012-12-28 09:40:16 +0100 | [diff] [blame] | 1263 | if (!(fe->to_log & LW_BYTES)) |
William Lallemand | 1d70556 | 2012-03-12 12:46:41 +0100 | [diff] [blame] | 1264 | LOGCHAR('+'); |
William Lallemand | 5f23240 | 2012-04-05 18:02:55 +0200 | [diff] [blame] | 1265 | ret = ltoa_o(s->logs.t_close, tmplog, dst + maxsize - tmplog); |
William Lallemand | 1d70556 | 2012-03-12 12:46:41 +0100 | [diff] [blame] | 1266 | if (ret == NULL) |
William Lallemand | bddd4fd | 2012-02-27 11:23:10 +0100 | [diff] [blame] | 1267 | goto out; |
William Lallemand | 1d70556 | 2012-03-12 12:46:41 +0100 | [diff] [blame] | 1268 | tmplog = ret; |
William Lallemand | bddd4fd | 2012-02-27 11:23:10 +0100 | [diff] [blame] | 1269 | last_isspace = 0; |
| 1270 | break; |
| 1271 | |
Willy Tarreau | 2beef58 | 2012-12-20 17:22:52 +0100 | [diff] [blame] | 1272 | case LOG_FMT_STATUS: // %ST |
William Lallemand | 5f23240 | 2012-04-05 18:02:55 +0200 | [diff] [blame] | 1273 | ret = ltoa_o(txn->status, tmplog, dst + maxsize - tmplog); |
William Lallemand | 1d70556 | 2012-03-12 12:46:41 +0100 | [diff] [blame] | 1274 | if (ret == NULL) |
William Lallemand | bddd4fd | 2012-02-27 11:23:10 +0100 | [diff] [blame] | 1275 | goto out; |
William Lallemand | 1d70556 | 2012-03-12 12:46:41 +0100 | [diff] [blame] | 1276 | tmplog = ret; |
William Lallemand | bddd4fd | 2012-02-27 11:23:10 +0100 | [diff] [blame] | 1277 | last_isspace = 0; |
| 1278 | break; |
| 1279 | |
William Lallemand | 1d70556 | 2012-03-12 12:46:41 +0100 | [diff] [blame] | 1280 | case LOG_FMT_BYTES: // %B |
Willy Tarreau | d79a3b2 | 2012-12-28 09:40:16 +0100 | [diff] [blame] | 1281 | if (!(fe->to_log & LW_BYTES)) |
William Lallemand | 1d70556 | 2012-03-12 12:46:41 +0100 | [diff] [blame] | 1282 | LOGCHAR('+'); |
William Lallemand | 5f23240 | 2012-04-05 18:02:55 +0200 | [diff] [blame] | 1283 | ret = lltoa(s->logs.bytes_out, tmplog, dst + maxsize - tmplog); |
William Lallemand | 1d70556 | 2012-03-12 12:46:41 +0100 | [diff] [blame] | 1284 | if (ret == NULL) |
William Lallemand | bddd4fd | 2012-02-27 11:23:10 +0100 | [diff] [blame] | 1285 | goto out; |
William Lallemand | 1d70556 | 2012-03-12 12:46:41 +0100 | [diff] [blame] | 1286 | tmplog = ret; |
William Lallemand | bddd4fd | 2012-02-27 11:23:10 +0100 | [diff] [blame] | 1287 | last_isspace = 0; |
| 1288 | break; |
| 1289 | |
Willy Tarreau | c5259fd | 2012-12-20 15:38:04 +0100 | [diff] [blame] | 1290 | case LOG_FMT_BYTES_UP: // %U |
Willy Tarreau | c5259fd | 2012-12-20 15:38:04 +0100 | [diff] [blame] | 1291 | ret = lltoa(s->logs.bytes_in, tmplog, dst + maxsize - tmplog); |
| 1292 | if (ret == NULL) |
| 1293 | goto out; |
| 1294 | tmplog = ret; |
| 1295 | last_isspace = 0; |
| 1296 | break; |
| 1297 | |
Willy Tarreau | 2beef58 | 2012-12-20 17:22:52 +0100 | [diff] [blame] | 1298 | case LOG_FMT_CCLIENT: // %CC |
William Lallemand | bddd4fd | 2012-02-27 11:23:10 +0100 | [diff] [blame] | 1299 | src = txn->cli_cookie; |
William Lallemand | 5f23240 | 2012-04-05 18:02:55 +0200 | [diff] [blame] | 1300 | ret = lf_text(tmplog, src, dst + maxsize - tmplog, tmp); |
William Lallemand | 1d70556 | 2012-03-12 12:46:41 +0100 | [diff] [blame] | 1301 | if (ret == NULL) |
William Lallemand | 51b5dca | 2012-03-26 17:52:55 +0200 | [diff] [blame] | 1302 | goto out; |
William Lallemand | 1d70556 | 2012-03-12 12:46:41 +0100 | [diff] [blame] | 1303 | tmplog = ret; |
William Lallemand | bddd4fd | 2012-02-27 11:23:10 +0100 | [diff] [blame] | 1304 | last_isspace = 0; |
| 1305 | break; |
| 1306 | |
Willy Tarreau | 2beef58 | 2012-12-20 17:22:52 +0100 | [diff] [blame] | 1307 | case LOG_FMT_CSERVER: // %CS |
William Lallemand | bddd4fd | 2012-02-27 11:23:10 +0100 | [diff] [blame] | 1308 | src = txn->srv_cookie; |
William Lallemand | 5f23240 | 2012-04-05 18:02:55 +0200 | [diff] [blame] | 1309 | ret = lf_text(tmplog, src, dst + maxsize - tmplog, tmp); |
William Lallemand | 1d70556 | 2012-03-12 12:46:41 +0100 | [diff] [blame] | 1310 | if (ret == NULL) |
William Lallemand | 51b5dca | 2012-03-26 17:52:55 +0200 | [diff] [blame] | 1311 | goto out; |
William Lallemand | 1d70556 | 2012-03-12 12:46:41 +0100 | [diff] [blame] | 1312 | tmplog = ret; |
William Lallemand | bddd4fd | 2012-02-27 11:23:10 +0100 | [diff] [blame] | 1313 | last_isspace = 0; |
| 1314 | break; |
| 1315 | |
William Lallemand | 1d70556 | 2012-03-12 12:46:41 +0100 | [diff] [blame] | 1316 | case LOG_FMT_TERMSTATE: // %ts |
Willy Tarreau | 6580c06 | 2012-03-12 15:09:42 +0100 | [diff] [blame] | 1317 | LOGCHAR(sess_term_cond[(s->flags & SN_ERR_MASK) >> SN_ERR_SHIFT]); |
| 1318 | LOGCHAR(sess_fin_state[(s->flags & SN_FINST_MASK) >> SN_FINST_SHIFT]); |
| 1319 | *tmplog = '\0'; |
| 1320 | last_isspace = 0; |
| 1321 | break; |
William Lallemand | bddd4fd | 2012-02-27 11:23:10 +0100 | [diff] [blame] | 1322 | |
William Lallemand | 1d70556 | 2012-03-12 12:46:41 +0100 | [diff] [blame] | 1323 | case LOG_FMT_TERMSTATE_CK: // %tsc, same as TS with cookie state (for mode HTTP) |
William Lallemand | bddd4fd | 2012-02-27 11:23:10 +0100 | [diff] [blame] | 1324 | LOGCHAR(sess_term_cond[(s->flags & SN_ERR_MASK) >> SN_ERR_SHIFT]); |
| 1325 | LOGCHAR(sess_fin_state[(s->flags & SN_FINST_MASK) >> SN_FINST_SHIFT]); |
Willy Tarreau | 6740213 | 2012-05-31 20:40:20 +0200 | [diff] [blame] | 1326 | LOGCHAR((be->ck_opts & PR_CK_ANY) ? sess_cookie[(txn->flags & TX_CK_MASK) >> TX_CK_SHIFT] : '-'); |
| 1327 | LOGCHAR((be->ck_opts & PR_CK_ANY) ? sess_set_cookie[(txn->flags & TX_SCK_MASK) >> TX_SCK_SHIFT] : '-'); |
William Lallemand | bddd4fd | 2012-02-27 11:23:10 +0100 | [diff] [blame] | 1328 | last_isspace = 0; |
| 1329 | break; |
| 1330 | |
William Lallemand | 1d70556 | 2012-03-12 12:46:41 +0100 | [diff] [blame] | 1331 | case LOG_FMT_ACTCONN: // %ac |
William Lallemand | 5f23240 | 2012-04-05 18:02:55 +0200 | [diff] [blame] | 1332 | ret = ltoa_o(actconn, tmplog, dst + maxsize - tmplog); |
William Lallemand | 1d70556 | 2012-03-12 12:46:41 +0100 | [diff] [blame] | 1333 | if (ret == NULL) |
William Lallemand | bddd4fd | 2012-02-27 11:23:10 +0100 | [diff] [blame] | 1334 | goto out; |
William Lallemand | 1d70556 | 2012-03-12 12:46:41 +0100 | [diff] [blame] | 1335 | tmplog = ret; |
William Lallemand | bddd4fd | 2012-02-27 11:23:10 +0100 | [diff] [blame] | 1336 | last_isspace = 0; |
| 1337 | break; |
| 1338 | |
William Lallemand | 1d70556 | 2012-03-12 12:46:41 +0100 | [diff] [blame] | 1339 | case LOG_FMT_FECONN: // %fc |
William Lallemand | 5f23240 | 2012-04-05 18:02:55 +0200 | [diff] [blame] | 1340 | ret = ltoa_o(fe->feconn, tmplog, dst + maxsize - tmplog); |
William Lallemand | 1d70556 | 2012-03-12 12:46:41 +0100 | [diff] [blame] | 1341 | if (ret == NULL) |
William Lallemand | bddd4fd | 2012-02-27 11:23:10 +0100 | [diff] [blame] | 1342 | goto out; |
William Lallemand | 1d70556 | 2012-03-12 12:46:41 +0100 | [diff] [blame] | 1343 | tmplog = ret; |
William Lallemand | bddd4fd | 2012-02-27 11:23:10 +0100 | [diff] [blame] | 1344 | last_isspace = 0; |
| 1345 | break; |
| 1346 | |
William Lallemand | 1d70556 | 2012-03-12 12:46:41 +0100 | [diff] [blame] | 1347 | case LOG_FMT_BECONN: // %bc |
William Lallemand | 5f23240 | 2012-04-05 18:02:55 +0200 | [diff] [blame] | 1348 | ret = ltoa_o(be->beconn, tmplog, dst + maxsize - tmplog); |
William Lallemand | 1d70556 | 2012-03-12 12:46:41 +0100 | [diff] [blame] | 1349 | if (ret == NULL) |
William Lallemand | bddd4fd | 2012-02-27 11:23:10 +0100 | [diff] [blame] | 1350 | goto out; |
William Lallemand | 1d70556 | 2012-03-12 12:46:41 +0100 | [diff] [blame] | 1351 | tmplog = ret; |
William Lallemand | bddd4fd | 2012-02-27 11:23:10 +0100 | [diff] [blame] | 1352 | last_isspace = 0; |
| 1353 | break; |
| 1354 | |
William Lallemand | 1d70556 | 2012-03-12 12:46:41 +0100 | [diff] [blame] | 1355 | case LOG_FMT_SRVCONN: // %sc |
Willy Tarreau | 54a08d3 | 2012-11-12 01:14:56 +0100 | [diff] [blame] | 1356 | ret = ultoa_o(objt_server(s->target) ? |
Willy Tarreau | 3fdb366 | 2012-11-12 00:42:33 +0100 | [diff] [blame] | 1357 | objt_server(s->target)->cur_sess : |
William Lallemand | 5f23240 | 2012-04-05 18:02:55 +0200 | [diff] [blame] | 1358 | 0, tmplog, dst + maxsize - tmplog); |
William Lallemand | 1d70556 | 2012-03-12 12:46:41 +0100 | [diff] [blame] | 1359 | if (ret == NULL) |
William Lallemand | bddd4fd | 2012-02-27 11:23:10 +0100 | [diff] [blame] | 1360 | goto out; |
William Lallemand | 1d70556 | 2012-03-12 12:46:41 +0100 | [diff] [blame] | 1361 | tmplog = ret; |
William Lallemand | bddd4fd | 2012-02-27 11:23:10 +0100 | [diff] [blame] | 1362 | last_isspace = 0; |
| 1363 | break; |
| 1364 | |
William Lallemand | 1d70556 | 2012-03-12 12:46:41 +0100 | [diff] [blame] | 1365 | case LOG_FMT_RETRIES: // %rq |
William Lallemand | bddd4fd | 2012-02-27 11:23:10 +0100 | [diff] [blame] | 1366 | if (s->flags & SN_REDISP) |
William Lallemand | 1d70556 | 2012-03-12 12:46:41 +0100 | [diff] [blame] | 1367 | LOGCHAR('+'); |
| 1368 | ret = ltoa_o((s->req->cons->conn_retries>0) ? |
| 1369 | (be->conn_retries - s->req->cons->conn_retries) : |
William Lallemand | 5f23240 | 2012-04-05 18:02:55 +0200 | [diff] [blame] | 1370 | be->conn_retries, tmplog, dst + maxsize - tmplog); |
William Lallemand | 1d70556 | 2012-03-12 12:46:41 +0100 | [diff] [blame] | 1371 | if (ret == NULL) |
William Lallemand | 51b5dca | 2012-03-26 17:52:55 +0200 | [diff] [blame] | 1372 | goto out; |
William Lallemand | 1d70556 | 2012-03-12 12:46:41 +0100 | [diff] [blame] | 1373 | tmplog = ret; |
William Lallemand | bddd4fd | 2012-02-27 11:23:10 +0100 | [diff] [blame] | 1374 | last_isspace = 0; |
| 1375 | break; |
| 1376 | |
William Lallemand | 1d70556 | 2012-03-12 12:46:41 +0100 | [diff] [blame] | 1377 | case LOG_FMT_SRVQUEUE: // %sq |
William Lallemand | 5f23240 | 2012-04-05 18:02:55 +0200 | [diff] [blame] | 1378 | ret = ltoa_o(s->logs.srv_queue_size, tmplog, dst + maxsize - tmplog); |
William Lallemand | 1d70556 | 2012-03-12 12:46:41 +0100 | [diff] [blame] | 1379 | if (ret == NULL) |
William Lallemand | bddd4fd | 2012-02-27 11:23:10 +0100 | [diff] [blame] | 1380 | goto out; |
William Lallemand | 1d70556 | 2012-03-12 12:46:41 +0100 | [diff] [blame] | 1381 | tmplog = ret; |
William Lallemand | bddd4fd | 2012-02-27 11:23:10 +0100 | [diff] [blame] | 1382 | last_isspace = 0; |
| 1383 | break; |
| 1384 | |
William Lallemand | 1d70556 | 2012-03-12 12:46:41 +0100 | [diff] [blame] | 1385 | case LOG_FMT_BCKQUEUE: // %bq |
William Lallemand | 5f23240 | 2012-04-05 18:02:55 +0200 | [diff] [blame] | 1386 | ret = ltoa_o(s->logs.prx_queue_size, tmplog, dst + maxsize - tmplog); |
William Lallemand | 1d70556 | 2012-03-12 12:46:41 +0100 | [diff] [blame] | 1387 | if (ret == NULL) |
William Lallemand | bddd4fd | 2012-02-27 11:23:10 +0100 | [diff] [blame] | 1388 | goto out; |
William Lallemand | 1d70556 | 2012-03-12 12:46:41 +0100 | [diff] [blame] | 1389 | tmplog = ret; |
William Lallemand | bddd4fd | 2012-02-27 11:23:10 +0100 | [diff] [blame] | 1390 | last_isspace = 0; |
| 1391 | break; |
| 1392 | |
William Lallemand | 1d70556 | 2012-03-12 12:46:41 +0100 | [diff] [blame] | 1393 | case LOG_FMT_HDRREQUEST: // %hr |
William Lallemand | bddd4fd | 2012-02-27 11:23:10 +0100 | [diff] [blame] | 1394 | /* request header */ |
Willy Tarreau | d79a3b2 | 2012-12-28 09:40:16 +0100 | [diff] [blame] | 1395 | if (fe->nb_req_cap && txn->req.cap) { |
William Lallemand | bddd4fd | 2012-02-27 11:23:10 +0100 | [diff] [blame] | 1396 | if (tmp->options & LOG_OPT_QUOTE) |
| 1397 | LOGCHAR('"'); |
| 1398 | LOGCHAR('{'); |
| 1399 | for (hdr = 0; hdr < fe->nb_req_cap; hdr++) { |
| 1400 | if (hdr) |
| 1401 | LOGCHAR('|'); |
William Lallemand | 51b5dca | 2012-03-26 17:52:55 +0200 | [diff] [blame] | 1402 | if (txn->req.cap[hdr] != NULL) { |
William Lallemand | 1d70556 | 2012-03-12 12:46:41 +0100 | [diff] [blame] | 1403 | ret = encode_string(tmplog, dst + maxsize, |
William Lallemand | bddd4fd | 2012-02-27 11:23:10 +0100 | [diff] [blame] | 1404 | '#', hdr_encode_map, txn->req.cap[hdr]); |
William Lallemand | 1d70556 | 2012-03-12 12:46:41 +0100 | [diff] [blame] | 1405 | if (ret == NULL || *ret != '\0') |
William Lallemand | 51b5dca | 2012-03-26 17:52:55 +0200 | [diff] [blame] | 1406 | goto out; |
William Lallemand | 1d70556 | 2012-03-12 12:46:41 +0100 | [diff] [blame] | 1407 | tmplog = ret; |
William Lallemand | 51b5dca | 2012-03-26 17:52:55 +0200 | [diff] [blame] | 1408 | } |
William Lallemand | bddd4fd | 2012-02-27 11:23:10 +0100 | [diff] [blame] | 1409 | } |
| 1410 | LOGCHAR('}'); |
William Lallemand | 51b5dca | 2012-03-26 17:52:55 +0200 | [diff] [blame] | 1411 | if (tmp->options & LOG_OPT_QUOTE) |
| 1412 | LOGCHAR('"'); |
William Lallemand | bddd4fd | 2012-02-27 11:23:10 +0100 | [diff] [blame] | 1413 | last_isspace = 0; |
| 1414 | } |
William Lallemand | bddd4fd | 2012-02-27 11:23:10 +0100 | [diff] [blame] | 1415 | break; |
| 1416 | |
William Lallemand | 1d70556 | 2012-03-12 12:46:41 +0100 | [diff] [blame] | 1417 | case LOG_FMT_HDRREQUESTLIST: // %hrl |
William Lallemand | bddd4fd | 2012-02-27 11:23:10 +0100 | [diff] [blame] | 1418 | /* request header list */ |
Willy Tarreau | d79a3b2 | 2012-12-28 09:40:16 +0100 | [diff] [blame] | 1419 | if (fe->nb_req_cap && txn->req.cap) { |
William Lallemand | bddd4fd | 2012-02-27 11:23:10 +0100 | [diff] [blame] | 1420 | for (hdr = 0; hdr < fe->nb_req_cap; hdr++) { |
| 1421 | if (hdr > 0) |
| 1422 | LOGCHAR(' '); |
| 1423 | if (tmp->options & LOG_OPT_QUOTE) |
| 1424 | LOGCHAR('"'); |
| 1425 | if (txn->req.cap[hdr] != NULL) { |
William Lallemand | 1d70556 | 2012-03-12 12:46:41 +0100 | [diff] [blame] | 1426 | ret = encode_string(tmplog, dst + maxsize, |
William Lallemand | bddd4fd | 2012-02-27 11:23:10 +0100 | [diff] [blame] | 1427 | '#', hdr_encode_map, txn->req.cap[hdr]); |
William Lallemand | 1d70556 | 2012-03-12 12:46:41 +0100 | [diff] [blame] | 1428 | if (ret == NULL || *ret != '\0') |
William Lallemand | 51b5dca | 2012-03-26 17:52:55 +0200 | [diff] [blame] | 1429 | goto out; |
William Lallemand | 1d70556 | 2012-03-12 12:46:41 +0100 | [diff] [blame] | 1430 | tmplog = ret; |
William Lallemand | bddd4fd | 2012-02-27 11:23:10 +0100 | [diff] [blame] | 1431 | } else if (!(tmp->options & LOG_OPT_QUOTE)) |
| 1432 | LOGCHAR('-'); |
| 1433 | if (tmp->options & LOG_OPT_QUOTE) |
| 1434 | LOGCHAR('"'); |
William Lallemand | bddd4fd | 2012-02-27 11:23:10 +0100 | [diff] [blame] | 1435 | last_isspace = 0; |
| 1436 | } |
| 1437 | } |
| 1438 | break; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1439 | |
William Lallemand | 1d70556 | 2012-03-12 12:46:41 +0100 | [diff] [blame] | 1440 | |
| 1441 | case LOG_FMT_HDRRESPONS: // %hs |
William Lallemand | bddd4fd | 2012-02-27 11:23:10 +0100 | [diff] [blame] | 1442 | /* response header */ |
Willy Tarreau | d79a3b2 | 2012-12-28 09:40:16 +0100 | [diff] [blame] | 1443 | if (fe->nb_rsp_cap && txn->rsp.cap) { |
William Lallemand | bddd4fd | 2012-02-27 11:23:10 +0100 | [diff] [blame] | 1444 | if (tmp->options & LOG_OPT_QUOTE) |
| 1445 | LOGCHAR('"'); |
| 1446 | LOGCHAR('{'); |
| 1447 | for (hdr = 0; hdr < fe->nb_rsp_cap; hdr++) { |
| 1448 | if (hdr) |
| 1449 | LOGCHAR('|'); |
William Lallemand | 51b5dca | 2012-03-26 17:52:55 +0200 | [diff] [blame] | 1450 | if (txn->rsp.cap[hdr] != NULL) { |
William Lallemand | 1d70556 | 2012-03-12 12:46:41 +0100 | [diff] [blame] | 1451 | ret = encode_string(tmplog, dst + maxsize, |
| 1452 | '#', hdr_encode_map, txn->rsp.cap[hdr]); |
| 1453 | if (ret == NULL || *ret != '\0') |
William Lallemand | 51b5dca | 2012-03-26 17:52:55 +0200 | [diff] [blame] | 1454 | goto out; |
William Lallemand | 1d70556 | 2012-03-12 12:46:41 +0100 | [diff] [blame] | 1455 | tmplog = ret; |
William Lallemand | 51b5dca | 2012-03-26 17:52:55 +0200 | [diff] [blame] | 1456 | } |
William Lallemand | bddd4fd | 2012-02-27 11:23:10 +0100 | [diff] [blame] | 1457 | } |
| 1458 | LOGCHAR('}'); |
| 1459 | last_isspace = 0; |
| 1460 | if (tmp->options & LOG_OPT_QUOTE) |
| 1461 | LOGCHAR('"'); |
| 1462 | } |
William Lallemand | bddd4fd | 2012-02-27 11:23:10 +0100 | [diff] [blame] | 1463 | break; |
| 1464 | |
William Lallemand | 1d70556 | 2012-03-12 12:46:41 +0100 | [diff] [blame] | 1465 | case LOG_FMT_HDRRESPONSLIST: // %hsl |
William Lallemand | bddd4fd | 2012-02-27 11:23:10 +0100 | [diff] [blame] | 1466 | /* response header list */ |
Willy Tarreau | d79a3b2 | 2012-12-28 09:40:16 +0100 | [diff] [blame] | 1467 | if (fe->nb_rsp_cap && txn->rsp.cap) { |
William Lallemand | bddd4fd | 2012-02-27 11:23:10 +0100 | [diff] [blame] | 1468 | for (hdr = 0; hdr < fe->nb_rsp_cap; hdr++) { |
| 1469 | if (hdr > 0) |
| 1470 | LOGCHAR(' '); |
| 1471 | if (tmp->options & LOG_OPT_QUOTE) |
| 1472 | LOGCHAR('"'); |
| 1473 | if (txn->rsp.cap[hdr] != NULL) { |
William Lallemand | 1d70556 | 2012-03-12 12:46:41 +0100 | [diff] [blame] | 1474 | ret = encode_string(tmplog, dst + maxsize, |
| 1475 | '#', hdr_encode_map, txn->rsp.cap[hdr]); |
| 1476 | if (ret == NULL || *ret != '\0') |
William Lallemand | 51b5dca | 2012-03-26 17:52:55 +0200 | [diff] [blame] | 1477 | goto out; |
William Lallemand | 1d70556 | 2012-03-12 12:46:41 +0100 | [diff] [blame] | 1478 | tmplog = ret; |
William Lallemand | bddd4fd | 2012-02-27 11:23:10 +0100 | [diff] [blame] | 1479 | } else if (!(tmp->options & LOG_OPT_QUOTE)) |
| 1480 | LOGCHAR('-'); |
| 1481 | if (tmp->options & LOG_OPT_QUOTE) |
| 1482 | LOGCHAR('"'); |
William Lallemand | bddd4fd | 2012-02-27 11:23:10 +0100 | [diff] [blame] | 1483 | last_isspace = 0; |
| 1484 | } |
| 1485 | } |
| 1486 | break; |
| 1487 | |
William Lallemand | 1d70556 | 2012-03-12 12:46:41 +0100 | [diff] [blame] | 1488 | case LOG_FMT_REQ: // %r |
William Lallemand | bddd4fd | 2012-02-27 11:23:10 +0100 | [diff] [blame] | 1489 | /* Request */ |
| 1490 | if (tmp->options & LOG_OPT_QUOTE) |
| 1491 | LOGCHAR('"'); |
| 1492 | uri = txn->uri ? txn->uri : "<BADREQ>"; |
William Lallemand | 1d70556 | 2012-03-12 12:46:41 +0100 | [diff] [blame] | 1493 | ret = encode_string(tmplog, dst + maxsize, |
William Lallemand | bddd4fd | 2012-02-27 11:23:10 +0100 | [diff] [blame] | 1494 | '#', url_encode_map, uri); |
William Lallemand | 1d70556 | 2012-03-12 12:46:41 +0100 | [diff] [blame] | 1495 | if (ret == NULL || *ret != '\0') |
William Lallemand | 51b5dca | 2012-03-26 17:52:55 +0200 | [diff] [blame] | 1496 | goto out; |
William Lallemand | 1d70556 | 2012-03-12 12:46:41 +0100 | [diff] [blame] | 1497 | tmplog = ret; |
William Lallemand | bddd4fd | 2012-02-27 11:23:10 +0100 | [diff] [blame] | 1498 | if (tmp->options & LOG_OPT_QUOTE) |
| 1499 | LOGCHAR('"'); |
William Lallemand | bddd4fd | 2012-02-27 11:23:10 +0100 | [diff] [blame] | 1500 | last_isspace = 0; |
| 1501 | break; |
William Lallemand | 5f23240 | 2012-04-05 18:02:55 +0200 | [diff] [blame] | 1502 | |
| 1503 | case LOG_FMT_COUNTER: // %rt |
| 1504 | if (tmp->options & LOG_OPT_HEXA) { |
Willy Tarreau | 1f0da24 | 2014-01-25 11:01:50 +0100 | [diff] [blame] | 1505 | iret = snprintf(tmplog, dst + maxsize - tmplog, "%04X", s->uniq_id); |
William Lallemand | 5f23240 | 2012-04-05 18:02:55 +0200 | [diff] [blame] | 1506 | if (iret < 0 || iret > dst + maxsize - tmplog) |
| 1507 | goto out; |
| 1508 | last_isspace = 0; |
| 1509 | tmplog += iret; |
| 1510 | } else { |
Willy Tarreau | 1f0da24 | 2014-01-25 11:01:50 +0100 | [diff] [blame] | 1511 | ret = ltoa_o(s->uniq_id, tmplog, dst + maxsize - tmplog); |
William Lallemand | 5f23240 | 2012-04-05 18:02:55 +0200 | [diff] [blame] | 1512 | if (ret == NULL) |
| 1513 | goto out; |
| 1514 | tmplog = ret; |
| 1515 | last_isspace = 0; |
| 1516 | } |
| 1517 | break; |
| 1518 | |
| 1519 | case LOG_FMT_HOSTNAME: // %H |
| 1520 | src = hostname; |
| 1521 | ret = lf_text(tmplog, src, dst + maxsize - tmplog, tmp); |
| 1522 | if (ret == NULL) |
| 1523 | goto out; |
| 1524 | tmplog = ret; |
| 1525 | last_isspace = 0; |
| 1526 | break; |
| 1527 | |
| 1528 | case LOG_FMT_PID: // %pid |
| 1529 | if (tmp->options & LOG_OPT_HEXA) { |
| 1530 | iret = snprintf(tmplog, dst + maxsize - tmplog, "%04X", pid); |
| 1531 | if (iret < 0 || iret > dst + maxsize - tmplog) |
| 1532 | goto out; |
| 1533 | last_isspace = 0; |
| 1534 | tmplog += iret; |
| 1535 | } else { |
| 1536 | ret = ltoa_o(pid, tmplog, dst + maxsize - tmplog); |
| 1537 | if (ret == NULL) |
| 1538 | goto out; |
| 1539 | tmplog = ret; |
| 1540 | last_isspace = 0; |
| 1541 | } |
| 1542 | break; |
William Lallemand | a73203e | 2012-03-12 12:48:57 +0100 | [diff] [blame] | 1543 | |
| 1544 | case LOG_FMT_UNIQUEID: // %ID |
William Lallemand | 5b7ea3a | 2013-08-28 15:44:19 +0200 | [diff] [blame] | 1545 | ret = NULL; |
William Lallemand | a73203e | 2012-03-12 12:48:57 +0100 | [diff] [blame] | 1546 | src = s->unique_id; |
Thierry FOURNIER | 1be6910 | 2014-04-15 01:38:48 +0200 | [diff] [blame] | 1547 | ret = lf_text(tmplog, src, maxsize - (tmplog - dst), tmp); |
William Lallemand | a73203e | 2012-03-12 12:48:57 +0100 | [diff] [blame] | 1548 | if (ret == NULL) |
| 1549 | goto out; |
| 1550 | tmplog = ret; |
| 1551 | last_isspace = 0; |
| 1552 | break; |
| 1553 | |
William Lallemand | bddd4fd | 2012-02-27 11:23:10 +0100 | [diff] [blame] | 1554 | } |
| 1555 | } |
| 1556 | |
| 1557 | out: |
William Lallemand | 1d70556 | 2012-03-12 12:46:41 +0100 | [diff] [blame] | 1558 | /* *tmplog is a unused character */ |
| 1559 | *tmplog = '\0'; |
Willy Tarreau | df97447 | 2012-12-28 02:44:01 +0100 | [diff] [blame] | 1560 | return tmplog - dst; |
William Lallemand | bddd4fd | 2012-02-27 11:23:10 +0100 | [diff] [blame] | 1561 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1562 | } |
| 1563 | |
William Lallemand | 1d70556 | 2012-03-12 12:46:41 +0100 | [diff] [blame] | 1564 | /* |
| 1565 | * send a log for the session when we have enough info about it. |
| 1566 | * Will not log if the frontend has no log defined. |
| 1567 | */ |
| 1568 | void sess_log(struct session *s) |
| 1569 | { |
| 1570 | char *tmplog; |
| 1571 | int size, err, level; |
| 1572 | |
| 1573 | /* if we don't want to log normal traffic, return now */ |
Willy Tarreau | 570f221 | 2013-06-10 16:42:09 +0200 | [diff] [blame] | 1574 | err = (s->flags & SN_REDISP) || |
| 1575 | ((s->flags & SN_ERR_MASK) > SN_ERR_LOCAL) || |
| 1576 | (((s->flags & SN_ERR_MASK) == SN_ERR_NONE) && |
| 1577 | (s->req->cons->conn_retries != s->be->conn_retries)) || |
| 1578 | ((s->fe->mode == PR_MODE_HTTP) && s->txn.status >= 500); |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1579 | |
William Lallemand | 1d70556 | 2012-03-12 12:46:41 +0100 | [diff] [blame] | 1580 | if (!err && (s->fe->options2 & PR_O2_NOLOGNORM)) |
| 1581 | return; |
William Lallemand | bddd4fd | 2012-02-27 11:23:10 +0100 | [diff] [blame] | 1582 | |
William Lallemand | 1d70556 | 2012-03-12 12:46:41 +0100 | [diff] [blame] | 1583 | if (LIST_ISEMPTY(&s->fe->logsrvs)) |
| 1584 | return; |
William Lallemand | bddd4fd | 2012-02-27 11:23:10 +0100 | [diff] [blame] | 1585 | |
Willy Tarreau | abcd514 | 2013-06-11 17:18:02 +0200 | [diff] [blame] | 1586 | if (s->logs.level) { /* loglevel was overridden */ |
| 1587 | if (s->logs.level == -1) { |
| 1588 | s->logs.logwait = 0; /* logs disabled */ |
| 1589 | return; |
| 1590 | } |
| 1591 | level = s->logs.level - 1; |
| 1592 | } |
| 1593 | else { |
| 1594 | level = LOG_INFO; |
| 1595 | if (err && (s->fe->options2 & PR_O2_LOGERRORS)) |
| 1596 | level = LOG_ERR; |
| 1597 | } |
William Lallemand | 1d70556 | 2012-03-12 12:46:41 +0100 | [diff] [blame] | 1598 | |
William Lallemand | 5b7ea3a | 2013-08-28 15:44:19 +0200 | [diff] [blame] | 1599 | /* if unique-id was not generated */ |
| 1600 | if (!s->unique_id && !LIST_ISEMPTY(&s->fe->format_unique_id)) { |
| 1601 | if ((s->unique_id = pool_alloc2(pool2_uniqueid)) != NULL) |
| 1602 | build_logline(s, s->unique_id, UNIQUEID_LEN, &s->fe->format_unique_id); |
| 1603 | } |
| 1604 | |
William Lallemand | 1d70556 | 2012-03-12 12:46:41 +0100 | [diff] [blame] | 1605 | tmplog = update_log_hdr(); |
| 1606 | size = tmplog - logline; |
| 1607 | size += build_logline(s, tmplog, sizeof(logline) - size, &s->fe->logformat); |
| 1608 | if (size > 0) { |
Willy Tarreau | df97447 | 2012-12-28 02:44:01 +0100 | [diff] [blame] | 1609 | __send_log(s->fe, level, logline, size + 1); |
William Lallemand | 1d70556 | 2012-03-12 12:46:41 +0100 | [diff] [blame] | 1610 | s->logs.logwait = 0; |
| 1611 | } |
| 1612 | } |
William Lallemand | bddd4fd | 2012-02-27 11:23:10 +0100 | [diff] [blame] | 1613 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1614 | /* |
| 1615 | * Local variables: |
| 1616 | * c-indent-level: 8 |
| 1617 | * c-basic-offset: 8 |
| 1618 | * End: |
| 1619 | */ |