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> |
Andrew Hayworth | 0ebc55f | 2015-04-27 21:37:03 +0000 | [diff] [blame] | 35 | #include <proto/proto_http.h> |
Willy Tarreau | ec6c5df | 2008-07-15 00:22:45 +0200 | [diff] [blame] | 36 | #include <proto/log.h> |
Willy Tarreau | c836845 | 2012-12-21 00:09:23 +0100 | [diff] [blame] | 37 | #include <proto/sample.h> |
Willy Tarreau | fb0afa7 | 2015-04-03 14:46:27 +0200 | [diff] [blame] | 38 | #include <proto/stream.h> |
Willy Tarreau | 827aee9 | 2011-03-10 16:55:02 +0100 | [diff] [blame] | 39 | #include <proto/stream_interface.h> |
Willy Tarreau | 773d65f | 2012-10-12 14:56:11 +0200 | [diff] [blame] | 40 | #ifdef USE_OPENSSL |
| 41 | #include <proto/ssl_sock.h> |
| 42 | #endif |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 43 | |
Dragan Dosen | 43885c7 | 2015-10-01 13:18:13 +0200 | [diff] [blame] | 44 | struct log_fmt { |
| 45 | char *name; |
| 46 | struct { |
| 47 | struct chunk sep1; /* first pid separator */ |
| 48 | struct chunk sep2; /* second pid separator */ |
| 49 | } pid; |
| 50 | }; |
| 51 | |
| 52 | static const struct log_fmt log_formats[LOG_FORMATS] = { |
| 53 | [LOG_FORMAT_RFC3164] = { |
| 54 | .name = "rfc3164", |
| 55 | .pid = { |
| 56 | .sep1 = { .str = "[", .len = 1 }, |
| 57 | .sep2 = { .str = "]: ", .len = 3 } |
| 58 | } |
| 59 | }, |
| 60 | [LOG_FORMAT_RFC5424] = { |
| 61 | .name = "rfc5424", |
| 62 | .pid = { |
| 63 | .sep1 = { .str = " ", .len = 1 }, |
| 64 | .sep2 = { .str = " - ", .len = 3 } |
| 65 | } |
| 66 | } |
Dragan Dosen | 1322d09 | 2015-09-22 16:05:32 +0200 | [diff] [blame] | 67 | }; |
| 68 | |
Dragan Dosen | 835b921 | 2016-02-12 13:23:03 +0100 | [diff] [blame] | 69 | #define FD_SETS_ARE_BITFIELDS |
| 70 | #ifdef FD_SETS_ARE_BITFIELDS |
| 71 | /* |
| 72 | * This map is used with all the FD_* macros to check whether a particular bit |
| 73 | * is set or not. Each bit represents an ACSII code. FD_SET() sets those bytes |
| 74 | * which should be escaped. When FD_ISSET() returns non-zero, it means that the |
| 75 | * byte should be escaped. Be careful to always pass bytes from 0 to 255 |
| 76 | * exclusively to the macros. |
| 77 | */ |
| 78 | fd_set rfc5424_escape_map[(sizeof(fd_set) > (256/8)) ? 1 : ((256/8) / sizeof(fd_set))]; |
| 79 | |
| 80 | #else |
| 81 | #error "Check if your OS uses bitfields for fd_sets" |
| 82 | #endif |
| 83 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 84 | const char *log_facilities[NB_LOG_FACILITIES] = { |
| 85 | "kern", "user", "mail", "daemon", |
| 86 | "auth", "syslog", "lpr", "news", |
| 87 | "uucp", "cron", "auth2", "ftp", |
| 88 | "ntp", "audit", "alert", "cron2", |
| 89 | "local0", "local1", "local2", "local3", |
| 90 | "local4", "local5", "local6", "local7" |
| 91 | }; |
| 92 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 93 | const char *log_levels[NB_LOG_LEVELS] = { |
| 94 | "emerg", "alert", "crit", "err", |
| 95 | "warning", "notice", "info", "debug" |
| 96 | }; |
| 97 | |
Willy Tarreau | 570f221 | 2013-06-10 16:42:09 +0200 | [diff] [blame] | 98 | 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] | 99 | 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] | 100 | |
William Lallemand | 723b73a | 2012-02-08 16:37:49 +0100 | [diff] [blame] | 101 | |
| 102 | /* log_format */ |
| 103 | struct logformat_type { |
| 104 | char *name; |
| 105 | int type; |
William Lallemand | bddd4fd | 2012-02-27 11:23:10 +0100 | [diff] [blame] | 106 | int mode; |
William Lallemand | 5e19a28 | 2012-04-02 16:22:10 +0200 | [diff] [blame] | 107 | int lw; /* logwait bitsfield */ |
William Lallemand | b7ff6a3 | 2012-03-02 14:35:21 +0100 | [diff] [blame] | 108 | int (*config_callback)(struct logformat_node *node, struct proxy *curproxy); |
Willy Tarreau | 2beef58 | 2012-12-20 17:22:52 +0100 | [diff] [blame] | 109 | const char *replace_by; /* new option to use instead of old one */ |
William Lallemand | 723b73a | 2012-02-08 16:37:49 +0100 | [diff] [blame] | 110 | }; |
| 111 | |
William Lallemand | b7ff6a3 | 2012-03-02 14:35:21 +0100 | [diff] [blame] | 112 | int prepare_addrsource(struct logformat_node *node, struct proxy *curproxy); |
| 113 | |
William Lallemand | 723b73a | 2012-02-08 16:37:49 +0100 | [diff] [blame] | 114 | /* log_format variable names */ |
| 115 | static const struct logformat_type logformat_keywords[] = { |
William Lallemand | 5e19a28 | 2012-04-02 16:22:10 +0200 | [diff] [blame] | 116 | { "o", LOG_FMT_GLOBAL, PR_MODE_TCP, 0, NULL }, /* global option */ |
Willy Tarreau | 2beef58 | 2012-12-20 17:22:52 +0100 | [diff] [blame] | 117 | |
| 118 | /* please keep these lines sorted ! */ |
| 119 | { "B", LOG_FMT_BYTES, PR_MODE_TCP, LW_BYTES, NULL }, /* bytes from server to client */ |
| 120 | { "CC", LOG_FMT_CCLIENT, PR_MODE_HTTP, LW_REQHDR, NULL }, /* client cookie */ |
| 121 | { "CS", LOG_FMT_CSERVER, PR_MODE_HTTP, LW_RSPHDR, NULL }, /* server cookie */ |
| 122 | { "H", LOG_FMT_HOSTNAME, PR_MODE_TCP, LW_INIT, NULL }, /* Hostname */ |
| 123 | { "ID", LOG_FMT_UNIQUEID, PR_MODE_HTTP, LW_BYTES, NULL }, /* Unique ID */ |
Willy Tarreau | 4bf9963 | 2014-06-13 12:21:40 +0200 | [diff] [blame] | 124 | { "ST", LOG_FMT_STATUS, PR_MODE_TCP, LW_RESP, NULL }, /* status code */ |
William Lallemand | 5e19a28 | 2012-04-02 16:22:10 +0200 | [diff] [blame] | 125 | { "T", LOG_FMT_DATEGMT, PR_MODE_TCP, LW_INIT, NULL }, /* date GMT */ |
Willy Tarreau | 2beef58 | 2012-12-20 17:22:52 +0100 | [diff] [blame] | 126 | { "Tc", LOG_FMT_TC, PR_MODE_TCP, LW_BYTES, NULL }, /* Tc */ |
Yuxans Yao | 4e25b01 | 2012-10-19 10:36:09 +0800 | [diff] [blame] | 127 | { "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] | 128 | { "Tq", LOG_FMT_TQ, PR_MODE_HTTP, LW_BYTES, NULL }, /* Tq */ |
William Lallemand | 5e19a28 | 2012-04-02 16:22:10 +0200 | [diff] [blame] | 129 | { "Tr", LOG_FMT_TR, PR_MODE_HTTP, LW_BYTES, NULL }, /* Tr */ |
Willy Tarreau | 2beef58 | 2012-12-20 17:22:52 +0100 | [diff] [blame] | 130 | { "Ts", LOG_FMT_TS, PR_MODE_TCP, LW_INIT, NULL }, /* timestamp GMT */ |
William Lallemand | 5e19a28 | 2012-04-02 16:22:10 +0200 | [diff] [blame] | 131 | { "Tt", LOG_FMT_TT, PR_MODE_TCP, LW_BYTES, NULL }, /* Tt */ |
Willy Tarreau | 2beef58 | 2012-12-20 17:22:52 +0100 | [diff] [blame] | 132 | { "Tw", LOG_FMT_TW, PR_MODE_TCP, LW_BYTES, NULL }, /* Tw */ |
| 133 | { "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] | 134 | { "ac", LOG_FMT_ACTCONN, PR_MODE_TCP, LW_BYTES, NULL }, /* actconn */ |
Willy Tarreau | 2beef58 | 2012-12-20 17:22:52 +0100 | [diff] [blame] | 135 | { "b", LOG_FMT_BACKEND, PR_MODE_TCP, LW_INIT, NULL }, /* backend */ |
William Lallemand | 5e19a28 | 2012-04-02 16:22:10 +0200 | [diff] [blame] | 136 | { "bc", LOG_FMT_BECONN, PR_MODE_TCP, LW_BYTES, NULL }, /* beconn */ |
Willy Tarreau | 2beef58 | 2012-12-20 17:22:52 +0100 | [diff] [blame] | 137 | { "bi", LOG_FMT_BACKENDIP, PR_MODE_TCP, LW_BCKIP, prepare_addrsource }, /* backend source ip */ |
| 138 | { "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] | 139 | { "bq", LOG_FMT_BCKQUEUE, PR_MODE_TCP, LW_BYTES, NULL }, /* backend_queue */ |
Willy Tarreau | 2beef58 | 2012-12-20 17:22:52 +0100 | [diff] [blame] | 140 | { "ci", LOG_FMT_CLIENTIP, PR_MODE_TCP, LW_CLIP, NULL }, /* client ip */ |
| 141 | { "cp", LOG_FMT_CLIENTPORT, PR_MODE_TCP, LW_CLIP, NULL }, /* client port */ |
| 142 | { "f", LOG_FMT_FRONTEND, PR_MODE_TCP, LW_INIT, NULL }, /* frontend */ |
| 143 | { "fc", LOG_FMT_FECONN, PR_MODE_TCP, LW_BYTES, NULL }, /* feconn */ |
| 144 | { "fi", LOG_FMT_FRONTENDIP, PR_MODE_TCP, LW_FRTIP, NULL }, /* frontend ip */ |
| 145 | { "fp", LOG_FMT_FRONTENDPORT, PR_MODE_TCP, LW_FRTIP, NULL }, /* frontend port */ |
| 146 | { "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] | 147 | { "hr", LOG_FMT_HDRREQUEST, PR_MODE_TCP, LW_REQHDR, NULL }, /* header request */ |
| 148 | { "hrl", LOG_FMT_HDRREQUESTLIST, PR_MODE_TCP, LW_REQHDR, NULL }, /* header request list */ |
| 149 | { "hs", LOG_FMT_HDRRESPONS, PR_MODE_TCP, LW_RSPHDR, NULL }, /* header response */ |
| 150 | { "hsl", LOG_FMT_HDRRESPONSLIST, PR_MODE_TCP, LW_RSPHDR, NULL }, /* header response list */ |
Andrew Hayworth | 0ebc55f | 2015-04-27 21:37:03 +0000 | [diff] [blame] | 151 | { "HM", LOG_FMT_HTTP_METHOD, PR_MODE_HTTP, LW_REQ, NULL }, /* HTTP method */ |
| 152 | { "HP", LOG_FMT_HTTP_PATH, PR_MODE_HTTP, LW_REQ, NULL }, /* HTTP path */ |
Andrew Hayworth | e63ac87 | 2015-07-31 16:14:16 +0000 | [diff] [blame] | 153 | { "HQ", LOG_FMT_HTTP_QUERY, PR_MODE_HTTP, LW_REQ, NULL }, /* HTTP query */ |
Andrew Hayworth | 0ebc55f | 2015-04-27 21:37:03 +0000 | [diff] [blame] | 154 | { "HU", LOG_FMT_HTTP_URI, PR_MODE_HTTP, LW_REQ, NULL }, /* HTTP full URI */ |
| 155 | { "HV", LOG_FMT_HTTP_VERSION, PR_MODE_HTTP, LW_REQ, NULL }, /* HTTP version */ |
Willy Tarreau | 7346acb | 2014-08-28 15:03:15 +0200 | [diff] [blame] | 156 | { "lc", LOG_FMT_LOGCNT, PR_MODE_TCP, LW_INIT, NULL }, /* log counter */ |
Willy Tarreau | 2beef58 | 2012-12-20 17:22:52 +0100 | [diff] [blame] | 157 | { "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] | 158 | { "pid", LOG_FMT_PID, PR_MODE_TCP, LW_INIT, NULL }, /* log pid */ |
Willy Tarreau | 2beef58 | 2012-12-20 17:22:52 +0100 | [diff] [blame] | 159 | { "r", LOG_FMT_REQ, PR_MODE_HTTP, LW_REQ, NULL }, /* request */ |
| 160 | { "rc", LOG_FMT_RETRIES, PR_MODE_TCP, LW_BYTES, NULL }, /* retries */ |
Willy Tarreau | 1f0da24 | 2014-01-25 11:01:50 +0100 | [diff] [blame] | 161 | { "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] | 162 | { "s", LOG_FMT_SERVER, PR_MODE_TCP, LW_SVID, NULL }, /* server */ |
| 163 | { "sc", LOG_FMT_SRVCONN, PR_MODE_TCP, LW_BYTES, NULL }, /* srv_conn */ |
| 164 | { "si", LOG_FMT_SERVERIP, PR_MODE_TCP, LW_SVIP, NULL }, /* server destination ip */ |
| 165 | { "sp", LOG_FMT_SERVERPORT, PR_MODE_TCP, LW_SVIP, NULL }, /* server destination port */ |
| 166 | { "sq", LOG_FMT_SRVQUEUE, PR_MODE_TCP, LW_BYTES, NULL }, /* srv_queue */ |
Willy Tarreau | ffc3fcd | 2012-10-12 20:17:54 +0200 | [diff] [blame] | 167 | { "sslc", LOG_FMT_SSL_CIPHER, PR_MODE_TCP, LW_XPRT, NULL }, /* client-side SSL ciphers */ |
| 168 | { "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] | 169 | { "t", LOG_FMT_DATE, PR_MODE_TCP, LW_INIT, NULL }, /* date */ |
| 170 | { "ts", LOG_FMT_TERMSTATE, PR_MODE_TCP, LW_BYTES, NULL },/* termination state */ |
| 171 | { "tsc", LOG_FMT_TERMSTATE_CK, PR_MODE_TCP, LW_INIT, NULL },/* termination state */ |
| 172 | |
| 173 | /* The following tags are deprecated and will be removed soon */ |
| 174 | { "Bi", LOG_FMT_BACKENDIP, PR_MODE_TCP, LW_BCKIP, prepare_addrsource, "bi" }, /* backend source ip */ |
| 175 | { "Bp", LOG_FMT_BACKENDPORT, PR_MODE_TCP, LW_BCKIP, prepare_addrsource, "bp" }, /* backend source port */ |
| 176 | { "Ci", LOG_FMT_CLIENTIP, PR_MODE_TCP, LW_CLIP, NULL, "ci" }, /* client ip */ |
| 177 | { "Cp", LOG_FMT_CLIENTPORT, PR_MODE_TCP, LW_CLIP, NULL, "cp" }, /* client port */ |
| 178 | { "Fi", LOG_FMT_FRONTENDIP, PR_MODE_TCP, LW_FRTIP, NULL, "fi" }, /* frontend ip */ |
| 179 | { "Fp", LOG_FMT_FRONTENDPORT, PR_MODE_TCP, LW_FRTIP, NULL, "fp" }, /* frontend port */ |
| 180 | { "Si", LOG_FMT_SERVERIP, PR_MODE_TCP, LW_SVIP, NULL, "si" }, /* server destination ip */ |
| 181 | { "Sp", LOG_FMT_SERVERPORT, PR_MODE_TCP, LW_SVIP, NULL, "sp" }, /* server destination port */ |
| 182 | { "cc", LOG_FMT_CCLIENT, PR_MODE_HTTP, LW_REQHDR, NULL, "CC" }, /* client cookie */ |
| 183 | { "cs", LOG_FMT_CSERVER, PR_MODE_HTTP, LW_RSPHDR, NULL, "CS" }, /* server cookie */ |
| 184 | { "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] | 185 | { 0, 0, 0, 0, NULL } |
William Lallemand | 723b73a | 2012-02-08 16:37:49 +0100 | [diff] [blame] | 186 | }; |
| 187 | |
Willy Tarreau | 2beef58 | 2012-12-20 17:22:52 +0100 | [diff] [blame] | 188 | 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 |
| 189 | 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"; |
| 190 | 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] | 191 | char *log_format = NULL; |
| 192 | |
Dragan Dosen | 0b85ece | 2015-09-25 19:17:44 +0200 | [diff] [blame] | 193 | /* Default string used for structured-data part in RFC5424 formatted |
| 194 | * syslog messages. |
| 195 | */ |
| 196 | char default_rfc5424_sd_log_format[] = "- "; |
Dragan Dosen | 1322d09 | 2015-09-22 16:05:32 +0200 | [diff] [blame] | 197 | |
| 198 | /* This is a global syslog header, common to all outgoing messages in |
| 199 | * RFC3164 format. It begins with time-based part and is updated by |
| 200 | * update_log_hdr(). |
Dragan Dosen | 59cee97 | 2015-09-19 22:09:02 +0200 | [diff] [blame] | 201 | */ |
| 202 | char *logheader = NULL; |
| 203 | |
Dragan Dosen | 1322d09 | 2015-09-22 16:05:32 +0200 | [diff] [blame] | 204 | /* This is a global syslog header for messages in RFC5424 format. It is |
| 205 | * updated by update_log_hdr_rfc5424(). |
| 206 | */ |
| 207 | char *logheader_rfc5424 = NULL; |
| 208 | |
Dragan Dosen | 59cee97 | 2015-09-19 22:09:02 +0200 | [diff] [blame] | 209 | /* This is a global syslog message buffer, common to all outgoing |
| 210 | * messages. It contains only the data part. |
Willy Tarreau | b1a2faf | 2012-03-19 16:51:53 +0100 | [diff] [blame] | 211 | */ |
Willy Tarreau | 18324f5 | 2014-06-27 18:10:07 +0200 | [diff] [blame] | 212 | char *logline = NULL; |
Willy Tarreau | b1a2faf | 2012-03-19 16:51:53 +0100 | [diff] [blame] | 213 | |
Dragan Dosen | 0b85ece | 2015-09-25 19:17:44 +0200 | [diff] [blame] | 214 | /* A global syslog message buffer, common to all RFC5424 syslog messages. |
| 215 | * Currently, it is used for generating the structured-data part. |
| 216 | */ |
| 217 | char *logline_rfc5424 = NULL; |
| 218 | |
William Lallemand | 723b73a | 2012-02-08 16:37:49 +0100 | [diff] [blame] | 219 | struct logformat_var_args { |
| 220 | char *name; |
| 221 | int mask; |
| 222 | }; |
| 223 | |
| 224 | struct logformat_var_args var_args_list[] = { |
| 225 | // global |
| 226 | { "M", LOG_OPT_MANDATORY }, |
| 227 | { "Q", LOG_OPT_QUOTE }, |
William Lallemand | 5f23240 | 2012-04-05 18:02:55 +0200 | [diff] [blame] | 228 | { "X", LOG_OPT_HEXA }, |
Dragan Dosen | 835b921 | 2016-02-12 13:23:03 +0100 | [diff] [blame] | 229 | { "E", LOG_OPT_ESC }, |
William Lallemand | 723b73a | 2012-02-08 16:37:49 +0100 | [diff] [blame] | 230 | { 0, 0 } |
| 231 | }; |
| 232 | |
Willy Tarreau | b1f3af2 | 2013-04-12 18:30:32 +0200 | [diff] [blame] | 233 | /* return the name of the directive used in the current proxy for which we're |
| 234 | * currently parsing a header, when it is known. |
| 235 | */ |
| 236 | static inline const char *fmt_directive(const struct proxy *curproxy) |
| 237 | { |
Willy Tarreau | bf0addb | 2013-12-02 12:24:54 +0100 | [diff] [blame] | 238 | switch (curproxy->conf.args.ctx) { |
Willy Tarreau | 53e1a6d | 2015-07-09 11:20:00 +0200 | [diff] [blame] | 239 | case ARGC_ACL: |
| 240 | return "acl"; |
| 241 | case ARGC_STK: |
| 242 | return "stick"; |
| 243 | case ARGC_TRK: |
| 244 | return "track-sc"; |
| 245 | case ARGC_LOG: |
| 246 | return "log-format"; |
Dragan Dosen | 0b85ece | 2015-09-25 19:17:44 +0200 | [diff] [blame] | 247 | case ARGC_LOGSD: |
| 248 | return "log-format-sd"; |
Willy Tarreau | bf0addb | 2013-12-02 12:24:54 +0100 | [diff] [blame] | 249 | case ARGC_HRQ: |
Thierry FOURNIER | 1c0054f | 2013-11-20 15:09:52 +0100 | [diff] [blame] | 250 | return "http-request"; |
Willy Tarreau | bf0addb | 2013-12-02 12:24:54 +0100 | [diff] [blame] | 251 | case ARGC_HRS: |
Thierry FOURNIER | 1c0054f | 2013-11-20 15:09:52 +0100 | [diff] [blame] | 252 | return "http-response"; |
Willy Tarreau | 53e1a6d | 2015-07-09 11:20:00 +0200 | [diff] [blame] | 253 | case ARGC_UIF: |
| 254 | return "unique-id-format"; |
Thierry FOURNIER | d18cd0f | 2013-11-29 12:15:45 +0100 | [diff] [blame] | 255 | case ARGC_RDR: |
Willy Tarreau | 53e1a6d | 2015-07-09 11:20:00 +0200 | [diff] [blame] | 256 | return "redirect"; |
| 257 | case ARGC_CAP: |
| 258 | return "capture"; |
Willy Tarreau | 28d976d | 2015-07-09 11:39:33 +0200 | [diff] [blame] | 259 | case ARGC_SRV: |
| 260 | return "server"; |
Willy Tarreau | bf0addb | 2013-12-02 12:24:54 +0100 | [diff] [blame] | 261 | default: |
Willy Tarreau | 53e1a6d | 2015-07-09 11:20:00 +0200 | [diff] [blame] | 262 | return "undefined(please report this bug)"; /* must never happen */ |
Willy Tarreau | bf0addb | 2013-12-02 12:24:54 +0100 | [diff] [blame] | 263 | } |
Willy Tarreau | b1f3af2 | 2013-04-12 18:30:32 +0200 | [diff] [blame] | 264 | } |
| 265 | |
William Lallemand | 723b73a | 2012-02-08 16:37:49 +0100 | [diff] [blame] | 266 | /* |
William Lallemand | b7ff6a3 | 2012-03-02 14:35:21 +0100 | [diff] [blame] | 267 | * callback used to configure addr source retrieval |
| 268 | */ |
| 269 | int prepare_addrsource(struct logformat_node *node, struct proxy *curproxy) |
| 270 | { |
| 271 | curproxy->options2 |= PR_O2_SRC_ADDR; |
| 272 | |
| 273 | return 0; |
| 274 | } |
| 275 | |
| 276 | |
| 277 | /* |
William Lallemand | 723b73a | 2012-02-08 16:37:49 +0100 | [diff] [blame] | 278 | * Parse args in a logformat_var |
| 279 | */ |
| 280 | int parse_logformat_var_args(char *args, struct logformat_node *node) |
| 281 | { |
| 282 | int i = 0; |
| 283 | int end = 0; |
| 284 | int flags = 0; // 1 = + 2 = - |
| 285 | char *sp = NULL; // start pointer |
| 286 | |
| 287 | if (args == NULL) |
| 288 | return 1; |
| 289 | |
| 290 | while (1) { |
| 291 | if (*args == '\0') |
| 292 | end = 1; |
| 293 | |
| 294 | if (*args == '+') { |
| 295 | // add flag |
| 296 | sp = args + 1; |
| 297 | flags = 1; |
| 298 | } |
| 299 | if (*args == '-') { |
| 300 | // delete flag |
| 301 | sp = args + 1; |
| 302 | flags = 2; |
| 303 | } |
| 304 | |
| 305 | if (*args == '\0' || *args == ',') { |
| 306 | *args = '\0'; |
Willy Tarreau | 254d44c | 2012-12-20 18:19:26 +0100 | [diff] [blame] | 307 | for (i = 0; sp && var_args_list[i].name; i++) { |
William Lallemand | 723b73a | 2012-02-08 16:37:49 +0100 | [diff] [blame] | 308 | if (strcmp(sp, var_args_list[i].name) == 0) { |
| 309 | if (flags == 1) { |
| 310 | node->options |= var_args_list[i].mask; |
| 311 | break; |
| 312 | } else if (flags == 2) { |
| 313 | node->options &= ~var_args_list[i].mask; |
| 314 | break; |
| 315 | } |
| 316 | } |
| 317 | } |
| 318 | sp = NULL; |
| 319 | if (end) |
| 320 | break; |
| 321 | } |
Willy Tarreau | 254d44c | 2012-12-20 18:19:26 +0100 | [diff] [blame] | 322 | args++; |
William Lallemand | 723b73a | 2012-02-08 16:37:49 +0100 | [diff] [blame] | 323 | } |
| 324 | return 0; |
| 325 | } |
| 326 | |
| 327 | /* |
Willy Tarreau | 8a3f52f | 2012-12-20 21:23:42 +0100 | [diff] [blame] | 328 | * Parse a variable '%varname' or '%{args}varname' in log-format. The caller |
| 329 | * must pass the args part in the <arg> pointer with its length in <arg_len>, |
| 330 | * and varname with its length in <var> and <var_len> respectively. <arg> is |
| 331 | * 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] | 332 | */ |
Willy Tarreau | 8a3f52f | 2012-12-20 21:23:42 +0100 | [diff] [blame] | 333 | 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] | 334 | { |
Willy Tarreau | 8a3f52f | 2012-12-20 21:23:42 +0100 | [diff] [blame] | 335 | int j; |
| 336 | struct logformat_node *node; |
William Lallemand | 723b73a | 2012-02-08 16:37:49 +0100 | [diff] [blame] | 337 | |
Willy Tarreau | 8a3f52f | 2012-12-20 21:23:42 +0100 | [diff] [blame] | 338 | for (j = 0; logformat_keywords[j].name; j++) { // search a log type |
| 339 | if (strlen(logformat_keywords[j].name) == var_len && |
| 340 | strncmp(var, logformat_keywords[j].name, var_len) == 0) { |
| 341 | if (logformat_keywords[j].mode != PR_MODE_HTTP || curproxy->mode == PR_MODE_HTTP) { |
| 342 | node = calloc(1, sizeof(struct logformat_node)); |
| 343 | node->type = logformat_keywords[j].type; |
| 344 | node->options = *defoptions; |
| 345 | if (arg_len) { |
| 346 | node->arg = my_strndup(arg, arg_len); |
| 347 | parse_logformat_var_args(node->arg, node); |
| 348 | } |
| 349 | if (node->type == LOG_FMT_GLOBAL) { |
| 350 | *defoptions = node->options; |
| 351 | free(node->arg); |
| 352 | free(node); |
| 353 | } else { |
| 354 | if (logformat_keywords[j].config_callback && |
| 355 | logformat_keywords[j].config_callback(node, curproxy) != 0) { |
William Lallemand | bddd4fd | 2012-02-27 11:23:10 +0100 | [diff] [blame] | 356 | return -1; |
William Lallemand | 723b73a | 2012-02-08 16:37:49 +0100 | [diff] [blame] | 357 | } |
Willy Tarreau | 8a3f52f | 2012-12-20 21:23:42 +0100 | [diff] [blame] | 358 | curproxy->to_log |= logformat_keywords[j].lw; |
| 359 | LIST_ADDQ(list_format, &node->list); |
William Lallemand | 723b73a | 2012-02-08 16:37:49 +0100 | [diff] [blame] | 360 | } |
Willy Tarreau | 8a3f52f | 2012-12-20 21:23:42 +0100 | [diff] [blame] | 361 | if (logformat_keywords[j].replace_by) |
Willy Tarreau | 06d97f9 | 2013-12-02 17:45:48 +0100 | [diff] [blame] | 362 | 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] | 363 | curproxy->conf.args.file, curproxy->conf.args.line, |
| 364 | logformat_keywords[j].name, fmt_directive(curproxy), logformat_keywords[j].replace_by); |
Willy Tarreau | 8a3f52f | 2012-12-20 21:23:42 +0100 | [diff] [blame] | 365 | return 0; |
| 366 | } else { |
Willy Tarreau | 06d97f9 | 2013-12-02 17:45:48 +0100 | [diff] [blame] | 367 | 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] | 368 | curproxy->conf.args.file, curproxy->conf.args.line, fmt_directive(curproxy), |
| 369 | logformat_keywords[j].name); |
Willy Tarreau | 8a3f52f | 2012-12-20 21:23:42 +0100 | [diff] [blame] | 370 | return -1; |
William Lallemand | 723b73a | 2012-02-08 16:37:49 +0100 | [diff] [blame] | 371 | } |
William Lallemand | 723b73a | 2012-02-08 16:37:49 +0100 | [diff] [blame] | 372 | } |
| 373 | } |
Willy Tarreau | 8a3f52f | 2012-12-20 21:23:42 +0100 | [diff] [blame] | 374 | |
| 375 | j = var[var_len]; |
| 376 | var[var_len] = 0; |
Willy Tarreau | 06d97f9 | 2013-12-02 17:45:48 +0100 | [diff] [blame] | 377 | 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] | 378 | curproxy->conf.args.file, curproxy->conf.args.line, var, fmt_directive(curproxy)); |
Willy Tarreau | 8a3f52f | 2012-12-20 21:23:42 +0100 | [diff] [blame] | 379 | var[var_len] = j; |
William Lallemand | 723b73a | 2012-02-08 16:37:49 +0100 | [diff] [blame] | 380 | return -1; |
| 381 | } |
| 382 | |
| 383 | /* |
| 384 | * push to the logformat linked list |
| 385 | * |
| 386 | * start: start pointer |
| 387 | * end: end text pointer |
| 388 | * type: string type |
William Lallemand | 1d70556 | 2012-03-12 12:46:41 +0100 | [diff] [blame] | 389 | * list_format: destination list |
William Lallemand | 723b73a | 2012-02-08 16:37:49 +0100 | [diff] [blame] | 390 | * |
| 391 | * LOG_TEXT: copy chars from start to end excluding end. |
| 392 | * |
| 393 | */ |
William Lallemand | 1d70556 | 2012-03-12 12:46:41 +0100 | [diff] [blame] | 394 | 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] | 395 | { |
| 396 | char *str; |
| 397 | |
Willy Tarreau | a357166 | 2012-12-20 21:59:12 +0100 | [diff] [blame] | 398 | if (type == LF_TEXT) { /* type text */ |
William Lallemand | 723b73a | 2012-02-08 16:37:49 +0100 | [diff] [blame] | 399 | struct logformat_node *node = calloc(1, sizeof(struct logformat_node)); |
William Lallemand | 723b73a | 2012-02-08 16:37:49 +0100 | [diff] [blame] | 400 | str = calloc(end - start + 1, 1); |
| 401 | strncpy(str, start, end - start); |
William Lallemand | 723b73a | 2012-02-08 16:37:49 +0100 | [diff] [blame] | 402 | str[end - start] = '\0'; |
| 403 | node->arg = str; |
William Lallemand | 1d70556 | 2012-03-12 12:46:41 +0100 | [diff] [blame] | 404 | node->type = LOG_FMT_TEXT; // type string |
| 405 | LIST_ADDQ(list_format, &node->list); |
Willy Tarreau | a357166 | 2012-12-20 21:59:12 +0100 | [diff] [blame] | 406 | } else if (type == LF_SEPARATOR) { |
William Lallemand | 723b73a | 2012-02-08 16:37:49 +0100 | [diff] [blame] | 407 | struct logformat_node *node = calloc(1, sizeof(struct logformat_node)); |
William Lallemand | 1d70556 | 2012-03-12 12:46:41 +0100 | [diff] [blame] | 408 | node->type = LOG_FMT_SEPARATOR; |
| 409 | LIST_ADDQ(list_format, &node->list); |
William Lallemand | 723b73a | 2012-02-08 16:37:49 +0100 | [diff] [blame] | 410 | } |
| 411 | } |
| 412 | |
| 413 | /* |
Willy Tarreau | c836845 | 2012-12-21 00:09:23 +0100 | [diff] [blame] | 414 | * Parse the sample fetch expression <text> and add a node to <list_format> upon |
| 415 | * 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] | 416 | * 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] | 417 | */ |
Thierry FOURNIER | eeaa951 | 2014-02-11 14:00:19 +0100 | [diff] [blame] | 418 | 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] | 419 | { |
| 420 | char *cmd[2]; |
| 421 | struct sample_expr *expr; |
| 422 | struct logformat_node *node; |
| 423 | int cmd_arg; |
Willy Tarreau | 975c178 | 2013-12-12 23:16:54 +0100 | [diff] [blame] | 424 | char *errmsg = NULL; |
Willy Tarreau | c836845 | 2012-12-21 00:09:23 +0100 | [diff] [blame] | 425 | |
| 426 | cmd[0] = text; |
| 427 | cmd[1] = ""; |
| 428 | cmd_arg = 0; |
| 429 | |
Thierry FOURNIER | eeaa951 | 2014-02-11 14:00:19 +0100 | [diff] [blame] | 430 | 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] | 431 | if (!expr) { |
Willy Tarreau | b1f3af2 | 2013-04-12 18:30:32 +0200 | [diff] [blame] | 432 | Warning("parsing [%s:%d] : '%s' : sample fetch <%s> failed with : %s\n", |
| 433 | curpx->conf.args.file, curpx->conf.args.line, fmt_directive(curpx), |
Willy Tarreau | 975c178 | 2013-12-12 23:16:54 +0100 | [diff] [blame] | 434 | text, errmsg); |
Willy Tarreau | c836845 | 2012-12-21 00:09:23 +0100 | [diff] [blame] | 435 | return; |
| 436 | } |
| 437 | |
| 438 | node = calloc(1, sizeof(struct logformat_node)); |
| 439 | node->type = LOG_FMT_EXPR; |
| 440 | node->expr = expr; |
| 441 | node->options = options; |
| 442 | |
| 443 | if (arg_len) { |
| 444 | node->arg = my_strndup(arg, arg_len); |
| 445 | parse_logformat_var_args(node->arg, node); |
| 446 | } |
Willy Tarreau | 434c57c | 2013-01-08 01:10:24 +0100 | [diff] [blame] | 447 | if (expr->fetch->val & cap & SMP_VAL_REQUEST) |
Willy Tarreau | c836845 | 2012-12-21 00:09:23 +0100 | [diff] [blame] | 448 | node->options |= LOG_OPT_REQ_CAP; /* fetch method is request-compatible */ |
| 449 | |
Willy Tarreau | 434c57c | 2013-01-08 01:10:24 +0100 | [diff] [blame] | 450 | if (expr->fetch->val & cap & SMP_VAL_RESPONSE) |
Willy Tarreau | c836845 | 2012-12-21 00:09:23 +0100 | [diff] [blame] | 451 | node->options |= LOG_OPT_RES_CAP; /* fetch method is response-compatible */ |
| 452 | |
Willy Tarreau | 434c57c | 2013-01-08 01:10:24 +0100 | [diff] [blame] | 453 | if (!(expr->fetch->val & cap)) |
Willy Tarreau | b1f3af2 | 2013-04-12 18:30:32 +0200 | [diff] [blame] | 454 | Warning("parsing [%s:%d] : '%s' : sample fetch <%s> may not be reliably used here because it needs '%s' which is not available here.\n", |
| 455 | curpx->conf.args.file, curpx->conf.args.line, fmt_directive(curpx), |
| 456 | text, sample_src_names(expr->fetch->use)); |
Willy Tarreau | 434c57c | 2013-01-08 01:10:24 +0100 | [diff] [blame] | 457 | |
Willy Tarreau | c836845 | 2012-12-21 00:09:23 +0100 | [diff] [blame] | 458 | /* check if we need to allocate an hdr_idx struct for HTTP parsing */ |
| 459 | /* 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] | 460 | curpx->http_needed |= !!(expr->fetch->use & SMP_USE_HTTP_ANY); |
Willy Tarreau | c836845 | 2012-12-21 00:09:23 +0100 | [diff] [blame] | 461 | |
William Lallemand | 65ad6e1 | 2014-01-31 15:08:02 +0100 | [diff] [blame] | 462 | /* FIXME: temporary workaround for missing LW_XPRT and LW_REQ flags |
| 463 | * needed with some sample fetches (eg: ssl*). We always set it for |
| 464 | * now on, but this will leave with sample capabilities soon. |
Willy Tarreau | 1f31c73 | 2013-01-10 16:22:27 +0100 | [diff] [blame] | 465 | */ |
| 466 | curpx->to_log |= LW_XPRT; |
William Lallemand | 65ad6e1 | 2014-01-31 15:08:02 +0100 | [diff] [blame] | 467 | curpx->to_log |= LW_REQ; |
Willy Tarreau | c836845 | 2012-12-21 00:09:23 +0100 | [diff] [blame] | 468 | LIST_ADDQ(list_format, &node->list); |
| 469 | } |
| 470 | |
| 471 | /* |
William Lallemand | 723b73a | 2012-02-08 16:37:49 +0100 | [diff] [blame] | 472 | * Parse the log_format string and fill a linked list. |
| 473 | * 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] | 474 | * You can set arguments using { } : %{many arguments}varname. |
| 475 | * The curproxy->conf.args.ctx must be set by the caller. |
William Lallemand | 1d70556 | 2012-03-12 12:46:41 +0100 | [diff] [blame] | 476 | * |
| 477 | * str: the string to parse |
| 478 | * curproxy: the proxy affected |
| 479 | * list_format: the destination list |
Willy Tarreau | 6cbbdbf | 2013-02-05 18:52:25 +0100 | [diff] [blame] | 480 | * options: LOG_OPT_* to force on every node |
Willy Tarreau | 434c57c | 2013-01-08 01:10:24 +0100 | [diff] [blame] | 481 | * cap: all SMP_VAL_* flags supported by the consumer |
William Lallemand | 723b73a | 2012-02-08 16:37:49 +0100 | [diff] [blame] | 482 | */ |
Thierry FOURNIER | eeaa951 | 2014-02-11 14:00:19 +0100 | [diff] [blame] | 483 | 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] | 484 | { |
Willy Tarreau | b83bc1e | 2012-12-24 12:36:33 +0100 | [diff] [blame] | 485 | char *sp, *str, *backfmt; /* start pointer for text parts */ |
Willy Tarreau | 8a3f52f | 2012-12-20 21:23:42 +0100 | [diff] [blame] | 486 | char *arg = NULL; /* start pointer for args */ |
| 487 | char *var = NULL; /* start pointer for vars */ |
| 488 | int arg_len = 0; |
| 489 | int var_len = 0; |
| 490 | int cformat; /* current token format */ |
| 491 | int pformat; /* previous token format */ |
William Lallemand | 723b73a | 2012-02-08 16:37:49 +0100 | [diff] [blame] | 492 | struct logformat_node *tmplf, *back; |
| 493 | |
Willy Tarreau | b83bc1e | 2012-12-24 12:36:33 +0100 | [diff] [blame] | 494 | sp = str = backfmt = strdup(fmt); |
William Lallemand | 1dc00ef | 2012-08-09 16:41:35 +0200 | [diff] [blame] | 495 | curproxy->to_log |= LW_INIT; |
William Lallemand | 5e19a28 | 2012-04-02 16:22:10 +0200 | [diff] [blame] | 496 | |
William Lallemand | 723b73a | 2012-02-08 16:37:49 +0100 | [diff] [blame] | 497 | /* flush the list first. */ |
William Lallemand | 1d70556 | 2012-03-12 12:46:41 +0100 | [diff] [blame] | 498 | list_for_each_entry_safe(tmplf, back, list_format, list) { |
William Lallemand | 723b73a | 2012-02-08 16:37:49 +0100 | [diff] [blame] | 499 | LIST_DEL(&tmplf->list); |
| 500 | free(tmplf); |
| 501 | } |
| 502 | |
Willy Tarreau | 8a3f52f | 2012-12-20 21:23:42 +0100 | [diff] [blame] | 503 | for (cformat = LF_INIT; cformat != LF_END; str++) { |
William Lallemand | 723b73a | 2012-02-08 16:37:49 +0100 | [diff] [blame] | 504 | pformat = cformat; |
| 505 | |
Willy Tarreau | 8a3f52f | 2012-12-20 21:23:42 +0100 | [diff] [blame] | 506 | if (!*str) |
| 507 | cformat = LF_END; // preset it to save all states from doing this |
William Lallemand | 723b73a | 2012-02-08 16:37:49 +0100 | [diff] [blame] | 508 | |
Willy Tarreau | 8a3f52f | 2012-12-20 21:23:42 +0100 | [diff] [blame] | 509 | /* The prinicple of the two-step state machine below is to first detect a change, and |
| 510 | * second have all common paths processed at one place. The common paths are the ones |
| 511 | * encountered in text areas (LF_INIT, LF_TEXT, LF_SEPARATOR) and at the end (LF_END). |
| 512 | * We use the common LF_INIT state to dispatch to the different final states. |
| 513 | */ |
| 514 | switch (pformat) { |
| 515 | case LF_STARTVAR: // text immediately following a '%' |
Willy Tarreau | c836845 | 2012-12-21 00:09:23 +0100 | [diff] [blame] | 516 | arg = NULL; var = NULL; |
Willy Tarreau | 8a3f52f | 2012-12-20 21:23:42 +0100 | [diff] [blame] | 517 | arg_len = var_len = 0; |
| 518 | if (*str == '{') { // optional argument |
| 519 | cformat = LF_STARG; |
| 520 | arg = str + 1; |
William Lallemand | 723b73a | 2012-02-08 16:37:49 +0100 | [diff] [blame] | 521 | } |
Willy Tarreau | c836845 | 2012-12-21 00:09:23 +0100 | [diff] [blame] | 522 | else if (*str == '[') { |
| 523 | cformat = LF_STEXPR; |
| 524 | var = str + 1; // store expr in variable name |
| 525 | } |
Willy Tarreau | 0f28f82 | 2013-12-16 01:38:33 +0100 | [diff] [blame] | 526 | else if (isalpha((unsigned char)*str)) { // variable name |
William Lallemand | 723b73a | 2012-02-08 16:37:49 +0100 | [diff] [blame] | 527 | cformat = LF_VAR; |
Willy Tarreau | 8a3f52f | 2012-12-20 21:23:42 +0100 | [diff] [blame] | 528 | var = str; |
William Lallemand | 723b73a | 2012-02-08 16:37:49 +0100 | [diff] [blame] | 529 | } |
Willy Tarreau | 8a3f52f | 2012-12-20 21:23:42 +0100 | [diff] [blame] | 530 | else if (*str == '%') |
| 531 | cformat = LF_TEXT; // convert this character to a litteral (useful for '%') |
Willy Tarreau | 0f28f82 | 2013-12-16 01:38:33 +0100 | [diff] [blame] | 532 | else if (isdigit((unsigned char)*str) || *str == ' ' || *str == '\t') { |
Willy Tarreau | 06d97f9 | 2013-12-02 17:45:48 +0100 | [diff] [blame] | 533 | /* single '%' followed by blank or digit, send them both */ |
| 534 | cformat = LF_TEXT; |
| 535 | pformat = LF_TEXT; /* finally we include the previous char as well */ |
| 536 | sp = str - 1; /* send both the '%' and the current char */ |
| 537 | 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", |
| 538 | curproxy->conf.args.file, curproxy->conf.args.line, *str, (int)(str - backfmt), fmt_directive(curproxy), fmt); |
| 539 | |
| 540 | } |
Willy Tarreau | 8a3f52f | 2012-12-20 21:23:42 +0100 | [diff] [blame] | 541 | else |
| 542 | cformat = LF_INIT; // handle other cases of litterals |
| 543 | break; |
| 544 | |
| 545 | case LF_STARG: // text immediately following '%{' |
| 546 | if (*str == '}') { // end of arg |
William Lallemand | 723b73a | 2012-02-08 16:37:49 +0100 | [diff] [blame] | 547 | cformat = LF_EDARG; |
Willy Tarreau | 8a3f52f | 2012-12-20 21:23:42 +0100 | [diff] [blame] | 548 | arg_len = str - arg; |
| 549 | *str = 0; // used for reporting errors |
William Lallemand | 723b73a | 2012-02-08 16:37:49 +0100 | [diff] [blame] | 550 | } |
Willy Tarreau | 8a3f52f | 2012-12-20 21:23:42 +0100 | [diff] [blame] | 551 | break; |
| 552 | |
| 553 | case LF_EDARG: // text immediately following '%{arg}' |
Willy Tarreau | c836845 | 2012-12-21 00:09:23 +0100 | [diff] [blame] | 554 | if (*str == '[') { |
| 555 | cformat = LF_STEXPR; |
| 556 | var = str + 1; // store expr in variable name |
| 557 | break; |
| 558 | } |
Willy Tarreau | 0f28f82 | 2013-12-16 01:38:33 +0100 | [diff] [blame] | 559 | else if (isalnum((unsigned char)*str)) { // variable name |
William Lallemand | 723b73a | 2012-02-08 16:37:49 +0100 | [diff] [blame] | 560 | cformat = LF_VAR; |
Willy Tarreau | 8a3f52f | 2012-12-20 21:23:42 +0100 | [diff] [blame] | 561 | var = str; |
| 562 | break; |
| 563 | } |
Willy Tarreau | b1f3af2 | 2013-04-12 18:30:32 +0200 | [diff] [blame] | 564 | Warning("parsing [%s:%d] : Skipping isolated argument in '%s' line : '%%{%s}'\n", |
| 565 | curproxy->conf.args.file, curproxy->conf.args.line, fmt_directive(curproxy), arg); |
Willy Tarreau | 8a3f52f | 2012-12-20 21:23:42 +0100 | [diff] [blame] | 566 | cformat = LF_INIT; |
| 567 | break; |
| 568 | |
Willy Tarreau | c836845 | 2012-12-21 00:09:23 +0100 | [diff] [blame] | 569 | case LF_STEXPR: // text immediately following '%[' |
| 570 | if (*str == ']') { // end of arg |
| 571 | cformat = LF_EDEXPR; |
| 572 | var_len = str - var; |
| 573 | *str = 0; // needed for parsing the expression |
| 574 | } |
| 575 | break; |
| 576 | |
Willy Tarreau | 8a3f52f | 2012-12-20 21:23:42 +0100 | [diff] [blame] | 577 | case LF_VAR: // text part of a variable name |
| 578 | var_len = str - var; |
Willy Tarreau | 0f28f82 | 2013-12-16 01:38:33 +0100 | [diff] [blame] | 579 | if (!isalnum((unsigned char)*str)) |
Willy Tarreau | 8a3f52f | 2012-12-20 21:23:42 +0100 | [diff] [blame] | 580 | cformat = LF_INIT; // not variable name anymore |
| 581 | break; |
| 582 | |
Willy Tarreau | c836845 | 2012-12-21 00:09:23 +0100 | [diff] [blame] | 583 | default: // LF_INIT, LF_TEXT, LF_SEPARATOR, LF_END, LF_EDEXPR |
Willy Tarreau | 8a3f52f | 2012-12-20 21:23:42 +0100 | [diff] [blame] | 584 | cformat = LF_INIT; |
| 585 | } |
| 586 | |
| 587 | if (cformat == LF_INIT) { /* resynchronize state to text/sep/startvar */ |
| 588 | switch (*str) { |
| 589 | case '%': cformat = LF_STARTVAR; break; |
| 590 | case ' ': cformat = LF_SEPARATOR; break; |
| 591 | case 0 : cformat = LF_END; break; |
| 592 | default : cformat = LF_TEXT; break; |
William Lallemand | 723b73a | 2012-02-08 16:37:49 +0100 | [diff] [blame] | 593 | } |
| 594 | } |
| 595 | |
Willy Tarreau | 8a3f52f | 2012-12-20 21:23:42 +0100 | [diff] [blame] | 596 | if (cformat != pformat || pformat == LF_SEPARATOR) { |
| 597 | switch (pformat) { |
| 598 | case LF_VAR: |
| 599 | parse_logformat_var(arg, arg_len, var, var_len, curproxy, list_format, &options); |
| 600 | break; |
Willy Tarreau | c836845 | 2012-12-21 00:09:23 +0100 | [diff] [blame] | 601 | case LF_STEXPR: |
Thierry FOURNIER | eeaa951 | 2014-02-11 14:00:19 +0100 | [diff] [blame] | 602 | 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] | 603 | break; |
Willy Tarreau | 8a3f52f | 2012-12-20 21:23:42 +0100 | [diff] [blame] | 604 | case LF_TEXT: |
| 605 | case LF_SEPARATOR: |
| 606 | add_to_logformat_list(sp, str, pformat, list_format); |
| 607 | break; |
| 608 | } |
| 609 | 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] | 610 | } |
| 611 | } |
Willy Tarreau | 8a3f52f | 2012-12-20 21:23:42 +0100 | [diff] [blame] | 612 | |
Willy Tarreau | c836845 | 2012-12-21 00:09:23 +0100 | [diff] [blame] | 613 | if (pformat == LF_STARTVAR || pformat == LF_STARG || pformat == LF_STEXPR) |
Willy Tarreau | b1f3af2 | 2013-04-12 18:30:32 +0200 | [diff] [blame] | 614 | Warning("parsing [%s:%d] : Ignoring end of truncated '%s' line after '%s'\n", |
| 615 | curproxy->conf.args.file, curproxy->conf.args.line, fmt_directive(curproxy), |
| 616 | var ? var : arg ? arg : "%"); |
Willy Tarreau | 3ed22a4 | 2012-12-23 17:29:07 +0100 | [diff] [blame] | 617 | |
Willy Tarreau | b83bc1e | 2012-12-24 12:36:33 +0100 | [diff] [blame] | 618 | free(backfmt); |
William Lallemand | 723b73a | 2012-02-08 16:37:49 +0100 | [diff] [blame] | 619 | } |
| 620 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 621 | /* |
| 622 | * Displays the message on stderr with the date and pid. Overrides the quiet |
| 623 | * mode during startup. |
| 624 | */ |
Willy Tarreau | b17916e | 2006-10-15 15:17:57 +0200 | [diff] [blame] | 625 | void Alert(const char *fmt, ...) |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 626 | { |
| 627 | va_list argp; |
Willy Tarreau | fe94460 | 2007-10-25 10:34:16 +0200 | [diff] [blame] | 628 | struct tm tm; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 629 | |
| 630 | if (!(global.mode & MODE_QUIET) || (global.mode & (MODE_VERBOSE | MODE_STARTING))) { |
| 631 | va_start(argp, fmt); |
| 632 | |
Willy Tarreau | b7f694f | 2008-06-22 17:18:02 +0200 | [diff] [blame] | 633 | get_localtime(date.tv_sec, &tm); |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 634 | fprintf(stderr, "[ALERT] %03d/%02d%02d%02d (%d) : ", |
Willy Tarreau | fe94460 | 2007-10-25 10:34:16 +0200 | [diff] [blame] | 635 | 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] | 636 | vfprintf(stderr, fmt, argp); |
| 637 | fflush(stderr); |
| 638 | va_end(argp); |
| 639 | } |
| 640 | } |
| 641 | |
| 642 | |
| 643 | /* |
| 644 | * Displays the message on stderr with the date and pid. |
| 645 | */ |
Willy Tarreau | b17916e | 2006-10-15 15:17:57 +0200 | [diff] [blame] | 646 | void Warning(const char *fmt, ...) |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 647 | { |
| 648 | va_list argp; |
Willy Tarreau | fe94460 | 2007-10-25 10:34:16 +0200 | [diff] [blame] | 649 | struct tm tm; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 650 | |
| 651 | if (!(global.mode & MODE_QUIET) || (global.mode & MODE_VERBOSE)) { |
| 652 | va_start(argp, fmt); |
| 653 | |
Willy Tarreau | b7f694f | 2008-06-22 17:18:02 +0200 | [diff] [blame] | 654 | get_localtime(date.tv_sec, &tm); |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 655 | fprintf(stderr, "[WARNING] %03d/%02d%02d%02d (%d) : ", |
Willy Tarreau | fe94460 | 2007-10-25 10:34:16 +0200 | [diff] [blame] | 656 | 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] | 657 | vfprintf(stderr, fmt, argp); |
| 658 | fflush(stderr); |
| 659 | va_end(argp); |
| 660 | } |
| 661 | } |
| 662 | |
| 663 | /* |
| 664 | * Displays the message on <out> only if quiet mode is not set. |
| 665 | */ |
Willy Tarreau | b17916e | 2006-10-15 15:17:57 +0200 | [diff] [blame] | 666 | void qfprintf(FILE *out, const char *fmt, ...) |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 667 | { |
| 668 | va_list argp; |
| 669 | |
| 670 | if (!(global.mode & MODE_QUIET) || (global.mode & MODE_VERBOSE)) { |
| 671 | va_start(argp, fmt); |
| 672 | vfprintf(out, fmt, argp); |
| 673 | fflush(out); |
| 674 | va_end(argp); |
| 675 | } |
| 676 | } |
| 677 | |
| 678 | /* |
Dragan Dosen | 1322d09 | 2015-09-22 16:05:32 +0200 | [diff] [blame] | 679 | * returns log format for <fmt> or -1 if not found. |
| 680 | */ |
| 681 | int get_log_format(const char *fmt) |
| 682 | { |
| 683 | int format; |
| 684 | |
| 685 | format = LOG_FORMATS - 1; |
Dragan Dosen | 43885c7 | 2015-10-01 13:18:13 +0200 | [diff] [blame] | 686 | while (format >= 0 && strcmp(log_formats[format].name, fmt)) |
Dragan Dosen | 1322d09 | 2015-09-22 16:05:32 +0200 | [diff] [blame] | 687 | format--; |
| 688 | |
| 689 | return format; |
| 690 | } |
| 691 | |
| 692 | /* |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 693 | * returns log level for <lev> or -1 if not found. |
| 694 | */ |
| 695 | int get_log_level(const char *lev) |
| 696 | { |
| 697 | int level; |
| 698 | |
| 699 | level = NB_LOG_LEVELS - 1; |
| 700 | while (level >= 0 && strcmp(log_levels[level], lev)) |
| 701 | level--; |
| 702 | |
| 703 | return level; |
| 704 | } |
| 705 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 706 | /* |
| 707 | * returns log facility for <fac> or -1 if not found. |
| 708 | */ |
| 709 | int get_log_facility(const char *fac) |
| 710 | { |
| 711 | int facility; |
| 712 | |
| 713 | facility = NB_LOG_FACILITIES - 1; |
| 714 | while (facility >= 0 && strcmp(log_facilities[facility], fac)) |
| 715 | facility--; |
William Lallemand | 2a4a44f | 2012-02-06 16:00:33 +0100 | [diff] [blame] | 716 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 717 | return facility; |
| 718 | } |
| 719 | |
William Lallemand | a1cc381 | 2012-02-08 16:38:44 +0100 | [diff] [blame] | 720 | /* |
Dragan Dosen | 835b921 | 2016-02-12 13:23:03 +0100 | [diff] [blame] | 721 | * Encode the string. |
| 722 | * |
| 723 | * When using the +E log format option, it will try to escape '"\]' |
| 724 | * characters with '\' as prefix. The same prefix should not be used as |
| 725 | * <escape>. |
| 726 | */ |
| 727 | static char *lf_encode_string(char *start, char *stop, |
| 728 | const char escape, const fd_set *map, |
| 729 | const char *string, |
| 730 | struct logformat_node *node) |
| 731 | { |
| 732 | if (node->options & LOG_OPT_ESC) { |
| 733 | if (start < stop) { |
| 734 | stop--; /* reserve one byte for the final '\0' */ |
| 735 | while (start < stop && *string != '\0') { |
| 736 | if (!FD_ISSET((unsigned char)(*string), map)) { |
| 737 | if (!FD_ISSET((unsigned char)(*string), rfc5424_escape_map)) |
| 738 | *start++ = *string; |
| 739 | else { |
| 740 | if (start + 2 >= stop) |
| 741 | break; |
| 742 | *start++ = '\\'; |
| 743 | *start++ = *string; |
| 744 | } |
| 745 | } |
| 746 | else { |
| 747 | if (start + 3 >= stop) |
| 748 | break; |
| 749 | *start++ = escape; |
| 750 | *start++ = hextab[(*string >> 4) & 15]; |
| 751 | *start++ = hextab[*string & 15]; |
| 752 | } |
| 753 | string++; |
| 754 | } |
| 755 | *start = '\0'; |
| 756 | } |
| 757 | } |
| 758 | else { |
| 759 | return encode_string(start, stop, escape, map, string); |
| 760 | } |
| 761 | |
| 762 | return start; |
| 763 | } |
| 764 | |
| 765 | /* |
| 766 | * Encode the chunk. |
| 767 | * |
| 768 | * When using the +E log format option, it will try to escape '"\]' |
| 769 | * characters with '\' as prefix. The same prefix should not be used as |
| 770 | * <escape>. |
| 771 | */ |
| 772 | static char *lf_encode_chunk(char *start, char *stop, |
| 773 | const char escape, const fd_set *map, |
| 774 | const struct chunk *chunk, |
| 775 | struct logformat_node *node) |
| 776 | { |
| 777 | char *str, *end; |
| 778 | |
| 779 | if (node->options & LOG_OPT_ESC) { |
| 780 | if (start < stop) { |
| 781 | str = chunk->str; |
| 782 | end = chunk->str + chunk->len; |
| 783 | |
| 784 | stop--; /* reserve one byte for the final '\0' */ |
| 785 | while (start < stop && str < end) { |
| 786 | if (!FD_ISSET((unsigned char)(*str), map)) { |
| 787 | if (!FD_ISSET((unsigned char)(*str), rfc5424_escape_map)) |
| 788 | *start++ = *str; |
| 789 | else { |
| 790 | if (start + 2 >= stop) |
| 791 | break; |
| 792 | *start++ = '\\'; |
| 793 | *start++ = *str; |
| 794 | } |
| 795 | } |
| 796 | else { |
| 797 | if (start + 3 >= stop) |
| 798 | break; |
| 799 | *start++ = escape; |
| 800 | *start++ = hextab[(*str >> 4) & 15]; |
| 801 | *start++ = hextab[*str & 15]; |
| 802 | } |
| 803 | str++; |
| 804 | } |
| 805 | *start = '\0'; |
| 806 | } |
| 807 | } |
| 808 | else { |
| 809 | return encode_chunk(start, stop, escape, map, chunk); |
| 810 | } |
| 811 | |
| 812 | return start; |
| 813 | } |
| 814 | |
| 815 | /* |
William Lallemand | a1cc381 | 2012-02-08 16:38:44 +0100 | [diff] [blame] | 816 | * Write a string in the log string |
Dragan Dosen | 835b921 | 2016-02-12 13:23:03 +0100 | [diff] [blame] | 817 | * Take cares of quote and escape options |
William Lallemand | a1cc381 | 2012-02-08 16:38:44 +0100 | [diff] [blame] | 818 | * |
| 819 | * Return the adress of the \0 character, or NULL on error |
| 820 | */ |
Willy Tarreau | 2b0108a | 2012-12-21 19:23:44 +0100 | [diff] [blame] | 821 | 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] | 822 | { |
Willy Tarreau | 2b0108a | 2012-12-21 19:23:44 +0100 | [diff] [blame] | 823 | if (size < 2) |
| 824 | return NULL; |
William Lallemand | a1cc381 | 2012-02-08 16:38:44 +0100 | [diff] [blame] | 825 | |
Willy Tarreau | 2b0108a | 2012-12-21 19:23:44 +0100 | [diff] [blame] | 826 | if (node->options & LOG_OPT_QUOTE) { |
| 827 | *(dst++) = '"'; |
| 828 | size--; |
William Lallemand | bddd4fd | 2012-02-27 11:23:10 +0100 | [diff] [blame] | 829 | } |
Willy Tarreau | 2b0108a | 2012-12-21 19:23:44 +0100 | [diff] [blame] | 830 | |
Willy Tarreau | 6cbbdbf | 2013-02-05 18:52:25 +0100 | [diff] [blame] | 831 | if (src && len) { |
Dragan Dosen | 835b921 | 2016-02-12 13:23:03 +0100 | [diff] [blame] | 832 | if (node->options & LOG_OPT_ESC) { |
| 833 | struct chunk chunk; |
| 834 | char *ret; |
| 835 | |
| 836 | chunk_initlen(&chunk, (char *)src, 0, len); |
| 837 | ret = escape_chunk(dst, dst + size, '\\', rfc5424_escape_map, &chunk); |
| 838 | if (ret == NULL || *ret != '\0') |
| 839 | return NULL; |
| 840 | len = ret - dst; |
| 841 | } |
| 842 | else { |
| 843 | if (++len > size) |
| 844 | len = size; |
| 845 | len = strlcpy2(dst, src, len); |
| 846 | } |
Willy Tarreau | 2b0108a | 2012-12-21 19:23:44 +0100 | [diff] [blame] | 847 | |
| 848 | size -= len; |
| 849 | dst += len; |
| 850 | } |
Willy Tarreau | 6cbbdbf | 2013-02-05 18:52:25 +0100 | [diff] [blame] | 851 | else if ((node->options & (LOG_OPT_QUOTE|LOG_OPT_MANDATORY)) == LOG_OPT_MANDATORY) { |
| 852 | if (size < 2) |
| 853 | return NULL; |
| 854 | *(dst++) = '-'; |
| 855 | } |
Willy Tarreau | 2b0108a | 2012-12-21 19:23:44 +0100 | [diff] [blame] | 856 | |
| 857 | if (node->options & LOG_OPT_QUOTE) { |
| 858 | if (size < 2) |
| 859 | return NULL; |
| 860 | *(dst++) = '"'; |
| 861 | } |
| 862 | |
| 863 | *dst = '\0'; |
William Lallemand | bddd4fd | 2012-02-27 11:23:10 +0100 | [diff] [blame] | 864 | return dst; |
William Lallemand | a1cc381 | 2012-02-08 16:38:44 +0100 | [diff] [blame] | 865 | } |
| 866 | |
Willy Tarreau | 2b0108a | 2012-12-21 19:23:44 +0100 | [diff] [blame] | 867 | static inline char *lf_text(char *dst, const char *src, size_t size, struct logformat_node *node) |
| 868 | { |
| 869 | return lf_text_len(dst, src, size, size, node); |
| 870 | } |
| 871 | |
William Lallemand | 5f23240 | 2012-04-05 18:02:55 +0200 | [diff] [blame] | 872 | /* |
| 873 | * Write a IP adress to the log string |
| 874 | * +X option write in hexadecimal notation, most signifant byte on the left |
| 875 | */ |
| 876 | char *lf_ip(char *dst, struct sockaddr *sockaddr, size_t size, struct logformat_node *node) |
| 877 | { |
| 878 | char *ret = dst; |
| 879 | int iret; |
| 880 | char pn[INET6_ADDRSTRLEN]; |
| 881 | |
| 882 | if (node->options & LOG_OPT_HEXA) { |
| 883 | const unsigned char *addr = (const unsigned char *)&((struct sockaddr_in *)sockaddr)->sin_addr.s_addr; |
| 884 | iret = snprintf(dst, size, "%02X%02X%02X%02X", addr[0], addr[1], addr[2], addr[3]); |
| 885 | if (iret < 0 || iret > size) |
| 886 | return NULL; |
| 887 | ret += iret; |
| 888 | } else { |
| 889 | addr_to_str((struct sockaddr_storage *)sockaddr, pn, sizeof(pn)); |
| 890 | ret = lf_text(dst, pn, size, node); |
| 891 | if (ret == NULL) |
| 892 | return NULL; |
| 893 | } |
| 894 | return ret; |
| 895 | } |
| 896 | |
| 897 | /* |
| 898 | * Write a port to the log |
| 899 | * +X option write in hexadecimal notation, most signifant byte on the left |
| 900 | */ |
| 901 | char *lf_port(char *dst, struct sockaddr *sockaddr, size_t size, struct logformat_node *node) |
| 902 | { |
| 903 | char *ret = dst; |
| 904 | int iret; |
| 905 | |
| 906 | if (node->options & LOG_OPT_HEXA) { |
| 907 | const unsigned char *port = (const unsigned char *)&((struct sockaddr_in *)sockaddr)->sin_port; |
| 908 | iret = snprintf(dst, size, "%02X%02X", port[0], port[1]); |
| 909 | if (iret < 0 || iret > size) |
| 910 | return NULL; |
| 911 | ret += iret; |
| 912 | } else { |
| 913 | ret = ltoa_o(get_host_port((struct sockaddr_storage *)sockaddr), dst, size); |
| 914 | if (ret == NULL) |
| 915 | return NULL; |
| 916 | } |
| 917 | return ret; |
| 918 | } |
| 919 | |
Dragan Dosen | 1322d09 | 2015-09-22 16:05:32 +0200 | [diff] [blame] | 920 | /* Re-generate time-based part of the syslog header in RFC3164 format at |
| 921 | * the beginning of logheader once a second and return the pointer to the |
| 922 | * first character after it. |
Willy Tarreau | b1a2faf | 2012-03-19 16:51:53 +0100 | [diff] [blame] | 923 | */ |
Dragan Dosen | 0b85ece | 2015-09-25 19:17:44 +0200 | [diff] [blame] | 924 | static char *update_log_hdr(const time_t time) |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 925 | { |
Willy Tarreau | b1a2faf | 2012-03-19 16:51:53 +0100 | [diff] [blame] | 926 | static long tvsec; |
| 927 | static char *dataptr = NULL; /* backup of last end of header, NULL first time */ |
Dragan Dosen | 43885c7 | 2015-10-01 13:18:13 +0200 | [diff] [blame] | 928 | static struct chunk host = { NULL, 0, 0 }; |
| 929 | static int sep = 0; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 930 | |
Dragan Dosen | 0b85ece | 2015-09-25 19:17:44 +0200 | [diff] [blame] | 931 | if (unlikely(time != tvsec || dataptr == NULL)) { |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 932 | /* this string is rebuild only once a second */ |
Willy Tarreau | fe94460 | 2007-10-25 10:34:16 +0200 | [diff] [blame] | 933 | struct tm tm; |
Willy Tarreau | b1a2faf | 2012-03-19 16:51:53 +0100 | [diff] [blame] | 934 | int hdr_len; |
Willy Tarreau | fe94460 | 2007-10-25 10:34:16 +0200 | [diff] [blame] | 935 | |
Dragan Dosen | 0b85ece | 2015-09-25 19:17:44 +0200 | [diff] [blame] | 936 | tvsec = time; |
Willy Tarreau | fe94460 | 2007-10-25 10:34:16 +0200 | [diff] [blame] | 937 | get_localtime(tvsec, &tm); |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 938 | |
Dragan Dosen | 43885c7 | 2015-10-01 13:18:13 +0200 | [diff] [blame] | 939 | if (unlikely(global.log_send_hostname != host.str)) { |
| 940 | host.str = global.log_send_hostname; |
| 941 | host.len = host.str ? strlen(host.str) : 0; |
| 942 | sep = host.len ? 1 : 0; |
| 943 | } |
| 944 | |
Dragan Dosen | 59cee97 | 2015-09-19 22:09:02 +0200 | [diff] [blame] | 945 | hdr_len = snprintf(logheader, global.max_syslog_len, |
Dragan Dosen | 43885c7 | 2015-10-01 13:18:13 +0200 | [diff] [blame] | 946 | "<<<<>%s %2d %02d:%02d:%02d %.*s%*s", |
Willy Tarreau | fe94460 | 2007-10-25 10:34:16 +0200 | [diff] [blame] | 947 | monthname[tm.tm_mon], |
Dragan Dosen | 43885c7 | 2015-10-01 13:18:13 +0200 | [diff] [blame] | 948 | tm.tm_mday, tm.tm_hour, tm.tm_min, tm.tm_sec, |
| 949 | host.len, host.str, sep, ""); |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 950 | /* WARNING: depending upon implementations, snprintf may return |
| 951 | * either -1 or the number of bytes that would be needed to store |
| 952 | * the total message. In both cases, we must adjust it. |
| 953 | */ |
Willy Tarreau | 18324f5 | 2014-06-27 18:10:07 +0200 | [diff] [blame] | 954 | if (hdr_len < 0 || hdr_len > global.max_syslog_len) |
| 955 | hdr_len = global.max_syslog_len; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 956 | |
Dragan Dosen | 59cee97 | 2015-09-19 22:09:02 +0200 | [diff] [blame] | 957 | dataptr = logheader + hdr_len; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 958 | } |
| 959 | |
Willy Tarreau | 094af4e | 2015-01-07 15:03:42 +0100 | [diff] [blame] | 960 | dataptr[0] = 0; // ensure we get rid of any previous attempt |
| 961 | |
Dragan Dosen | 68d2e3a | 2015-09-19 22:35:44 +0200 | [diff] [blame] | 962 | return dataptr; |
William Lallemand | 2a4a44f | 2012-02-06 16:00:33 +0100 | [diff] [blame] | 963 | } |
| 964 | |
Dragan Dosen | 1322d09 | 2015-09-22 16:05:32 +0200 | [diff] [blame] | 965 | /* Re-generate time-based part of the syslog header in RFC5424 format at |
| 966 | * the beginning of logheader_rfc5424 once a second and return the pointer |
| 967 | * to the first character after it. |
| 968 | */ |
Dragan Dosen | 0b85ece | 2015-09-25 19:17:44 +0200 | [diff] [blame] | 969 | static char *update_log_hdr_rfc5424(const time_t time) |
Dragan Dosen | 1322d09 | 2015-09-22 16:05:32 +0200 | [diff] [blame] | 970 | { |
| 971 | static long tvsec; |
| 972 | static char *dataptr = NULL; /* backup of last end of header, NULL first time */ |
Benoit GARNIER | b413c2a | 2016-03-27 11:08:03 +0200 | [diff] [blame] | 973 | const char *gmt_offset; |
Dragan Dosen | 1322d09 | 2015-09-22 16:05:32 +0200 | [diff] [blame] | 974 | |
Dragan Dosen | 0b85ece | 2015-09-25 19:17:44 +0200 | [diff] [blame] | 975 | if (unlikely(time != tvsec || dataptr == NULL)) { |
Dragan Dosen | 1322d09 | 2015-09-22 16:05:32 +0200 | [diff] [blame] | 976 | /* this string is rebuild only once a second */ |
| 977 | struct tm tm; |
| 978 | int hdr_len; |
| 979 | |
Dragan Dosen | 0b85ece | 2015-09-25 19:17:44 +0200 | [diff] [blame] | 980 | tvsec = time; |
Dragan Dosen | 1322d09 | 2015-09-22 16:05:32 +0200 | [diff] [blame] | 981 | get_localtime(tvsec, &tm); |
Benoit GARNIER | e2e5bde | 2016-03-27 03:04:16 +0200 | [diff] [blame] | 982 | gmt_offset = get_gmt_offset(time, &tm); |
Dragan Dosen | 1322d09 | 2015-09-22 16:05:32 +0200 | [diff] [blame] | 983 | |
| 984 | hdr_len = snprintf(logheader_rfc5424, global.max_syslog_len, |
Dragan Dosen | 17def46 | 2015-10-09 21:31:43 +0200 | [diff] [blame] | 985 | "<<<<>1 %4d-%02d-%02dT%02d:%02d:%02d%.3s:%.2s %s ", |
Dragan Dosen | 1322d09 | 2015-09-22 16:05:32 +0200 | [diff] [blame] | 986 | tm.tm_year+1900, tm.tm_mon+1, tm.tm_mday, |
Dragan Dosen | 17def46 | 2015-10-09 21:31:43 +0200 | [diff] [blame] | 987 | tm.tm_hour, tm.tm_min, tm.tm_sec, |
Benoit GARNIER | b413c2a | 2016-03-27 11:08:03 +0200 | [diff] [blame] | 988 | gmt_offset, gmt_offset+3, |
Dragan Dosen | 43885c7 | 2015-10-01 13:18:13 +0200 | [diff] [blame] | 989 | global.log_send_hostname ? global.log_send_hostname : hostname); |
Dragan Dosen | 1322d09 | 2015-09-22 16:05:32 +0200 | [diff] [blame] | 990 | /* WARNING: depending upon implementations, snprintf may return |
| 991 | * either -1 or the number of bytes that would be needed to store |
| 992 | * the total message. In both cases, we must adjust it. |
| 993 | */ |
| 994 | if (hdr_len < 0 || hdr_len > global.max_syslog_len) |
| 995 | hdr_len = global.max_syslog_len; |
| 996 | |
| 997 | dataptr = logheader_rfc5424 + hdr_len; |
| 998 | } |
| 999 | |
| 1000 | dataptr[0] = 0; // ensure we get rid of any previous attempt |
| 1001 | |
| 1002 | return dataptr; |
| 1003 | } |
| 1004 | |
William Lallemand | 2a4a44f | 2012-02-06 16:00:33 +0100 | [diff] [blame] | 1005 | /* |
Dragan Dosen | 59cee97 | 2015-09-19 22:09:02 +0200 | [diff] [blame] | 1006 | * This function sends the syslog message using a printf format string. It |
| 1007 | * expects an LF-terminated message. |
William Lallemand | 2a4a44f | 2012-02-06 16:00:33 +0100 | [diff] [blame] | 1008 | */ |
| 1009 | void send_log(struct proxy *p, int level, const char *format, ...) |
| 1010 | { |
| 1011 | va_list argp; |
Willy Tarreau | b1a2faf | 2012-03-19 16:51:53 +0100 | [diff] [blame] | 1012 | int data_len; |
William Lallemand | 2a4a44f | 2012-02-06 16:00:33 +0100 | [diff] [blame] | 1013 | |
Willy Tarreau | 8c97ab5 | 2015-01-15 16:29:53 +0100 | [diff] [blame] | 1014 | if (level < 0 || format == NULL || logline == NULL) |
William Lallemand | 2a4a44f | 2012-02-06 16:00:33 +0100 | [diff] [blame] | 1015 | return; |
| 1016 | |
William Lallemand | 2a4a44f | 2012-02-06 16:00:33 +0100 | [diff] [blame] | 1017 | va_start(argp, format); |
Dragan Dosen | 59cee97 | 2015-09-19 22:09:02 +0200 | [diff] [blame] | 1018 | data_len = vsnprintf(logline, global.max_syslog_len, format, argp); |
Willy Tarreau | 18324f5 | 2014-06-27 18:10:07 +0200 | [diff] [blame] | 1019 | if (data_len < 0 || data_len > global.max_syslog_len) |
| 1020 | data_len = global.max_syslog_len; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1021 | va_end(argp); |
William Lallemand | 2a4a44f | 2012-02-06 16:00:33 +0100 | [diff] [blame] | 1022 | |
Dragan Dosen | 0b85ece | 2015-09-25 19:17:44 +0200 | [diff] [blame] | 1023 | __send_log(p, level, logline, data_len, default_rfc5424_sd_log_format, 2); |
William Lallemand | 2a4a44f | 2012-02-06 16:00:33 +0100 | [diff] [blame] | 1024 | } |
| 1025 | |
| 1026 | /* |
| 1027 | * This function sends a syslog message. |
| 1028 | * It doesn't care about errors nor does it report them. |
Dragan Dosen | 0b85ece | 2015-09-25 19:17:44 +0200 | [diff] [blame] | 1029 | * It overrides the last byte of the message vector with an LF character. |
| 1030 | * The arguments <sd> and <sd_size> are used for the structured-data part |
| 1031 | * in RFC5424 formatted syslog messages. |
William Lallemand | 2a4a44f | 2012-02-06 16:00:33 +0100 | [diff] [blame] | 1032 | */ |
Dragan Dosen | 0b85ece | 2015-09-25 19:17:44 +0200 | [diff] [blame] | 1033 | void __send_log(struct proxy *p, int level, char *message, size_t size, char *sd, size_t sd_size) |
William Lallemand | 2a4a44f | 2012-02-06 16:00:33 +0100 | [diff] [blame] | 1034 | { |
Dragan Dosen | 609ac2a | 2015-09-16 18:25:42 +0200 | [diff] [blame] | 1035 | static struct iovec iovec[NB_MSG_IOVEC_ELEMENTS] = { }; |
| 1036 | static struct msghdr msghdr = { |
| 1037 | .msg_iov = iovec, |
| 1038 | .msg_iovlen = NB_MSG_IOVEC_ELEMENTS |
| 1039 | }; |
William Lallemand | 2a4a44f | 2012-02-06 16:00:33 +0100 | [diff] [blame] | 1040 | static int logfdunix = -1; /* syslog to AF_UNIX socket */ |
| 1041 | static int logfdinet = -1; /* syslog to AF_INET socket */ |
| 1042 | static char *dataptr = NULL; |
| 1043 | int fac_level; |
| 1044 | struct list *logsrvs = NULL; |
| 1045 | struct logsrv *tmp = NULL; |
| 1046 | int nblogger; |
Dragan Dosen | 1322d09 | 2015-09-22 16:05:32 +0200 | [diff] [blame] | 1047 | char *hdr, *hdr_ptr; |
Dragan Dosen | 59cee97 | 2015-09-19 22:09:02 +0200 | [diff] [blame] | 1048 | size_t hdr_size; |
Dragan Dosen | 0b85ece | 2015-09-25 19:17:44 +0200 | [diff] [blame] | 1049 | time_t time = date.tv_sec; |
Dragan Dosen | 43885c7 | 2015-10-01 13:18:13 +0200 | [diff] [blame] | 1050 | struct chunk *tag = &global.log_tag; |
| 1051 | static int curr_pid; |
| 1052 | static char pidstr[100]; |
| 1053 | static struct chunk pid; |
William Lallemand | 2a4a44f | 2012-02-06 16:00:33 +0100 | [diff] [blame] | 1054 | |
| 1055 | dataptr = message; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1056 | |
| 1057 | if (p == NULL) { |
William Lallemand | 0f99e34 | 2011-10-12 17:50:54 +0200 | [diff] [blame] | 1058 | if (!LIST_ISEMPTY(&global.logsrvs)) { |
| 1059 | logsrvs = &global.logsrvs; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1060 | } |
| 1061 | } else { |
William Lallemand | 0f99e34 | 2011-10-12 17:50:54 +0200 | [diff] [blame] | 1062 | if (!LIST_ISEMPTY(&p->logsrvs)) { |
| 1063 | logsrvs = &p->logsrvs; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1064 | } |
Dragan Dosen | 43885c7 | 2015-10-01 13:18:13 +0200 | [diff] [blame] | 1065 | if (p->log_tag.str) { |
| 1066 | tag = &p->log_tag; |
| 1067 | } |
Robert Tsai | 81ae195 | 2007-12-05 10:47:29 +0100 | [diff] [blame] | 1068 | } |
| 1069 | |
William Lallemand | 0f99e34 | 2011-10-12 17:50:54 +0200 | [diff] [blame] | 1070 | if (!logsrvs) |
| 1071 | return; |
| 1072 | |
Dragan Dosen | 43885c7 | 2015-10-01 13:18:13 +0200 | [diff] [blame] | 1073 | if (unlikely(curr_pid != getpid())) { |
| 1074 | curr_pid = getpid(); |
| 1075 | ltoa_o(curr_pid, pidstr, sizeof(pidstr)); |
| 1076 | chunk_initstr(&pid, pidstr); |
| 1077 | } |
| 1078 | |
Robert Tsai | 81ae195 | 2007-12-05 10:47:29 +0100 | [diff] [blame] | 1079 | /* Send log messages to syslog server. */ |
William Lallemand | 0f99e34 | 2011-10-12 17:50:54 +0200 | [diff] [blame] | 1080 | nblogger = 0; |
| 1081 | list_for_each_entry(tmp, logsrvs, list) { |
| 1082 | const struct logsrv *logsrv = tmp; |
David du Colombier | 11bcb6c | 2011-03-24 12:23:00 +0100 | [diff] [blame] | 1083 | int *plogfd = logsrv->addr.ss_family == AF_UNIX ? |
Robert Tsai | 81ae195 | 2007-12-05 10:47:29 +0100 | [diff] [blame] | 1084 | &logfdunix : &logfdinet; |
Dragan Dosen | 43885c7 | 2015-10-01 13:18:13 +0200 | [diff] [blame] | 1085 | char *pid_sep1 = NULL, *pid_sep2 = NULL; |
Robert Tsai | 81ae195 | 2007-12-05 10:47:29 +0100 | [diff] [blame] | 1086 | int sent; |
Dragan Dosen | 68d2e3a | 2015-09-19 22:35:44 +0200 | [diff] [blame] | 1087 | int maxlen; |
Dragan Dosen | 59cee97 | 2015-09-19 22:09:02 +0200 | [diff] [blame] | 1088 | int hdr_max = 0; |
Dragan Dosen | 43885c7 | 2015-10-01 13:18:13 +0200 | [diff] [blame] | 1089 | int tag_max = 0; |
| 1090 | int pid_sep1_max = 0; |
| 1091 | int pid_max = 0; |
| 1092 | int pid_sep2_max = 0; |
Dragan Dosen | 0b85ece | 2015-09-25 19:17:44 +0200 | [diff] [blame] | 1093 | int sd_max = 0; |
Dragan Dosen | 5b78d9b | 2015-09-28 16:01:03 +0200 | [diff] [blame] | 1094 | int max = 0; |
Robert Tsai | 81ae195 | 2007-12-05 10:47:29 +0100 | [diff] [blame] | 1095 | |
Willy Tarreau | c7c7be2 | 2014-06-23 18:07:15 +0200 | [diff] [blame] | 1096 | nblogger++; |
| 1097 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1098 | /* 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] | 1099 | if (level > logsrv->level) |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1100 | continue; |
William Lallemand | bddd4fd | 2012-02-27 11:23:10 +0100 | [diff] [blame] | 1101 | |
Willy Tarreau | c7c7be2 | 2014-06-23 18:07:15 +0200 | [diff] [blame] | 1102 | if (unlikely(*plogfd < 0)) { |
| 1103 | /* socket not successfully initialized yet */ |
| 1104 | int proto = logsrv->addr.ss_family == AF_UNIX ? 0 : IPPROTO_UDP; |
| 1105 | |
| 1106 | if ((*plogfd = socket(logsrv->addr.ss_family, SOCK_DGRAM, proto)) < 0) { |
| 1107 | Alert("socket for logger #%d failed: %s (errno=%d)\n", |
| 1108 | nblogger, strerror(errno), errno); |
| 1109 | continue; |
| 1110 | } |
| 1111 | /* we don't want to receive anything on this socket */ |
| 1112 | setsockopt(*plogfd, SOL_SOCKET, SO_RCVBUF, &zero, sizeof(zero)); |
| 1113 | /* does nothing under Linux, maybe needed for others */ |
| 1114 | shutdown(*plogfd, SHUT_RD); |
| 1115 | } |
| 1116 | |
Dragan Dosen | 1322d09 | 2015-09-22 16:05:32 +0200 | [diff] [blame] | 1117 | switch (logsrv->format) { |
| 1118 | case LOG_FORMAT_RFC3164: |
| 1119 | hdr = logheader; |
Dragan Dosen | 0b85ece | 2015-09-25 19:17:44 +0200 | [diff] [blame] | 1120 | hdr_ptr = update_log_hdr(time); |
Dragan Dosen | 1322d09 | 2015-09-22 16:05:32 +0200 | [diff] [blame] | 1121 | break; |
| 1122 | |
| 1123 | case LOG_FORMAT_RFC5424: |
| 1124 | hdr = logheader_rfc5424; |
Dragan Dosen | 0b85ece | 2015-09-25 19:17:44 +0200 | [diff] [blame] | 1125 | hdr_ptr = update_log_hdr_rfc5424(time); |
Dragan Dosen | 0b85ece | 2015-09-25 19:17:44 +0200 | [diff] [blame] | 1126 | sd_max = sd_size; /* the SD part allowed only in RFC5424 */ |
Dragan Dosen | 1322d09 | 2015-09-22 16:05:32 +0200 | [diff] [blame] | 1127 | break; |
| 1128 | |
| 1129 | default: |
| 1130 | continue; /* must never happen */ |
| 1131 | } |
| 1132 | |
| 1133 | hdr_size = hdr_ptr - hdr; |
| 1134 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1135 | /* For each target, we may have a different facility. |
| 1136 | * We can also have a different log level for each message. |
| 1137 | * This induces variations in the message header length. |
| 1138 | * Since we don't want to recompute it each time, nor copy it every |
| 1139 | * time, we only change the facility in the pre-computed header, |
| 1140 | * and we change the pointer to the header accordingly. |
| 1141 | */ |
William Lallemand | 0f99e34 | 2011-10-12 17:50:54 +0200 | [diff] [blame] | 1142 | fac_level = (logsrv->facility << 3) + MAX(level, logsrv->minlvl); |
Dragan Dosen | 1322d09 | 2015-09-22 16:05:32 +0200 | [diff] [blame] | 1143 | hdr_ptr = hdr + 3; /* last digit of the log level */ |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1144 | do { |
Dragan Dosen | 59cee97 | 2015-09-19 22:09:02 +0200 | [diff] [blame] | 1145 | *hdr_ptr = '0' + fac_level % 10; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1146 | fac_level /= 10; |
Dragan Dosen | 59cee97 | 2015-09-19 22:09:02 +0200 | [diff] [blame] | 1147 | hdr_ptr--; |
Dragan Dosen | 1322d09 | 2015-09-22 16:05:32 +0200 | [diff] [blame] | 1148 | } while (fac_level && hdr_ptr > hdr); |
Dragan Dosen | 59cee97 | 2015-09-19 22:09:02 +0200 | [diff] [blame] | 1149 | *hdr_ptr = '<'; |
William Lallemand | 2a4a44f | 2012-02-06 16:00:33 +0100 | [diff] [blame] | 1150 | |
Dragan Dosen | 1322d09 | 2015-09-22 16:05:32 +0200 | [diff] [blame] | 1151 | hdr_max = hdr_size - (hdr_ptr - hdr); |
Dragan Dosen | 59cee97 | 2015-09-19 22:09:02 +0200 | [diff] [blame] | 1152 | |
Dragan Dosen | 43885c7 | 2015-10-01 13:18:13 +0200 | [diff] [blame] | 1153 | /* time-based header */ |
Dragan Dosen | 59cee97 | 2015-09-19 22:09:02 +0200 | [diff] [blame] | 1154 | if (unlikely(hdr_size >= logsrv->maxlen)) { |
| 1155 | hdr_max = MIN(hdr_max, logsrv->maxlen) - 1; |
Dragan Dosen | 0b85ece | 2015-09-25 19:17:44 +0200 | [diff] [blame] | 1156 | sd_max = 0; |
Dragan Dosen | 59cee97 | 2015-09-19 22:09:02 +0200 | [diff] [blame] | 1157 | goto send; |
| 1158 | } |
| 1159 | |
Dragan Dosen | 68d2e3a | 2015-09-19 22:35:44 +0200 | [diff] [blame] | 1160 | maxlen = logsrv->maxlen - hdr_max; |
Dragan Dosen | 68d2e3a | 2015-09-19 22:35:44 +0200 | [diff] [blame] | 1161 | |
Dragan Dosen | 43885c7 | 2015-10-01 13:18:13 +0200 | [diff] [blame] | 1162 | /* tag */ |
| 1163 | tag_max = tag->len; |
| 1164 | if (unlikely(tag_max >= maxlen)) { |
| 1165 | tag_max = maxlen - 1; |
| 1166 | sd_max = 0; |
| 1167 | goto send; |
| 1168 | } |
| 1169 | |
| 1170 | maxlen -= tag_max; |
| 1171 | |
| 1172 | /* first pid separator */ |
| 1173 | pid_sep1_max = log_formats[logsrv->format].pid.sep1.len; |
| 1174 | if (unlikely(pid_sep1_max >= maxlen)) { |
| 1175 | pid_sep1_max = maxlen - 1; |
Dragan Dosen | 0b85ece | 2015-09-25 19:17:44 +0200 | [diff] [blame] | 1176 | sd_max = 0; |
Dragan Dosen | 68d2e3a | 2015-09-19 22:35:44 +0200 | [diff] [blame] | 1177 | goto send; |
| 1178 | } |
| 1179 | |
Dragan Dosen | 43885c7 | 2015-10-01 13:18:13 +0200 | [diff] [blame] | 1180 | pid_sep1 = log_formats[logsrv->format].pid.sep1.str; |
| 1181 | maxlen -= pid_sep1_max; |
Dragan Dosen | 59cee97 | 2015-09-19 22:09:02 +0200 | [diff] [blame] | 1182 | |
Dragan Dosen | 43885c7 | 2015-10-01 13:18:13 +0200 | [diff] [blame] | 1183 | /* pid */ |
| 1184 | pid_max = pid.len; |
| 1185 | if (unlikely(pid_max >= maxlen)) { |
| 1186 | pid_max = maxlen - 1; |
| 1187 | sd_max = 0; |
| 1188 | goto send; |
| 1189 | } |
| 1190 | |
| 1191 | maxlen -= pid_max; |
| 1192 | |
| 1193 | /* second pid separator */ |
| 1194 | pid_sep2_max = log_formats[logsrv->format].pid.sep2.len; |
| 1195 | if (unlikely(pid_sep2_max >= maxlen)) { |
| 1196 | pid_sep2_max = maxlen - 1; |
| 1197 | sd_max = 0; |
| 1198 | goto send; |
| 1199 | } |
| 1200 | |
| 1201 | pid_sep2 = log_formats[logsrv->format].pid.sep2.str; |
| 1202 | maxlen -= pid_sep2_max; |
| 1203 | |
| 1204 | /* structured-data */ |
Dragan Dosen | 0b85ece | 2015-09-25 19:17:44 +0200 | [diff] [blame] | 1205 | if (sd_max >= maxlen) { |
| 1206 | sd_max = maxlen - 1; |
| 1207 | goto send; |
| 1208 | } |
Dragan Dosen | 59cee97 | 2015-09-19 22:09:02 +0200 | [diff] [blame] | 1209 | |
Dragan Dosen | 5b78d9b | 2015-09-28 16:01:03 +0200 | [diff] [blame] | 1210 | max = MIN(size, maxlen - sd_max) - 1; |
Dragan Dosen | 59cee97 | 2015-09-19 22:09:02 +0200 | [diff] [blame] | 1211 | send: |
Dragan Dosen | 59cee97 | 2015-09-19 22:09:02 +0200 | [diff] [blame] | 1212 | iovec[0].iov_base = hdr_ptr; |
Dragan Dosen | 43885c7 | 2015-10-01 13:18:13 +0200 | [diff] [blame] | 1213 | iovec[0].iov_len = hdr_max; |
| 1214 | iovec[1].iov_base = tag->str; |
| 1215 | iovec[1].iov_len = tag_max; |
| 1216 | iovec[2].iov_base = pid_sep1; |
| 1217 | iovec[2].iov_len = pid_sep1_max; |
| 1218 | iovec[3].iov_base = pid.str; |
| 1219 | iovec[3].iov_len = pid_max; |
| 1220 | iovec[4].iov_base = pid_sep2; |
| 1221 | iovec[4].iov_len = pid_sep2_max; |
| 1222 | iovec[5].iov_base = sd; |
| 1223 | iovec[5].iov_len = sd_max; |
| 1224 | iovec[6].iov_base = dataptr; |
| 1225 | iovec[6].iov_len = max; |
| 1226 | iovec[7].iov_base = "\n"; /* insert a \n at the end of the message */ |
| 1227 | iovec[7].iov_len = 1; |
Dragan Dosen | 609ac2a | 2015-09-16 18:25:42 +0200 | [diff] [blame] | 1228 | |
| 1229 | msghdr.msg_name = (struct sockaddr *)&logsrv->addr; |
| 1230 | msghdr.msg_namelen = get_addr_len(&logsrv->addr); |
| 1231 | |
| 1232 | sent = sendmsg(*plogfd, &msghdr, MSG_DONTWAIT | MSG_NOSIGNAL); |
Willy Tarreau | 18324f5 | 2014-06-27 18:10:07 +0200 | [diff] [blame] | 1233 | |
Robert Tsai | 81ae195 | 2007-12-05 10:47:29 +0100 | [diff] [blame] | 1234 | if (sent < 0) { |
Dragan Dosen | 609ac2a | 2015-09-16 18:25:42 +0200 | [diff] [blame] | 1235 | Alert("sendmsg logger #%d failed: %s (errno=%d)\n", |
Robert Tsai | 81ae195 | 2007-12-05 10:47:29 +0100 | [diff] [blame] | 1236 | nblogger, strerror(errno), errno); |
| 1237 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1238 | } |
| 1239 | } |
| 1240 | |
William Lallemand | bddd4fd | 2012-02-27 11:23:10 +0100 | [diff] [blame] | 1241 | extern fd_set hdr_encode_map[]; |
| 1242 | extern fd_set url_encode_map[]; |
Thierry FOURNIER | d048d8b | 2014-03-13 16:46:18 +0100 | [diff] [blame] | 1243 | extern fd_set http_encode_map[]; |
William Lallemand | bddd4fd | 2012-02-27 11:23:10 +0100 | [diff] [blame] | 1244 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1245 | |
Willy Tarreau | c89ccb6 | 2012-04-05 21:18:22 +0200 | [diff] [blame] | 1246 | 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] | 1247 | const char sess_set_cookie[8] = "NPDIRU67"; /* No set-cookie, Set-cookie found and left unchanged (passive), |
| 1248 | Set-cookie Deleted, Set-Cookie Inserted, Set-cookie Rewritten, |
| 1249 | Set-cookie Updated, unknown, unknown */ |
| 1250 | |
William Lallemand | 1d70556 | 2012-03-12 12:46:41 +0100 | [diff] [blame] | 1251 | /* |
| 1252 | * try to write a character if there is enough space, or goto out |
| 1253 | */ |
William Lallemand | bddd4fd | 2012-02-27 11:23:10 +0100 | [diff] [blame] | 1254 | #define LOGCHAR(x) do { \ |
William Lallemand | 1d70556 | 2012-03-12 12:46:41 +0100 | [diff] [blame] | 1255 | if (tmplog < dst + maxsize - 1) { \ |
William Lallemand | bddd4fd | 2012-02-27 11:23:10 +0100 | [diff] [blame] | 1256 | *(tmplog++) = (x); \ |
| 1257 | } else { \ |
| 1258 | goto out; \ |
| 1259 | } \ |
| 1260 | } while(0) |
| 1261 | |
Dragan Dosen | 835b921 | 2016-02-12 13:23:03 +0100 | [diff] [blame] | 1262 | |
| 1263 | /* Initializes some log data. |
| 1264 | */ |
| 1265 | void init_log() |
| 1266 | { |
| 1267 | char *tmp; |
| 1268 | |
| 1269 | /* Initialize the escape map for the RFC5424 structured-data : '"\]' |
| 1270 | * inside PARAM-VALUE should be escaped with '\' as prefix. |
| 1271 | * See https://tools.ietf.org/html/rfc5424#section-6.3.3 for more |
| 1272 | * details. |
| 1273 | */ |
| 1274 | memset(rfc5424_escape_map, 0, sizeof(rfc5424_escape_map)); |
| 1275 | |
| 1276 | tmp = "\"\\]"; |
| 1277 | while (*tmp) { |
| 1278 | FD_SET(*tmp, rfc5424_escape_map); |
| 1279 | tmp++; |
| 1280 | } |
| 1281 | } |
William Lallemand | 1d70556 | 2012-03-12 12:46:41 +0100 | [diff] [blame] | 1282 | |
Willy Tarreau | df97447 | 2012-12-28 02:44:01 +0100 | [diff] [blame] | 1283 | /* Builds a log line in <dst> based on <list_format>, and stops before reaching |
| 1284 | * <maxsize> characters. Returns the size of the output string in characters, |
| 1285 | * not counting the trailing zero which is always added if the resulting size |
| 1286 | * is not zero. |
| 1287 | */ |
Willy Tarreau | 87b0966 | 2015-04-03 00:22:06 +0200 | [diff] [blame] | 1288 | int build_logline(struct stream *s, char *dst, size_t maxsize, struct list *list_format) |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1289 | { |
Willy Tarreau | fb0afa7 | 2015-04-03 14:46:27 +0200 | [diff] [blame] | 1290 | struct session *sess = strm_sess(s); |
Willy Tarreau | e36cbcb | 2015-04-03 15:40:56 +0200 | [diff] [blame] | 1291 | struct proxy *fe = sess->fe; |
Willy Tarreau | ddb358d | 2006-12-17 22:55:52 +0100 | [diff] [blame] | 1292 | struct proxy *be = s->be; |
Willy Tarreau | eee5b51 | 2015-04-03 23:46:31 +0200 | [diff] [blame] | 1293 | struct http_txn *txn = s->txn; |
Andrew Hayworth | 0ebc55f | 2015-04-27 21:37:03 +0000 | [diff] [blame] | 1294 | struct chunk chunk; |
William Lallemand | bddd4fd | 2012-02-27 11:23:10 +0100 | [diff] [blame] | 1295 | char *uri; |
Andrew Hayworth | 0ebc55f | 2015-04-27 21:37:03 +0000 | [diff] [blame] | 1296 | char *spc; |
Andrew Hayworth | e63ac87 | 2015-07-31 16:14:16 +0000 | [diff] [blame] | 1297 | char *qmark; |
Andrew Hayworth | 0ebc55f | 2015-04-27 21:37:03 +0000 | [diff] [blame] | 1298 | char *end; |
Willy Tarreau | fe94460 | 2007-10-25 10:34:16 +0200 | [diff] [blame] | 1299 | struct tm tm; |
William Lallemand | bddd4fd | 2012-02-27 11:23:10 +0100 | [diff] [blame] | 1300 | int t_request; |
| 1301 | int hdr; |
| 1302 | int last_isspace = 1; |
Andrew Hayworth | 0ebc55f | 2015-04-27 21:37:03 +0000 | [diff] [blame] | 1303 | int nspaces = 0; |
Willy Tarreau | b1a2faf | 2012-03-19 16:51:53 +0100 | [diff] [blame] | 1304 | char *tmplog; |
William Lallemand | 1d70556 | 2012-03-12 12:46:41 +0100 | [diff] [blame] | 1305 | char *ret; |
| 1306 | int iret; |
William Lallemand | bddd4fd | 2012-02-27 11:23:10 +0100 | [diff] [blame] | 1307 | struct logformat_node *tmp; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1308 | |
William Lallemand | bddd4fd | 2012-02-27 11:23:10 +0100 | [diff] [blame] | 1309 | /* FIXME: let's limit ourselves to frontend logging for now. */ |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1310 | |
William Lallemand | bddd4fd | 2012-02-27 11:23:10 +0100 | [diff] [blame] | 1311 | t_request = -1; |
| 1312 | if (tv_isge(&s->logs.tv_request, &s->logs.tv_accept)) |
| 1313 | t_request = tv_ms_elapsed(&s->logs.tv_accept, &s->logs.tv_request); |
| 1314 | |
William Lallemand | 1d70556 | 2012-03-12 12:46:41 +0100 | [diff] [blame] | 1315 | tmplog = dst; |
Willy Tarreau | c9bd0cc | 2009-05-10 11:57:02 +0200 | [diff] [blame] | 1316 | |
William Lallemand | bddd4fd | 2012-02-27 11:23:10 +0100 | [diff] [blame] | 1317 | /* fill logbuffer */ |
William Lallemand | 1d70556 | 2012-03-12 12:46:41 +0100 | [diff] [blame] | 1318 | if (LIST_ISEMPTY(list_format)) |
| 1319 | return 0; |
William Lallemand | bddd4fd | 2012-02-27 11:23:10 +0100 | [diff] [blame] | 1320 | |
William Lallemand | 1d70556 | 2012-03-12 12:46:41 +0100 | [diff] [blame] | 1321 | list_for_each_entry(tmp, list_format, list) { |
Willy Tarreau | b363a1f | 2013-10-01 10:45:07 +0200 | [diff] [blame] | 1322 | struct connection *conn; |
Willy Tarreau | 4f65356 | 2012-10-12 19:48:16 +0200 | [diff] [blame] | 1323 | const char *src = NULL; |
Willy Tarreau | c836845 | 2012-12-21 00:09:23 +0100 | [diff] [blame] | 1324 | struct sample *key; |
Thierry FOURNIER | d048d8b | 2014-03-13 16:46:18 +0100 | [diff] [blame] | 1325 | const struct chunk empty = { NULL, 0, 0 }; |
William Lallemand | bddd4fd | 2012-02-27 11:23:10 +0100 | [diff] [blame] | 1326 | |
Willy Tarreau | c836845 | 2012-12-21 00:09:23 +0100 | [diff] [blame] | 1327 | switch (tmp->type) { |
William Lallemand | 1d70556 | 2012-03-12 12:46:41 +0100 | [diff] [blame] | 1328 | case LOG_FMT_SEPARATOR: |
William Lallemand | bddd4fd | 2012-02-27 11:23:10 +0100 | [diff] [blame] | 1329 | if (!last_isspace) { |
| 1330 | LOGCHAR(' '); |
| 1331 | last_isspace = 1; |
William Lallemand | bddd4fd | 2012-02-27 11:23:10 +0100 | [diff] [blame] | 1332 | } |
| 1333 | break; |
| 1334 | |
William Lallemand | 1d70556 | 2012-03-12 12:46:41 +0100 | [diff] [blame] | 1335 | case LOG_FMT_TEXT: // text |
William Lallemand | bddd4fd | 2012-02-27 11:23:10 +0100 | [diff] [blame] | 1336 | src = tmp->arg; |
William Lallemand | 5f23240 | 2012-04-05 18:02:55 +0200 | [diff] [blame] | 1337 | iret = strlcpy2(tmplog, src, dst + maxsize - tmplog); |
William Lallemand | 1d70556 | 2012-03-12 12:46:41 +0100 | [diff] [blame] | 1338 | if (iret == 0) |
William Lallemand | bddd4fd | 2012-02-27 11:23:10 +0100 | [diff] [blame] | 1339 | goto out; |
William Lallemand | 1d70556 | 2012-03-12 12:46:41 +0100 | [diff] [blame] | 1340 | tmplog += iret; |
William Lallemand | bddd4fd | 2012-02-27 11:23:10 +0100 | [diff] [blame] | 1341 | last_isspace = 0; |
| 1342 | break; |
| 1343 | |
Willy Tarreau | c836845 | 2012-12-21 00:09:23 +0100 | [diff] [blame] | 1344 | case LOG_FMT_EXPR: // sample expression, may be request or response |
| 1345 | key = NULL; |
| 1346 | if (tmp->options & LOG_OPT_REQ_CAP) |
Adis Nezirovic | 79beb24 | 2015-07-06 15:41:02 +0200 | [diff] [blame] | 1347 | key = sample_fetch_as_type(be, sess, s, SMP_OPT_DIR_REQ|SMP_OPT_FINAL, tmp->expr, SMP_T_STR); |
Willy Tarreau | c836845 | 2012-12-21 00:09:23 +0100 | [diff] [blame] | 1348 | if (!key && (tmp->options & LOG_OPT_RES_CAP)) |
Adis Nezirovic | 79beb24 | 2015-07-06 15:41:02 +0200 | [diff] [blame] | 1349 | key = sample_fetch_as_type(be, sess, s, SMP_OPT_DIR_RES|SMP_OPT_FINAL, tmp->expr, SMP_T_STR); |
Thierry FOURNIER | d048d8b | 2014-03-13 16:46:18 +0100 | [diff] [blame] | 1350 | if (tmp->options & LOG_OPT_HTTP) |
Dragan Dosen | 835b921 | 2016-02-12 13:23:03 +0100 | [diff] [blame] | 1351 | ret = lf_encode_chunk(tmplog, dst + maxsize, |
| 1352 | '%', http_encode_map, key ? &key->data.u.str : &empty, tmp); |
Thierry FOURNIER | d048d8b | 2014-03-13 16:46:18 +0100 | [diff] [blame] | 1353 | else |
Thierry FOURNIER | 136f9d3 | 2015-08-19 09:07:19 +0200 | [diff] [blame] | 1354 | ret = lf_text_len(tmplog, key ? key->data.u.str.str : NULL, key ? key->data.u.str.len : 0, dst + maxsize - tmplog, tmp); |
Willy Tarreau | c836845 | 2012-12-21 00:09:23 +0100 | [diff] [blame] | 1355 | if (ret == 0) |
| 1356 | goto out; |
| 1357 | tmplog = ret; |
| 1358 | last_isspace = 0; |
| 1359 | break; |
| 1360 | |
Willy Tarreau | 2beef58 | 2012-12-20 17:22:52 +0100 | [diff] [blame] | 1361 | case LOG_FMT_CLIENTIP: // %ci |
Willy Tarreau | 9ad7bd4 | 2015-04-03 19:19:59 +0200 | [diff] [blame] | 1362 | conn = objt_conn(sess->origin); |
Willy Tarreau | b363a1f | 2013-10-01 10:45:07 +0200 | [diff] [blame] | 1363 | if (conn) |
| 1364 | ret = lf_ip(tmplog, (struct sockaddr *)&conn->addr.from, dst + maxsize - tmplog, tmp); |
| 1365 | else |
| 1366 | ret = lf_text_len(tmplog, NULL, 0, dst + maxsize - tmplog, tmp); |
William Lallemand | 1d70556 | 2012-03-12 12:46:41 +0100 | [diff] [blame] | 1367 | if (ret == NULL) |
William Lallemand | bddd4fd | 2012-02-27 11:23:10 +0100 | [diff] [blame] | 1368 | goto out; |
William Lallemand | 1d70556 | 2012-03-12 12:46:41 +0100 | [diff] [blame] | 1369 | tmplog = ret; |
William Lallemand | bddd4fd | 2012-02-27 11:23:10 +0100 | [diff] [blame] | 1370 | last_isspace = 0; |
| 1371 | break; |
| 1372 | |
Willy Tarreau | 2beef58 | 2012-12-20 17:22:52 +0100 | [diff] [blame] | 1373 | case LOG_FMT_CLIENTPORT: // %cp |
Willy Tarreau | 9ad7bd4 | 2015-04-03 19:19:59 +0200 | [diff] [blame] | 1374 | conn = objt_conn(sess->origin); |
Willy Tarreau | b363a1f | 2013-10-01 10:45:07 +0200 | [diff] [blame] | 1375 | if (conn) { |
| 1376 | if (conn->addr.from.ss_family == AF_UNIX) { |
Willy Tarreau | fb0afa7 | 2015-04-03 14:46:27 +0200 | [diff] [blame] | 1377 | ret = ltoa_o(sess->listener->luid, tmplog, dst + maxsize - tmplog); |
Willy Tarreau | b363a1f | 2013-10-01 10:45:07 +0200 | [diff] [blame] | 1378 | } else { |
| 1379 | ret = lf_port(tmplog, (struct sockaddr *)&conn->addr.from, |
| 1380 | dst + maxsize - tmplog, tmp); |
| 1381 | } |
William Lallemand | 5f23240 | 2012-04-05 18:02:55 +0200 | [diff] [blame] | 1382 | } |
Willy Tarreau | b363a1f | 2013-10-01 10:45:07 +0200 | [diff] [blame] | 1383 | else |
| 1384 | ret = lf_text_len(tmplog, NULL, 0, dst + maxsize - tmplog, tmp); |
| 1385 | |
William Lallemand | 5f23240 | 2012-04-05 18:02:55 +0200 | [diff] [blame] | 1386 | if (ret == NULL) |
| 1387 | goto out; |
| 1388 | tmplog = ret; |
| 1389 | last_isspace = 0; |
| 1390 | break; |
| 1391 | |
Willy Tarreau | 2beef58 | 2012-12-20 17:22:52 +0100 | [diff] [blame] | 1392 | case LOG_FMT_FRONTENDIP: // %fi |
Willy Tarreau | 9ad7bd4 | 2015-04-03 19:19:59 +0200 | [diff] [blame] | 1393 | conn = objt_conn(sess->origin); |
Willy Tarreau | b363a1f | 2013-10-01 10:45:07 +0200 | [diff] [blame] | 1394 | if (conn) { |
| 1395 | conn_get_to_addr(conn); |
| 1396 | ret = lf_ip(tmplog, (struct sockaddr *)&conn->addr.to, dst + maxsize - tmplog, tmp); |
| 1397 | } |
| 1398 | else |
| 1399 | ret = lf_text_len(tmplog, NULL, 0, dst + maxsize - tmplog, tmp); |
| 1400 | |
William Lallemand | 1d70556 | 2012-03-12 12:46:41 +0100 | [diff] [blame] | 1401 | if (ret == NULL) |
William Lallemand | bddd4fd | 2012-02-27 11:23:10 +0100 | [diff] [blame] | 1402 | goto out; |
William Lallemand | 1d70556 | 2012-03-12 12:46:41 +0100 | [diff] [blame] | 1403 | tmplog = ret; |
William Lallemand | bddd4fd | 2012-02-27 11:23:10 +0100 | [diff] [blame] | 1404 | last_isspace = 0; |
| 1405 | break; |
| 1406 | |
Willy Tarreau | 2beef58 | 2012-12-20 17:22:52 +0100 | [diff] [blame] | 1407 | case LOG_FMT_FRONTENDPORT: // %fp |
Willy Tarreau | 9ad7bd4 | 2015-04-03 19:19:59 +0200 | [diff] [blame] | 1408 | conn = objt_conn(sess->origin); |
Willy Tarreau | b363a1f | 2013-10-01 10:45:07 +0200 | [diff] [blame] | 1409 | if (conn) { |
| 1410 | conn_get_to_addr(conn); |
| 1411 | if (conn->addr.to.ss_family == AF_UNIX) |
Willy Tarreau | fb0afa7 | 2015-04-03 14:46:27 +0200 | [diff] [blame] | 1412 | ret = ltoa_o(sess->listener->luid, tmplog, dst + maxsize - tmplog); |
Willy Tarreau | b363a1f | 2013-10-01 10:45:07 +0200 | [diff] [blame] | 1413 | else |
| 1414 | 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] | 1415 | } |
Willy Tarreau | b363a1f | 2013-10-01 10:45:07 +0200 | [diff] [blame] | 1416 | else |
| 1417 | ret = lf_text_len(tmplog, NULL, 0, dst + maxsize - tmplog, tmp); |
| 1418 | |
William Lallemand | 5f23240 | 2012-04-05 18:02:55 +0200 | [diff] [blame] | 1419 | if (ret == NULL) |
| 1420 | goto out; |
| 1421 | tmplog = ret; |
| 1422 | last_isspace = 0; |
| 1423 | break; |
| 1424 | |
Willy Tarreau | 2beef58 | 2012-12-20 17:22:52 +0100 | [diff] [blame] | 1425 | case LOG_FMT_BACKENDIP: // %bi |
Willy Tarreau | 350f487 | 2014-11-28 14:42:25 +0100 | [diff] [blame] | 1426 | conn = objt_conn(s->si[1].end); |
Willy Tarreau | b363a1f | 2013-10-01 10:45:07 +0200 | [diff] [blame] | 1427 | if (conn) |
| 1428 | ret = lf_ip(tmplog, (struct sockaddr *)&conn->addr.from, dst + maxsize - tmplog, tmp); |
| 1429 | else |
| 1430 | ret = lf_text_len(tmplog, NULL, 0, dst + maxsize - tmplog, tmp); |
| 1431 | |
William Lallemand | 1d70556 | 2012-03-12 12:46:41 +0100 | [diff] [blame] | 1432 | if (ret == NULL) |
William Lallemand | b7ff6a3 | 2012-03-02 14:35:21 +0100 | [diff] [blame] | 1433 | goto out; |
William Lallemand | 1d70556 | 2012-03-12 12:46:41 +0100 | [diff] [blame] | 1434 | tmplog = ret; |
William Lallemand | b7ff6a3 | 2012-03-02 14:35:21 +0100 | [diff] [blame] | 1435 | last_isspace = 0; |
| 1436 | break; |
| 1437 | |
Willy Tarreau | 2beef58 | 2012-12-20 17:22:52 +0100 | [diff] [blame] | 1438 | case LOG_FMT_BACKENDPORT: // %bp |
Willy Tarreau | 350f487 | 2014-11-28 14:42:25 +0100 | [diff] [blame] | 1439 | conn = objt_conn(s->si[1].end); |
Willy Tarreau | b363a1f | 2013-10-01 10:45:07 +0200 | [diff] [blame] | 1440 | if (conn) |
| 1441 | ret = lf_port(tmplog, (struct sockaddr *)&conn->addr.from, dst + maxsize - tmplog, tmp); |
| 1442 | else |
| 1443 | ret = lf_text_len(tmplog, NULL, 0, dst + maxsize - tmplog, tmp); |
| 1444 | |
William Lallemand | 5f23240 | 2012-04-05 18:02:55 +0200 | [diff] [blame] | 1445 | if (ret == NULL) |
| 1446 | goto out; |
| 1447 | tmplog = ret; |
| 1448 | last_isspace = 0; |
| 1449 | break; |
| 1450 | |
Willy Tarreau | 2beef58 | 2012-12-20 17:22:52 +0100 | [diff] [blame] | 1451 | case LOG_FMT_SERVERIP: // %si |
Willy Tarreau | 350f487 | 2014-11-28 14:42:25 +0100 | [diff] [blame] | 1452 | conn = objt_conn(s->si[1].end); |
Willy Tarreau | b363a1f | 2013-10-01 10:45:07 +0200 | [diff] [blame] | 1453 | if (conn) |
| 1454 | ret = lf_ip(tmplog, (struct sockaddr *)&conn->addr.to, dst + maxsize - tmplog, tmp); |
| 1455 | else |
| 1456 | ret = lf_text_len(tmplog, NULL, 0, dst + maxsize - tmplog, tmp); |
| 1457 | |
William Lallemand | 5f23240 | 2012-04-05 18:02:55 +0200 | [diff] [blame] | 1458 | if (ret == NULL) |
| 1459 | goto out; |
| 1460 | tmplog = ret; |
| 1461 | last_isspace = 0; |
| 1462 | break; |
| 1463 | |
Willy Tarreau | 2beef58 | 2012-12-20 17:22:52 +0100 | [diff] [blame] | 1464 | case LOG_FMT_SERVERPORT: // %sp |
Willy Tarreau | 350f487 | 2014-11-28 14:42:25 +0100 | [diff] [blame] | 1465 | conn = objt_conn(s->si[1].end); |
Willy Tarreau | b363a1f | 2013-10-01 10:45:07 +0200 | [diff] [blame] | 1466 | if (conn) |
| 1467 | ret = lf_port(tmplog, (struct sockaddr *)&conn->addr.to, dst + maxsize - tmplog, tmp); |
| 1468 | else |
| 1469 | ret = lf_text_len(tmplog, NULL, 0, dst + maxsize - tmplog, tmp); |
| 1470 | |
William Lallemand | 1d70556 | 2012-03-12 12:46:41 +0100 | [diff] [blame] | 1471 | if (ret == NULL) |
William Lallemand | b7ff6a3 | 2012-03-02 14:35:21 +0100 | [diff] [blame] | 1472 | goto out; |
William Lallemand | 1d70556 | 2012-03-12 12:46:41 +0100 | [diff] [blame] | 1473 | tmplog = ret; |
William Lallemand | b7ff6a3 | 2012-03-02 14:35:21 +0100 | [diff] [blame] | 1474 | last_isspace = 0; |
| 1475 | break; |
| 1476 | |
William Lallemand | 1d70556 | 2012-03-12 12:46:41 +0100 | [diff] [blame] | 1477 | case LOG_FMT_DATE: // %t |
William Lallemand | bddd4fd | 2012-02-27 11:23:10 +0100 | [diff] [blame] | 1478 | get_localtime(s->logs.accept_date.tv_sec, &tm); |
William Lallemand | 5f23240 | 2012-04-05 18:02:55 +0200 | [diff] [blame] | 1479 | ret = date2str_log(tmplog, &tm, &(s->logs.accept_date), |
| 1480 | dst + maxsize - tmplog); |
William Lallemand | 1d70556 | 2012-03-12 12:46:41 +0100 | [diff] [blame] | 1481 | if (ret == NULL) |
William Lallemand | bddd4fd | 2012-02-27 11:23:10 +0100 | [diff] [blame] | 1482 | goto out; |
William Lallemand | 1d70556 | 2012-03-12 12:46:41 +0100 | [diff] [blame] | 1483 | tmplog = ret; |
William Lallemand | bddd4fd | 2012-02-27 11:23:10 +0100 | [diff] [blame] | 1484 | last_isspace = 0; |
| 1485 | break; |
| 1486 | |
William Lallemand | 1d70556 | 2012-03-12 12:46:41 +0100 | [diff] [blame] | 1487 | case LOG_FMT_DATEGMT: // %T |
William Lallemand | bddd4fd | 2012-02-27 11:23:10 +0100 | [diff] [blame] | 1488 | get_gmtime(s->logs.accept_date.tv_sec, &tm); |
William Lallemand | 5f23240 | 2012-04-05 18:02:55 +0200 | [diff] [blame] | 1489 | ret = gmt2str_log(tmplog, &tm, dst + maxsize - tmplog); |
William Lallemand | 1d70556 | 2012-03-12 12:46:41 +0100 | [diff] [blame] | 1490 | if (ret == NULL) |
William Lallemand | bddd4fd | 2012-02-27 11:23:10 +0100 | [diff] [blame] | 1491 | goto out; |
William Lallemand | 1d70556 | 2012-03-12 12:46:41 +0100 | [diff] [blame] | 1492 | tmplog = ret; |
William Lallemand | bddd4fd | 2012-02-27 11:23:10 +0100 | [diff] [blame] | 1493 | last_isspace = 0; |
| 1494 | break; |
| 1495 | |
Yuxans Yao | 4e25b01 | 2012-10-19 10:36:09 +0800 | [diff] [blame] | 1496 | case LOG_FMT_DATELOCAL: // %Tl |
| 1497 | get_localtime(s->logs.accept_date.tv_sec, &tm); |
Benoit GARNIER | e2e5bde | 2016-03-27 03:04:16 +0200 | [diff] [blame] | 1498 | ret = localdate2str_log(tmplog, s->logs.accept_date.tv_sec, &tm, dst + maxsize - tmplog); |
Yuxans Yao | 4e25b01 | 2012-10-19 10:36:09 +0800 | [diff] [blame] | 1499 | if (ret == NULL) |
| 1500 | goto out; |
| 1501 | tmplog = ret; |
| 1502 | last_isspace = 0; |
| 1503 | break; |
| 1504 | |
William Lallemand | 5f23240 | 2012-04-05 18:02:55 +0200 | [diff] [blame] | 1505 | case LOG_FMT_TS: // %Ts |
| 1506 | get_gmtime(s->logs.accept_date.tv_sec, &tm); |
| 1507 | if (tmp->options & LOG_OPT_HEXA) { |
| 1508 | iret = snprintf(tmplog, dst + maxsize - tmplog, "%04X", (unsigned int)s->logs.accept_date.tv_sec); |
| 1509 | if (iret < 0 || iret > dst + maxsize - tmplog) |
| 1510 | goto out; |
| 1511 | last_isspace = 0; |
| 1512 | tmplog += iret; |
| 1513 | } else { |
| 1514 | ret = ltoa_o(s->logs.accept_date.tv_sec, tmplog, dst + maxsize - tmplog); |
| 1515 | if (ret == NULL) |
| 1516 | goto out; |
| 1517 | tmplog = ret; |
| 1518 | last_isspace = 0; |
| 1519 | } |
| 1520 | break; |
| 1521 | |
William Lallemand | 1d70556 | 2012-03-12 12:46:41 +0100 | [diff] [blame] | 1522 | case LOG_FMT_MS: // %ms |
William Lallemand | 5f23240 | 2012-04-05 18:02:55 +0200 | [diff] [blame] | 1523 | if (tmp->options & LOG_OPT_HEXA) { |
| 1524 | iret = snprintf(tmplog, dst + maxsize - tmplog, "%02X",(unsigned int)s->logs.accept_date.tv_usec/1000); |
| 1525 | if (iret < 0 || iret > dst + maxsize - tmplog) |
| 1526 | goto out; |
| 1527 | last_isspace = 0; |
| 1528 | tmplog += iret; |
| 1529 | } else { |
| 1530 | if ((dst + maxsize - tmplog) < 4) |
William Lallemand | bddd4fd | 2012-02-27 11:23:10 +0100 | [diff] [blame] | 1531 | goto out; |
Willy Tarreau | 9e60cd8 | 2013-01-24 01:18:16 +0100 | [diff] [blame] | 1532 | ret = utoa_pad((unsigned int)s->logs.accept_date.tv_usec/1000, |
| 1533 | tmplog, 4); |
| 1534 | if (ret == NULL) |
William Lallemand | 51b5dca | 2012-03-26 17:52:55 +0200 | [diff] [blame] | 1535 | goto out; |
Willy Tarreau | 9e60cd8 | 2013-01-24 01:18:16 +0100 | [diff] [blame] | 1536 | tmplog = ret; |
William Lallemand | bddd4fd | 2012-02-27 11:23:10 +0100 | [diff] [blame] | 1537 | last_isspace = 0; |
William Lallemand | 5f23240 | 2012-04-05 18:02:55 +0200 | [diff] [blame] | 1538 | } |
| 1539 | break; |
William Lallemand | bddd4fd | 2012-02-27 11:23:10 +0100 | [diff] [blame] | 1540 | |
William Lallemand | 1d70556 | 2012-03-12 12:46:41 +0100 | [diff] [blame] | 1541 | case LOG_FMT_FRONTEND: // %f |
William Lallemand | bddd4fd | 2012-02-27 11:23:10 +0100 | [diff] [blame] | 1542 | src = fe->id; |
William Lallemand | 5f23240 | 2012-04-05 18:02:55 +0200 | [diff] [blame] | 1543 | ret = lf_text(tmplog, src, dst + maxsize - tmplog, tmp); |
William Lallemand | 1d70556 | 2012-03-12 12:46:41 +0100 | [diff] [blame] | 1544 | if (ret == NULL) |
William Lallemand | bddd4fd | 2012-02-27 11:23:10 +0100 | [diff] [blame] | 1545 | goto out; |
William Lallemand | 1d70556 | 2012-03-12 12:46:41 +0100 | [diff] [blame] | 1546 | tmplog = ret; |
William Lallemand | 51b5dca | 2012-03-26 17:52:55 +0200 | [diff] [blame] | 1547 | last_isspace = 0; |
William Lallemand | bddd4fd | 2012-02-27 11:23:10 +0100 | [diff] [blame] | 1548 | break; |
| 1549 | |
Willy Tarreau | 773d65f | 2012-10-12 14:56:11 +0200 | [diff] [blame] | 1550 | case LOG_FMT_FRONTEND_XPRT: // %ft |
| 1551 | src = fe->id; |
| 1552 | if (tmp->options & LOG_OPT_QUOTE) |
| 1553 | LOGCHAR('"'); |
| 1554 | iret = strlcpy2(tmplog, src, dst + maxsize - tmplog); |
| 1555 | if (iret == 0) |
| 1556 | goto out; |
| 1557 | tmplog += iret; |
| 1558 | #ifdef USE_OPENSSL |
Willy Tarreau | fb0afa7 | 2015-04-03 14:46:27 +0200 | [diff] [blame] | 1559 | if (sess->listener->xprt == &ssl_sock) |
Willy Tarreau | 773d65f | 2012-10-12 14:56:11 +0200 | [diff] [blame] | 1560 | LOGCHAR('~'); |
| 1561 | #endif |
| 1562 | if (tmp->options & LOG_OPT_QUOTE) |
| 1563 | LOGCHAR('"'); |
| 1564 | last_isspace = 0; |
| 1565 | break; |
Willy Tarreau | ffc3fcd | 2012-10-12 20:17:54 +0200 | [diff] [blame] | 1566 | #ifdef USE_OPENSSL |
| 1567 | case LOG_FMT_SSL_CIPHER: // %sslc |
| 1568 | src = NULL; |
Willy Tarreau | 9ad7bd4 | 2015-04-03 19:19:59 +0200 | [diff] [blame] | 1569 | conn = objt_conn(sess->origin); |
Willy Tarreau | b363a1f | 2013-10-01 10:45:07 +0200 | [diff] [blame] | 1570 | if (conn) { |
Willy Tarreau | fb0afa7 | 2015-04-03 14:46:27 +0200 | [diff] [blame] | 1571 | if (sess->listener->xprt == &ssl_sock) |
Willy Tarreau | b363a1f | 2013-10-01 10:45:07 +0200 | [diff] [blame] | 1572 | src = ssl_sock_get_cipher_name(conn); |
| 1573 | } |
Willy Tarreau | ffc3fcd | 2012-10-12 20:17:54 +0200 | [diff] [blame] | 1574 | ret = lf_text(tmplog, src, dst + maxsize - tmplog, tmp); |
| 1575 | if (ret == NULL) |
| 1576 | goto out; |
| 1577 | tmplog = ret; |
| 1578 | last_isspace = 0; |
| 1579 | break; |
Willy Tarreau | 773d65f | 2012-10-12 14:56:11 +0200 | [diff] [blame] | 1580 | |
Willy Tarreau | ffc3fcd | 2012-10-12 20:17:54 +0200 | [diff] [blame] | 1581 | case LOG_FMT_SSL_VERSION: // %sslv |
| 1582 | src = NULL; |
Willy Tarreau | 9ad7bd4 | 2015-04-03 19:19:59 +0200 | [diff] [blame] | 1583 | conn = objt_conn(sess->origin); |
Willy Tarreau | b363a1f | 2013-10-01 10:45:07 +0200 | [diff] [blame] | 1584 | if (conn) { |
Willy Tarreau | fb0afa7 | 2015-04-03 14:46:27 +0200 | [diff] [blame] | 1585 | if (sess->listener->xprt == &ssl_sock) |
Willy Tarreau | b363a1f | 2013-10-01 10:45:07 +0200 | [diff] [blame] | 1586 | src = ssl_sock_get_proto_version(conn); |
| 1587 | } |
Willy Tarreau | ffc3fcd | 2012-10-12 20:17:54 +0200 | [diff] [blame] | 1588 | ret = lf_text(tmplog, src, dst + maxsize - tmplog, tmp); |
| 1589 | if (ret == NULL) |
| 1590 | goto out; |
| 1591 | tmplog = ret; |
| 1592 | last_isspace = 0; |
| 1593 | break; |
| 1594 | #endif |
William Lallemand | 1d70556 | 2012-03-12 12:46:41 +0100 | [diff] [blame] | 1595 | case LOG_FMT_BACKEND: // %b |
William Lallemand | bddd4fd | 2012-02-27 11:23:10 +0100 | [diff] [blame] | 1596 | src = be->id; |
William Lallemand | 5f23240 | 2012-04-05 18:02:55 +0200 | [diff] [blame] | 1597 | ret = lf_text(tmplog, src, dst + maxsize - tmplog, tmp); |
William Lallemand | 1d70556 | 2012-03-12 12:46:41 +0100 | [diff] [blame] | 1598 | if (ret == NULL) |
William Lallemand | bddd4fd | 2012-02-27 11:23:10 +0100 | [diff] [blame] | 1599 | goto out; |
William Lallemand | 1d70556 | 2012-03-12 12:46:41 +0100 | [diff] [blame] | 1600 | tmplog = ret; |
William Lallemand | 51b5dca | 2012-03-26 17:52:55 +0200 | [diff] [blame] | 1601 | last_isspace = 0; |
William Lallemand | bddd4fd | 2012-02-27 11:23:10 +0100 | [diff] [blame] | 1602 | break; |
| 1603 | |
William Lallemand | 1d70556 | 2012-03-12 12:46:41 +0100 | [diff] [blame] | 1604 | case LOG_FMT_SERVER: // %s |
Willy Tarreau | d79a3b2 | 2012-12-28 09:40:16 +0100 | [diff] [blame] | 1605 | switch (obj_type(s->target)) { |
| 1606 | case OBJ_TYPE_SERVER: |
| 1607 | src = objt_server(s->target)->id; |
| 1608 | break; |
| 1609 | case OBJ_TYPE_APPLET: |
| 1610 | src = objt_applet(s->target)->name; |
| 1611 | break; |
| 1612 | default: |
| 1613 | src = "<NOSRV>"; |
| 1614 | break; |
| 1615 | } |
William Lallemand | 5f23240 | 2012-04-05 18:02:55 +0200 | [diff] [blame] | 1616 | ret = lf_text(tmplog, src, dst + maxsize - tmplog, tmp); |
William Lallemand | 1d70556 | 2012-03-12 12:46:41 +0100 | [diff] [blame] | 1617 | if (ret == NULL) |
William Lallemand | bddd4fd | 2012-02-27 11:23:10 +0100 | [diff] [blame] | 1618 | goto out; |
William Lallemand | 1d70556 | 2012-03-12 12:46:41 +0100 | [diff] [blame] | 1619 | tmplog = ret; |
William Lallemand | bddd4fd | 2012-02-27 11:23:10 +0100 | [diff] [blame] | 1620 | last_isspace = 0; |
| 1621 | break; |
| 1622 | |
William Lallemand | 1d70556 | 2012-03-12 12:46:41 +0100 | [diff] [blame] | 1623 | case LOG_FMT_TQ: // %Tq |
William Lallemand | 5f23240 | 2012-04-05 18:02:55 +0200 | [diff] [blame] | 1624 | ret = ltoa_o(t_request, tmplog, dst + maxsize - tmplog); |
William Lallemand | 1d70556 | 2012-03-12 12:46:41 +0100 | [diff] [blame] | 1625 | if (ret == NULL) |
William Lallemand | bddd4fd | 2012-02-27 11:23:10 +0100 | [diff] [blame] | 1626 | goto out; |
William Lallemand | 1d70556 | 2012-03-12 12:46:41 +0100 | [diff] [blame] | 1627 | tmplog = ret; |
William Lallemand | bddd4fd | 2012-02-27 11:23:10 +0100 | [diff] [blame] | 1628 | last_isspace = 0; |
| 1629 | break; |
| 1630 | |
William Lallemand | 1d70556 | 2012-03-12 12:46:41 +0100 | [diff] [blame] | 1631 | case LOG_FMT_TW: // %Tw |
| 1632 | 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] | 1633 | tmplog, dst + maxsize - tmplog); |
William Lallemand | 1d70556 | 2012-03-12 12:46:41 +0100 | [diff] [blame] | 1634 | if (ret == NULL) |
William Lallemand | bddd4fd | 2012-02-27 11:23:10 +0100 | [diff] [blame] | 1635 | goto out; |
William Lallemand | 1d70556 | 2012-03-12 12:46:41 +0100 | [diff] [blame] | 1636 | tmplog = ret; |
William Lallemand | bddd4fd | 2012-02-27 11:23:10 +0100 | [diff] [blame] | 1637 | last_isspace = 0; |
| 1638 | break; |
| 1639 | |
William Lallemand | 1d70556 | 2012-03-12 12:46:41 +0100 | [diff] [blame] | 1640 | case LOG_FMT_TC: // %Tc |
| 1641 | 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] | 1642 | tmplog, dst + maxsize - tmplog); |
William Lallemand | 1d70556 | 2012-03-12 12:46:41 +0100 | [diff] [blame] | 1643 | if (ret == NULL) |
William Lallemand | bddd4fd | 2012-02-27 11:23:10 +0100 | [diff] [blame] | 1644 | goto out; |
William Lallemand | 1d70556 | 2012-03-12 12:46:41 +0100 | [diff] [blame] | 1645 | tmplog = ret; |
William Lallemand | bddd4fd | 2012-02-27 11:23:10 +0100 | [diff] [blame] | 1646 | last_isspace = 0; |
| 1647 | break; |
| 1648 | |
William Lallemand | 1d70556 | 2012-03-12 12:46:41 +0100 | [diff] [blame] | 1649 | case LOG_FMT_TR: // %Tr |
| 1650 | 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] | 1651 | tmplog, dst + maxsize - tmplog); |
William Lallemand | 1d70556 | 2012-03-12 12:46:41 +0100 | [diff] [blame] | 1652 | if (ret == NULL) |
William Lallemand | bddd4fd | 2012-02-27 11:23:10 +0100 | [diff] [blame] | 1653 | goto out; |
William Lallemand | 1d70556 | 2012-03-12 12:46:41 +0100 | [diff] [blame] | 1654 | tmplog = ret; |
William Lallemand | bddd4fd | 2012-02-27 11:23:10 +0100 | [diff] [blame] | 1655 | last_isspace = 0; |
| 1656 | break; |
| 1657 | |
William Lallemand | 1d70556 | 2012-03-12 12:46:41 +0100 | [diff] [blame] | 1658 | case LOG_FMT_TT: // %Tt |
Willy Tarreau | d79a3b2 | 2012-12-28 09:40:16 +0100 | [diff] [blame] | 1659 | if (!(fe->to_log & LW_BYTES)) |
William Lallemand | 1d70556 | 2012-03-12 12:46:41 +0100 | [diff] [blame] | 1660 | LOGCHAR('+'); |
William Lallemand | 5f23240 | 2012-04-05 18:02:55 +0200 | [diff] [blame] | 1661 | ret = ltoa_o(s->logs.t_close, tmplog, dst + maxsize - tmplog); |
William Lallemand | 1d70556 | 2012-03-12 12:46:41 +0100 | [diff] [blame] | 1662 | if (ret == NULL) |
William Lallemand | bddd4fd | 2012-02-27 11:23:10 +0100 | [diff] [blame] | 1663 | goto out; |
William Lallemand | 1d70556 | 2012-03-12 12:46:41 +0100 | [diff] [blame] | 1664 | tmplog = ret; |
William Lallemand | bddd4fd | 2012-02-27 11:23:10 +0100 | [diff] [blame] | 1665 | last_isspace = 0; |
| 1666 | break; |
| 1667 | |
Willy Tarreau | 2beef58 | 2012-12-20 17:22:52 +0100 | [diff] [blame] | 1668 | case LOG_FMT_STATUS: // %ST |
William Lallemand | 5f23240 | 2012-04-05 18:02:55 +0200 | [diff] [blame] | 1669 | ret = ltoa_o(txn->status, tmplog, dst + maxsize - tmplog); |
William Lallemand | 1d70556 | 2012-03-12 12:46:41 +0100 | [diff] [blame] | 1670 | if (ret == NULL) |
William Lallemand | bddd4fd | 2012-02-27 11:23:10 +0100 | [diff] [blame] | 1671 | goto out; |
William Lallemand | 1d70556 | 2012-03-12 12:46:41 +0100 | [diff] [blame] | 1672 | tmplog = ret; |
William Lallemand | bddd4fd | 2012-02-27 11:23:10 +0100 | [diff] [blame] | 1673 | last_isspace = 0; |
| 1674 | break; |
| 1675 | |
William Lallemand | 1d70556 | 2012-03-12 12:46:41 +0100 | [diff] [blame] | 1676 | case LOG_FMT_BYTES: // %B |
Willy Tarreau | d79a3b2 | 2012-12-28 09:40:16 +0100 | [diff] [blame] | 1677 | if (!(fe->to_log & LW_BYTES)) |
William Lallemand | 1d70556 | 2012-03-12 12:46:41 +0100 | [diff] [blame] | 1678 | LOGCHAR('+'); |
William Lallemand | 5f23240 | 2012-04-05 18:02:55 +0200 | [diff] [blame] | 1679 | ret = lltoa(s->logs.bytes_out, tmplog, dst + maxsize - tmplog); |
William Lallemand | 1d70556 | 2012-03-12 12:46:41 +0100 | [diff] [blame] | 1680 | if (ret == NULL) |
William Lallemand | bddd4fd | 2012-02-27 11:23:10 +0100 | [diff] [blame] | 1681 | goto out; |
William Lallemand | 1d70556 | 2012-03-12 12:46:41 +0100 | [diff] [blame] | 1682 | tmplog = ret; |
William Lallemand | bddd4fd | 2012-02-27 11:23:10 +0100 | [diff] [blame] | 1683 | last_isspace = 0; |
| 1684 | break; |
| 1685 | |
Willy Tarreau | c5259fd | 2012-12-20 15:38:04 +0100 | [diff] [blame] | 1686 | case LOG_FMT_BYTES_UP: // %U |
Willy Tarreau | c5259fd | 2012-12-20 15:38:04 +0100 | [diff] [blame] | 1687 | ret = lltoa(s->logs.bytes_in, tmplog, dst + maxsize - tmplog); |
| 1688 | if (ret == NULL) |
| 1689 | goto out; |
| 1690 | tmplog = ret; |
| 1691 | last_isspace = 0; |
| 1692 | break; |
| 1693 | |
Willy Tarreau | 2beef58 | 2012-12-20 17:22:52 +0100 | [diff] [blame] | 1694 | case LOG_FMT_CCLIENT: // %CC |
William Lallemand | bddd4fd | 2012-02-27 11:23:10 +0100 | [diff] [blame] | 1695 | src = txn->cli_cookie; |
William Lallemand | 5f23240 | 2012-04-05 18:02:55 +0200 | [diff] [blame] | 1696 | ret = lf_text(tmplog, src, dst + maxsize - tmplog, tmp); |
William Lallemand | 1d70556 | 2012-03-12 12:46:41 +0100 | [diff] [blame] | 1697 | if (ret == NULL) |
William Lallemand | 51b5dca | 2012-03-26 17:52:55 +0200 | [diff] [blame] | 1698 | goto out; |
William Lallemand | 1d70556 | 2012-03-12 12:46:41 +0100 | [diff] [blame] | 1699 | tmplog = ret; |
William Lallemand | bddd4fd | 2012-02-27 11:23:10 +0100 | [diff] [blame] | 1700 | last_isspace = 0; |
| 1701 | break; |
| 1702 | |
Willy Tarreau | 2beef58 | 2012-12-20 17:22:52 +0100 | [diff] [blame] | 1703 | case LOG_FMT_CSERVER: // %CS |
William Lallemand | bddd4fd | 2012-02-27 11:23:10 +0100 | [diff] [blame] | 1704 | src = txn->srv_cookie; |
William Lallemand | 5f23240 | 2012-04-05 18:02:55 +0200 | [diff] [blame] | 1705 | ret = lf_text(tmplog, src, dst + maxsize - tmplog, tmp); |
William Lallemand | 1d70556 | 2012-03-12 12:46:41 +0100 | [diff] [blame] | 1706 | if (ret == NULL) |
William Lallemand | 51b5dca | 2012-03-26 17:52:55 +0200 | [diff] [blame] | 1707 | goto out; |
William Lallemand | 1d70556 | 2012-03-12 12:46:41 +0100 | [diff] [blame] | 1708 | tmplog = ret; |
William Lallemand | bddd4fd | 2012-02-27 11:23:10 +0100 | [diff] [blame] | 1709 | last_isspace = 0; |
| 1710 | break; |
| 1711 | |
William Lallemand | 1d70556 | 2012-03-12 12:46:41 +0100 | [diff] [blame] | 1712 | case LOG_FMT_TERMSTATE: // %ts |
Willy Tarreau | e7dff02 | 2015-04-03 01:14:29 +0200 | [diff] [blame] | 1713 | LOGCHAR(sess_term_cond[(s->flags & SF_ERR_MASK) >> SF_ERR_SHIFT]); |
| 1714 | LOGCHAR(sess_fin_state[(s->flags & SF_FINST_MASK) >> SF_FINST_SHIFT]); |
Willy Tarreau | 6580c06 | 2012-03-12 15:09:42 +0100 | [diff] [blame] | 1715 | *tmplog = '\0'; |
| 1716 | last_isspace = 0; |
| 1717 | break; |
William Lallemand | bddd4fd | 2012-02-27 11:23:10 +0100 | [diff] [blame] | 1718 | |
William Lallemand | 1d70556 | 2012-03-12 12:46:41 +0100 | [diff] [blame] | 1719 | case LOG_FMT_TERMSTATE_CK: // %tsc, same as TS with cookie state (for mode HTTP) |
Willy Tarreau | e7dff02 | 2015-04-03 01:14:29 +0200 | [diff] [blame] | 1720 | LOGCHAR(sess_term_cond[(s->flags & SF_ERR_MASK) >> SF_ERR_SHIFT]); |
| 1721 | LOGCHAR(sess_fin_state[(s->flags & SF_FINST_MASK) >> SF_FINST_SHIFT]); |
Willy Tarreau | 6740213 | 2012-05-31 20:40:20 +0200 | [diff] [blame] | 1722 | LOGCHAR((be->ck_opts & PR_CK_ANY) ? sess_cookie[(txn->flags & TX_CK_MASK) >> TX_CK_SHIFT] : '-'); |
| 1723 | 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] | 1724 | last_isspace = 0; |
| 1725 | break; |
| 1726 | |
William Lallemand | 1d70556 | 2012-03-12 12:46:41 +0100 | [diff] [blame] | 1727 | case LOG_FMT_ACTCONN: // %ac |
William Lallemand | 5f23240 | 2012-04-05 18:02:55 +0200 | [diff] [blame] | 1728 | ret = ltoa_o(actconn, tmplog, dst + maxsize - tmplog); |
William Lallemand | 1d70556 | 2012-03-12 12:46:41 +0100 | [diff] [blame] | 1729 | if (ret == NULL) |
William Lallemand | bddd4fd | 2012-02-27 11:23:10 +0100 | [diff] [blame] | 1730 | goto out; |
William Lallemand | 1d70556 | 2012-03-12 12:46:41 +0100 | [diff] [blame] | 1731 | tmplog = ret; |
William Lallemand | bddd4fd | 2012-02-27 11:23:10 +0100 | [diff] [blame] | 1732 | last_isspace = 0; |
| 1733 | break; |
| 1734 | |
William Lallemand | 1d70556 | 2012-03-12 12:46:41 +0100 | [diff] [blame] | 1735 | case LOG_FMT_FECONN: // %fc |
William Lallemand | 5f23240 | 2012-04-05 18:02:55 +0200 | [diff] [blame] | 1736 | ret = ltoa_o(fe->feconn, tmplog, dst + maxsize - tmplog); |
William Lallemand | 1d70556 | 2012-03-12 12:46:41 +0100 | [diff] [blame] | 1737 | if (ret == NULL) |
William Lallemand | bddd4fd | 2012-02-27 11:23:10 +0100 | [diff] [blame] | 1738 | goto out; |
William Lallemand | 1d70556 | 2012-03-12 12:46:41 +0100 | [diff] [blame] | 1739 | tmplog = ret; |
William Lallemand | bddd4fd | 2012-02-27 11:23:10 +0100 | [diff] [blame] | 1740 | last_isspace = 0; |
| 1741 | break; |
| 1742 | |
William Lallemand | 1d70556 | 2012-03-12 12:46:41 +0100 | [diff] [blame] | 1743 | case LOG_FMT_BECONN: // %bc |
William Lallemand | 5f23240 | 2012-04-05 18:02:55 +0200 | [diff] [blame] | 1744 | ret = ltoa_o(be->beconn, tmplog, dst + maxsize - tmplog); |
William Lallemand | 1d70556 | 2012-03-12 12:46:41 +0100 | [diff] [blame] | 1745 | if (ret == NULL) |
William Lallemand | bddd4fd | 2012-02-27 11:23:10 +0100 | [diff] [blame] | 1746 | goto out; |
William Lallemand | 1d70556 | 2012-03-12 12:46:41 +0100 | [diff] [blame] | 1747 | tmplog = ret; |
William Lallemand | bddd4fd | 2012-02-27 11:23:10 +0100 | [diff] [blame] | 1748 | last_isspace = 0; |
| 1749 | break; |
| 1750 | |
William Lallemand | 1d70556 | 2012-03-12 12:46:41 +0100 | [diff] [blame] | 1751 | case LOG_FMT_SRVCONN: // %sc |
Willy Tarreau | 54a08d3 | 2012-11-12 01:14:56 +0100 | [diff] [blame] | 1752 | ret = ultoa_o(objt_server(s->target) ? |
Willy Tarreau | 3fdb366 | 2012-11-12 00:42:33 +0100 | [diff] [blame] | 1753 | objt_server(s->target)->cur_sess : |
William Lallemand | 5f23240 | 2012-04-05 18:02:55 +0200 | [diff] [blame] | 1754 | 0, tmplog, dst + maxsize - tmplog); |
William Lallemand | 1d70556 | 2012-03-12 12:46:41 +0100 | [diff] [blame] | 1755 | if (ret == NULL) |
William Lallemand | bddd4fd | 2012-02-27 11:23:10 +0100 | [diff] [blame] | 1756 | goto out; |
William Lallemand | 1d70556 | 2012-03-12 12:46:41 +0100 | [diff] [blame] | 1757 | tmplog = ret; |
William Lallemand | bddd4fd | 2012-02-27 11:23:10 +0100 | [diff] [blame] | 1758 | last_isspace = 0; |
| 1759 | break; |
| 1760 | |
William Lallemand | 1d70556 | 2012-03-12 12:46:41 +0100 | [diff] [blame] | 1761 | case LOG_FMT_RETRIES: // %rq |
Willy Tarreau | e7dff02 | 2015-04-03 01:14:29 +0200 | [diff] [blame] | 1762 | if (s->flags & SF_REDISP) |
William Lallemand | 1d70556 | 2012-03-12 12:46:41 +0100 | [diff] [blame] | 1763 | LOGCHAR('+'); |
Willy Tarreau | 350f487 | 2014-11-28 14:42:25 +0100 | [diff] [blame] | 1764 | ret = ltoa_o((s->si[1].conn_retries>0) ? |
| 1765 | (be->conn_retries - s->si[1].conn_retries) : |
William Lallemand | 5f23240 | 2012-04-05 18:02:55 +0200 | [diff] [blame] | 1766 | be->conn_retries, tmplog, dst + maxsize - tmplog); |
William Lallemand | 1d70556 | 2012-03-12 12:46:41 +0100 | [diff] [blame] | 1767 | if (ret == NULL) |
William Lallemand | 51b5dca | 2012-03-26 17:52:55 +0200 | [diff] [blame] | 1768 | goto out; |
William Lallemand | 1d70556 | 2012-03-12 12:46:41 +0100 | [diff] [blame] | 1769 | tmplog = ret; |
William Lallemand | bddd4fd | 2012-02-27 11:23:10 +0100 | [diff] [blame] | 1770 | last_isspace = 0; |
| 1771 | break; |
| 1772 | |
William Lallemand | 1d70556 | 2012-03-12 12:46:41 +0100 | [diff] [blame] | 1773 | case LOG_FMT_SRVQUEUE: // %sq |
William Lallemand | 5f23240 | 2012-04-05 18:02:55 +0200 | [diff] [blame] | 1774 | ret = ltoa_o(s->logs.srv_queue_size, tmplog, dst + maxsize - tmplog); |
William Lallemand | 1d70556 | 2012-03-12 12:46:41 +0100 | [diff] [blame] | 1775 | if (ret == NULL) |
William Lallemand | bddd4fd | 2012-02-27 11:23:10 +0100 | [diff] [blame] | 1776 | goto out; |
William Lallemand | 1d70556 | 2012-03-12 12:46:41 +0100 | [diff] [blame] | 1777 | tmplog = ret; |
William Lallemand | bddd4fd | 2012-02-27 11:23:10 +0100 | [diff] [blame] | 1778 | last_isspace = 0; |
| 1779 | break; |
| 1780 | |
William Lallemand | 1d70556 | 2012-03-12 12:46:41 +0100 | [diff] [blame] | 1781 | case LOG_FMT_BCKQUEUE: // %bq |
William Lallemand | 5f23240 | 2012-04-05 18:02:55 +0200 | [diff] [blame] | 1782 | ret = ltoa_o(s->logs.prx_queue_size, tmplog, dst + maxsize - tmplog); |
William Lallemand | 1d70556 | 2012-03-12 12:46:41 +0100 | [diff] [blame] | 1783 | if (ret == NULL) |
William Lallemand | bddd4fd | 2012-02-27 11:23:10 +0100 | [diff] [blame] | 1784 | goto out; |
William Lallemand | 1d70556 | 2012-03-12 12:46:41 +0100 | [diff] [blame] | 1785 | tmplog = ret; |
William Lallemand | bddd4fd | 2012-02-27 11:23:10 +0100 | [diff] [blame] | 1786 | last_isspace = 0; |
| 1787 | break; |
| 1788 | |
William Lallemand | 1d70556 | 2012-03-12 12:46:41 +0100 | [diff] [blame] | 1789 | case LOG_FMT_HDRREQUEST: // %hr |
William Lallemand | bddd4fd | 2012-02-27 11:23:10 +0100 | [diff] [blame] | 1790 | /* request header */ |
Willy Tarreau | cb7dd01 | 2015-04-03 22:16:32 +0200 | [diff] [blame] | 1791 | if (fe->nb_req_cap && s->req_cap) { |
William Lallemand | bddd4fd | 2012-02-27 11:23:10 +0100 | [diff] [blame] | 1792 | if (tmp->options & LOG_OPT_QUOTE) |
| 1793 | LOGCHAR('"'); |
| 1794 | LOGCHAR('{'); |
| 1795 | for (hdr = 0; hdr < fe->nb_req_cap; hdr++) { |
| 1796 | if (hdr) |
| 1797 | LOGCHAR('|'); |
Willy Tarreau | cb7dd01 | 2015-04-03 22:16:32 +0200 | [diff] [blame] | 1798 | if (s->req_cap[hdr] != NULL) { |
Dragan Dosen | 835b921 | 2016-02-12 13:23:03 +0100 | [diff] [blame] | 1799 | ret = lf_encode_string(tmplog, dst + maxsize, |
| 1800 | '#', hdr_encode_map, s->req_cap[hdr], tmp); |
William Lallemand | 1d70556 | 2012-03-12 12:46:41 +0100 | [diff] [blame] | 1801 | if (ret == NULL || *ret != '\0') |
William Lallemand | 51b5dca | 2012-03-26 17:52:55 +0200 | [diff] [blame] | 1802 | goto out; |
William Lallemand | 1d70556 | 2012-03-12 12:46:41 +0100 | [diff] [blame] | 1803 | tmplog = ret; |
William Lallemand | 51b5dca | 2012-03-26 17:52:55 +0200 | [diff] [blame] | 1804 | } |
William Lallemand | bddd4fd | 2012-02-27 11:23:10 +0100 | [diff] [blame] | 1805 | } |
| 1806 | LOGCHAR('}'); |
William Lallemand | 51b5dca | 2012-03-26 17:52:55 +0200 | [diff] [blame] | 1807 | if (tmp->options & LOG_OPT_QUOTE) |
| 1808 | LOGCHAR('"'); |
William Lallemand | bddd4fd | 2012-02-27 11:23:10 +0100 | [diff] [blame] | 1809 | last_isspace = 0; |
| 1810 | } |
William Lallemand | bddd4fd | 2012-02-27 11:23:10 +0100 | [diff] [blame] | 1811 | break; |
| 1812 | |
William Lallemand | 1d70556 | 2012-03-12 12:46:41 +0100 | [diff] [blame] | 1813 | case LOG_FMT_HDRREQUESTLIST: // %hrl |
William Lallemand | bddd4fd | 2012-02-27 11:23:10 +0100 | [diff] [blame] | 1814 | /* request header list */ |
Willy Tarreau | cb7dd01 | 2015-04-03 22:16:32 +0200 | [diff] [blame] | 1815 | if (fe->nb_req_cap && s->req_cap) { |
William Lallemand | bddd4fd | 2012-02-27 11:23:10 +0100 | [diff] [blame] | 1816 | for (hdr = 0; hdr < fe->nb_req_cap; hdr++) { |
| 1817 | if (hdr > 0) |
| 1818 | LOGCHAR(' '); |
| 1819 | if (tmp->options & LOG_OPT_QUOTE) |
| 1820 | LOGCHAR('"'); |
Willy Tarreau | cb7dd01 | 2015-04-03 22:16:32 +0200 | [diff] [blame] | 1821 | if (s->req_cap[hdr] != NULL) { |
Dragan Dosen | 835b921 | 2016-02-12 13:23:03 +0100 | [diff] [blame] | 1822 | ret = lf_encode_string(tmplog, dst + maxsize, |
| 1823 | '#', hdr_encode_map, s->req_cap[hdr], tmp); |
William Lallemand | 1d70556 | 2012-03-12 12:46:41 +0100 | [diff] [blame] | 1824 | if (ret == NULL || *ret != '\0') |
William Lallemand | 51b5dca | 2012-03-26 17:52:55 +0200 | [diff] [blame] | 1825 | goto out; |
William Lallemand | 1d70556 | 2012-03-12 12:46:41 +0100 | [diff] [blame] | 1826 | tmplog = ret; |
William Lallemand | bddd4fd | 2012-02-27 11:23:10 +0100 | [diff] [blame] | 1827 | } else if (!(tmp->options & LOG_OPT_QUOTE)) |
| 1828 | LOGCHAR('-'); |
| 1829 | if (tmp->options & LOG_OPT_QUOTE) |
| 1830 | LOGCHAR('"'); |
William Lallemand | bddd4fd | 2012-02-27 11:23:10 +0100 | [diff] [blame] | 1831 | last_isspace = 0; |
| 1832 | } |
| 1833 | } |
| 1834 | break; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1835 | |
William Lallemand | 1d70556 | 2012-03-12 12:46:41 +0100 | [diff] [blame] | 1836 | |
| 1837 | case LOG_FMT_HDRRESPONS: // %hs |
William Lallemand | bddd4fd | 2012-02-27 11:23:10 +0100 | [diff] [blame] | 1838 | /* response header */ |
Willy Tarreau | cb7dd01 | 2015-04-03 22:16:32 +0200 | [diff] [blame] | 1839 | if (fe->nb_rsp_cap && s->res_cap) { |
William Lallemand | bddd4fd | 2012-02-27 11:23:10 +0100 | [diff] [blame] | 1840 | if (tmp->options & LOG_OPT_QUOTE) |
| 1841 | LOGCHAR('"'); |
| 1842 | LOGCHAR('{'); |
| 1843 | for (hdr = 0; hdr < fe->nb_rsp_cap; hdr++) { |
| 1844 | if (hdr) |
| 1845 | LOGCHAR('|'); |
Willy Tarreau | cb7dd01 | 2015-04-03 22:16:32 +0200 | [diff] [blame] | 1846 | if (s->res_cap[hdr] != NULL) { |
Dragan Dosen | 835b921 | 2016-02-12 13:23:03 +0100 | [diff] [blame] | 1847 | ret = lf_encode_string(tmplog, dst + maxsize, |
| 1848 | '#', hdr_encode_map, s->res_cap[hdr], tmp); |
William Lallemand | 1d70556 | 2012-03-12 12:46:41 +0100 | [diff] [blame] | 1849 | if (ret == NULL || *ret != '\0') |
William Lallemand | 51b5dca | 2012-03-26 17:52:55 +0200 | [diff] [blame] | 1850 | goto out; |
William Lallemand | 1d70556 | 2012-03-12 12:46:41 +0100 | [diff] [blame] | 1851 | tmplog = ret; |
William Lallemand | 51b5dca | 2012-03-26 17:52:55 +0200 | [diff] [blame] | 1852 | } |
William Lallemand | bddd4fd | 2012-02-27 11:23:10 +0100 | [diff] [blame] | 1853 | } |
| 1854 | LOGCHAR('}'); |
| 1855 | last_isspace = 0; |
| 1856 | if (tmp->options & LOG_OPT_QUOTE) |
| 1857 | LOGCHAR('"'); |
| 1858 | } |
William Lallemand | bddd4fd | 2012-02-27 11:23:10 +0100 | [diff] [blame] | 1859 | break; |
| 1860 | |
William Lallemand | 1d70556 | 2012-03-12 12:46:41 +0100 | [diff] [blame] | 1861 | case LOG_FMT_HDRRESPONSLIST: // %hsl |
William Lallemand | bddd4fd | 2012-02-27 11:23:10 +0100 | [diff] [blame] | 1862 | /* response header list */ |
Willy Tarreau | cb7dd01 | 2015-04-03 22:16:32 +0200 | [diff] [blame] | 1863 | if (fe->nb_rsp_cap && s->res_cap) { |
William Lallemand | bddd4fd | 2012-02-27 11:23:10 +0100 | [diff] [blame] | 1864 | for (hdr = 0; hdr < fe->nb_rsp_cap; hdr++) { |
| 1865 | if (hdr > 0) |
| 1866 | LOGCHAR(' '); |
| 1867 | if (tmp->options & LOG_OPT_QUOTE) |
| 1868 | LOGCHAR('"'); |
Willy Tarreau | cb7dd01 | 2015-04-03 22:16:32 +0200 | [diff] [blame] | 1869 | if (s->res_cap[hdr] != NULL) { |
Dragan Dosen | 835b921 | 2016-02-12 13:23:03 +0100 | [diff] [blame] | 1870 | ret = lf_encode_string(tmplog, dst + maxsize, |
| 1871 | '#', hdr_encode_map, s->res_cap[hdr], tmp); |
William Lallemand | 1d70556 | 2012-03-12 12:46:41 +0100 | [diff] [blame] | 1872 | if (ret == NULL || *ret != '\0') |
William Lallemand | 51b5dca | 2012-03-26 17:52:55 +0200 | [diff] [blame] | 1873 | goto out; |
William Lallemand | 1d70556 | 2012-03-12 12:46:41 +0100 | [diff] [blame] | 1874 | tmplog = ret; |
William Lallemand | bddd4fd | 2012-02-27 11:23:10 +0100 | [diff] [blame] | 1875 | } else if (!(tmp->options & LOG_OPT_QUOTE)) |
| 1876 | LOGCHAR('-'); |
| 1877 | if (tmp->options & LOG_OPT_QUOTE) |
| 1878 | LOGCHAR('"'); |
William Lallemand | bddd4fd | 2012-02-27 11:23:10 +0100 | [diff] [blame] | 1879 | last_isspace = 0; |
| 1880 | } |
| 1881 | } |
| 1882 | break; |
| 1883 | |
William Lallemand | 1d70556 | 2012-03-12 12:46:41 +0100 | [diff] [blame] | 1884 | case LOG_FMT_REQ: // %r |
William Lallemand | bddd4fd | 2012-02-27 11:23:10 +0100 | [diff] [blame] | 1885 | /* Request */ |
| 1886 | if (tmp->options & LOG_OPT_QUOTE) |
| 1887 | LOGCHAR('"'); |
| 1888 | uri = txn->uri ? txn->uri : "<BADREQ>"; |
Dragan Dosen | 835b921 | 2016-02-12 13:23:03 +0100 | [diff] [blame] | 1889 | ret = lf_encode_string(tmplog, dst + maxsize, |
| 1890 | '#', url_encode_map, uri, tmp); |
William Lallemand | 1d70556 | 2012-03-12 12:46:41 +0100 | [diff] [blame] | 1891 | if (ret == NULL || *ret != '\0') |
William Lallemand | 51b5dca | 2012-03-26 17:52:55 +0200 | [diff] [blame] | 1892 | goto out; |
William Lallemand | 1d70556 | 2012-03-12 12:46:41 +0100 | [diff] [blame] | 1893 | tmplog = ret; |
William Lallemand | bddd4fd | 2012-02-27 11:23:10 +0100 | [diff] [blame] | 1894 | if (tmp->options & LOG_OPT_QUOTE) |
| 1895 | LOGCHAR('"'); |
William Lallemand | bddd4fd | 2012-02-27 11:23:10 +0100 | [diff] [blame] | 1896 | last_isspace = 0; |
| 1897 | break; |
William Lallemand | 5f23240 | 2012-04-05 18:02:55 +0200 | [diff] [blame] | 1898 | |
Andrew Hayworth | 0ebc55f | 2015-04-27 21:37:03 +0000 | [diff] [blame] | 1899 | case LOG_FMT_HTTP_PATH: // %HP |
| 1900 | uri = txn->uri ? txn->uri : "<BADREQ>"; |
| 1901 | |
Willy Tarreau | b7636d1 | 2015-06-17 19:58:02 +0200 | [diff] [blame] | 1902 | if (tmp->options & LOG_OPT_QUOTE) |
Andrew Hayworth | 0ebc55f | 2015-04-27 21:37:03 +0000 | [diff] [blame] | 1903 | LOGCHAR('"'); |
| 1904 | |
| 1905 | end = uri + strlen(uri); |
| 1906 | // look for the first whitespace character |
| 1907 | while (uri < end && !HTTP_IS_SPHT(*uri)) |
| 1908 | uri++; |
| 1909 | |
| 1910 | // keep advancing past multiple spaces |
| 1911 | while (uri < end && HTTP_IS_SPHT(*uri)) { |
| 1912 | uri++; nspaces++; |
| 1913 | } |
| 1914 | |
| 1915 | // look for first space or question mark after url |
| 1916 | spc = uri; |
| 1917 | while (spc < end && *spc != '?' && !HTTP_IS_SPHT(*spc)) |
| 1918 | spc++; |
| 1919 | |
| 1920 | if (!txn->uri || nspaces == 0) { |
| 1921 | chunk.str = "<BADREQ>"; |
| 1922 | chunk.len = strlen("<BADREQ>"); |
| 1923 | } else { |
| 1924 | chunk.str = uri; |
| 1925 | chunk.len = spc - uri; |
| 1926 | } |
| 1927 | |
Dragan Dosen | 835b921 | 2016-02-12 13:23:03 +0100 | [diff] [blame] | 1928 | ret = lf_encode_chunk(tmplog, dst + maxsize, '#', url_encode_map, &chunk, tmp); |
Andrew Hayworth | 0ebc55f | 2015-04-27 21:37:03 +0000 | [diff] [blame] | 1929 | if (ret == NULL || *ret != '\0') |
| 1930 | goto out; |
| 1931 | |
| 1932 | tmplog = ret; |
Willy Tarreau | b7636d1 | 2015-06-17 19:58:02 +0200 | [diff] [blame] | 1933 | if (tmp->options & LOG_OPT_QUOTE) |
Andrew Hayworth | 0ebc55f | 2015-04-27 21:37:03 +0000 | [diff] [blame] | 1934 | LOGCHAR('"'); |
| 1935 | |
| 1936 | last_isspace = 0; |
| 1937 | break; |
| 1938 | |
Andrew Hayworth | e63ac87 | 2015-07-31 16:14:16 +0000 | [diff] [blame] | 1939 | case LOG_FMT_HTTP_QUERY: // %HQ |
| 1940 | if (tmp->options & LOG_OPT_QUOTE) |
| 1941 | LOGCHAR('"'); |
| 1942 | |
| 1943 | if (!txn->uri) { |
| 1944 | chunk.str = "<BADREQ>"; |
| 1945 | chunk.len = strlen("<BADREQ>"); |
| 1946 | } else { |
| 1947 | uri = txn->uri; |
| 1948 | end = uri + strlen(uri); |
| 1949 | // look for the first question mark |
| 1950 | while (uri < end && *uri != '?') |
| 1951 | uri++; |
| 1952 | |
| 1953 | qmark = uri; |
| 1954 | // look for first space or question mark after url |
| 1955 | while (uri < end && !HTTP_IS_SPHT(*uri)) |
| 1956 | uri++; |
| 1957 | |
| 1958 | chunk.str = qmark; |
| 1959 | chunk.len = uri - qmark; |
| 1960 | } |
| 1961 | |
Dragan Dosen | 835b921 | 2016-02-12 13:23:03 +0100 | [diff] [blame] | 1962 | ret = lf_encode_chunk(tmplog, dst + maxsize, '#', url_encode_map, &chunk, tmp); |
Andrew Hayworth | e63ac87 | 2015-07-31 16:14:16 +0000 | [diff] [blame] | 1963 | if (ret == NULL || *ret != '\0') |
| 1964 | goto out; |
| 1965 | |
| 1966 | tmplog = ret; |
| 1967 | if (tmp->options & LOG_OPT_QUOTE) |
| 1968 | LOGCHAR('"'); |
| 1969 | |
| 1970 | last_isspace = 0; |
| 1971 | break; |
| 1972 | |
Andrew Hayworth | 0ebc55f | 2015-04-27 21:37:03 +0000 | [diff] [blame] | 1973 | case LOG_FMT_HTTP_URI: // %HU |
| 1974 | uri = txn->uri ? txn->uri : "<BADREQ>"; |
| 1975 | |
Willy Tarreau | b7636d1 | 2015-06-17 19:58:02 +0200 | [diff] [blame] | 1976 | if (tmp->options & LOG_OPT_QUOTE) |
Andrew Hayworth | 0ebc55f | 2015-04-27 21:37:03 +0000 | [diff] [blame] | 1977 | LOGCHAR('"'); |
| 1978 | |
| 1979 | end = uri + strlen(uri); |
| 1980 | // look for the first whitespace character |
| 1981 | while (uri < end && !HTTP_IS_SPHT(*uri)) |
| 1982 | uri++; |
| 1983 | |
| 1984 | // keep advancing past multiple spaces |
| 1985 | while (uri < end && HTTP_IS_SPHT(*uri)) { |
| 1986 | uri++; nspaces++; |
| 1987 | } |
| 1988 | |
| 1989 | // look for first space after url |
| 1990 | spc = uri; |
| 1991 | while (spc < end && !HTTP_IS_SPHT(*spc)) |
| 1992 | spc++; |
| 1993 | |
| 1994 | if (!txn->uri || nspaces == 0) { |
| 1995 | chunk.str = "<BADREQ>"; |
| 1996 | chunk.len = strlen("<BADREQ>"); |
| 1997 | } else { |
| 1998 | chunk.str = uri; |
| 1999 | chunk.len = spc - uri; |
| 2000 | } |
| 2001 | |
Dragan Dosen | 835b921 | 2016-02-12 13:23:03 +0100 | [diff] [blame] | 2002 | ret = lf_encode_chunk(tmplog, dst + maxsize, '#', url_encode_map, &chunk, tmp); |
Andrew Hayworth | 0ebc55f | 2015-04-27 21:37:03 +0000 | [diff] [blame] | 2003 | if (ret == NULL || *ret != '\0') |
| 2004 | goto out; |
| 2005 | |
| 2006 | tmplog = ret; |
Willy Tarreau | b7636d1 | 2015-06-17 19:58:02 +0200 | [diff] [blame] | 2007 | if (tmp->options & LOG_OPT_QUOTE) |
Andrew Hayworth | 0ebc55f | 2015-04-27 21:37:03 +0000 | [diff] [blame] | 2008 | LOGCHAR('"'); |
| 2009 | |
| 2010 | last_isspace = 0; |
| 2011 | break; |
| 2012 | |
| 2013 | case LOG_FMT_HTTP_METHOD: // %HM |
| 2014 | uri = txn->uri ? txn->uri : "<BADREQ>"; |
Willy Tarreau | b7636d1 | 2015-06-17 19:58:02 +0200 | [diff] [blame] | 2015 | if (tmp->options & LOG_OPT_QUOTE) |
Andrew Hayworth | 0ebc55f | 2015-04-27 21:37:03 +0000 | [diff] [blame] | 2016 | LOGCHAR('"'); |
| 2017 | |
| 2018 | end = uri + strlen(uri); |
| 2019 | // look for the first whitespace character |
| 2020 | spc = uri; |
| 2021 | while (spc < end && !HTTP_IS_SPHT(*spc)) |
| 2022 | spc++; |
| 2023 | |
| 2024 | if (spc == end) { // odd case, we have txn->uri, but we only got a verb |
| 2025 | chunk.str = "<BADREQ>"; |
| 2026 | chunk.len = strlen("<BADREQ>"); |
| 2027 | } else { |
| 2028 | chunk.str = uri; |
| 2029 | chunk.len = spc - uri; |
| 2030 | } |
| 2031 | |
Dragan Dosen | 835b921 | 2016-02-12 13:23:03 +0100 | [diff] [blame] | 2032 | ret = lf_encode_chunk(tmplog, dst + maxsize, '#', url_encode_map, &chunk, tmp); |
Andrew Hayworth | 0ebc55f | 2015-04-27 21:37:03 +0000 | [diff] [blame] | 2033 | if (ret == NULL || *ret != '\0') |
| 2034 | goto out; |
| 2035 | |
| 2036 | tmplog = ret; |
Willy Tarreau | b7636d1 | 2015-06-17 19:58:02 +0200 | [diff] [blame] | 2037 | if (tmp->options & LOG_OPT_QUOTE) |
Andrew Hayworth | 0ebc55f | 2015-04-27 21:37:03 +0000 | [diff] [blame] | 2038 | LOGCHAR('"'); |
| 2039 | |
| 2040 | last_isspace = 0; |
| 2041 | break; |
| 2042 | |
| 2043 | case LOG_FMT_HTTP_VERSION: // %HV |
| 2044 | uri = txn->uri ? txn->uri : "<BADREQ>"; |
Willy Tarreau | b7636d1 | 2015-06-17 19:58:02 +0200 | [diff] [blame] | 2045 | if (tmp->options & LOG_OPT_QUOTE) |
Andrew Hayworth | 0ebc55f | 2015-04-27 21:37:03 +0000 | [diff] [blame] | 2046 | LOGCHAR('"'); |
| 2047 | |
| 2048 | end = uri + strlen(uri); |
| 2049 | // look for the first whitespace character |
| 2050 | while (uri < end && !HTTP_IS_SPHT(*uri)) |
| 2051 | uri++; |
| 2052 | |
| 2053 | // keep advancing past multiple spaces |
| 2054 | while (uri < end && HTTP_IS_SPHT(*uri)) { |
| 2055 | uri++; nspaces++; |
| 2056 | } |
| 2057 | |
| 2058 | // look for the next whitespace character |
| 2059 | while (uri < end && !HTTP_IS_SPHT(*uri)) |
| 2060 | uri++; |
| 2061 | |
| 2062 | // keep advancing past multiple spaces |
| 2063 | while (uri < end && HTTP_IS_SPHT(*uri)) |
| 2064 | uri++; |
| 2065 | |
| 2066 | if (!txn->uri || nspaces == 0) { |
| 2067 | chunk.str = "<BADREQ>"; |
| 2068 | chunk.len = strlen("<BADREQ>"); |
| 2069 | } else if (uri == end) { |
| 2070 | chunk.str = "HTTP/0.9"; |
| 2071 | chunk.len = strlen("HTTP/0.9"); |
| 2072 | } else { |
| 2073 | chunk.str = uri; |
| 2074 | chunk.len = end - uri; |
| 2075 | } |
| 2076 | |
Dragan Dosen | 835b921 | 2016-02-12 13:23:03 +0100 | [diff] [blame] | 2077 | ret = lf_encode_chunk(tmplog, dst + maxsize, '#', url_encode_map, &chunk, tmp); |
Andrew Hayworth | 0ebc55f | 2015-04-27 21:37:03 +0000 | [diff] [blame] | 2078 | if (ret == NULL || *ret != '\0') |
| 2079 | goto out; |
| 2080 | |
| 2081 | tmplog = ret; |
Willy Tarreau | b7636d1 | 2015-06-17 19:58:02 +0200 | [diff] [blame] | 2082 | if (tmp->options & LOG_OPT_QUOTE) |
Andrew Hayworth | 0ebc55f | 2015-04-27 21:37:03 +0000 | [diff] [blame] | 2083 | LOGCHAR('"'); |
| 2084 | |
| 2085 | last_isspace = 0; |
| 2086 | break; |
| 2087 | |
William Lallemand | 5f23240 | 2012-04-05 18:02:55 +0200 | [diff] [blame] | 2088 | case LOG_FMT_COUNTER: // %rt |
| 2089 | if (tmp->options & LOG_OPT_HEXA) { |
Willy Tarreau | 1f0da24 | 2014-01-25 11:01:50 +0100 | [diff] [blame] | 2090 | iret = snprintf(tmplog, dst + maxsize - tmplog, "%04X", s->uniq_id); |
William Lallemand | 5f23240 | 2012-04-05 18:02:55 +0200 | [diff] [blame] | 2091 | if (iret < 0 || iret > dst + maxsize - tmplog) |
| 2092 | goto out; |
| 2093 | last_isspace = 0; |
| 2094 | tmplog += iret; |
| 2095 | } else { |
Willy Tarreau | 1f0da24 | 2014-01-25 11:01:50 +0100 | [diff] [blame] | 2096 | ret = ltoa_o(s->uniq_id, tmplog, dst + maxsize - tmplog); |
William Lallemand | 5f23240 | 2012-04-05 18:02:55 +0200 | [diff] [blame] | 2097 | if (ret == NULL) |
| 2098 | goto out; |
| 2099 | tmplog = ret; |
| 2100 | last_isspace = 0; |
| 2101 | } |
| 2102 | break; |
| 2103 | |
Willy Tarreau | 7346acb | 2014-08-28 15:03:15 +0200 | [diff] [blame] | 2104 | case LOG_FMT_LOGCNT: // %lc |
| 2105 | if (tmp->options & LOG_OPT_HEXA) { |
Willy Tarreau | e36cbcb | 2015-04-03 15:40:56 +0200 | [diff] [blame] | 2106 | iret = snprintf(tmplog, dst + maxsize - tmplog, "%04X", fe->log_count); |
Willy Tarreau | 7346acb | 2014-08-28 15:03:15 +0200 | [diff] [blame] | 2107 | if (iret < 0 || iret > dst + maxsize - tmplog) |
| 2108 | goto out; |
| 2109 | last_isspace = 0; |
| 2110 | tmplog += iret; |
| 2111 | } else { |
Willy Tarreau | e36cbcb | 2015-04-03 15:40:56 +0200 | [diff] [blame] | 2112 | ret = ultoa_o(fe->log_count, tmplog, dst + maxsize - tmplog); |
Willy Tarreau | 7346acb | 2014-08-28 15:03:15 +0200 | [diff] [blame] | 2113 | if (ret == NULL) |
| 2114 | goto out; |
| 2115 | tmplog = ret; |
| 2116 | last_isspace = 0; |
| 2117 | } |
| 2118 | break; |
| 2119 | |
William Lallemand | 5f23240 | 2012-04-05 18:02:55 +0200 | [diff] [blame] | 2120 | case LOG_FMT_HOSTNAME: // %H |
| 2121 | src = hostname; |
| 2122 | ret = lf_text(tmplog, src, dst + maxsize - tmplog, tmp); |
| 2123 | if (ret == NULL) |
| 2124 | goto out; |
| 2125 | tmplog = ret; |
| 2126 | last_isspace = 0; |
| 2127 | break; |
| 2128 | |
| 2129 | case LOG_FMT_PID: // %pid |
| 2130 | if (tmp->options & LOG_OPT_HEXA) { |
| 2131 | iret = snprintf(tmplog, dst + maxsize - tmplog, "%04X", pid); |
| 2132 | if (iret < 0 || iret > dst + maxsize - tmplog) |
| 2133 | goto out; |
| 2134 | last_isspace = 0; |
| 2135 | tmplog += iret; |
| 2136 | } else { |
| 2137 | ret = ltoa_o(pid, tmplog, dst + maxsize - tmplog); |
| 2138 | if (ret == NULL) |
| 2139 | goto out; |
| 2140 | tmplog = ret; |
| 2141 | last_isspace = 0; |
| 2142 | } |
| 2143 | break; |
William Lallemand | a73203e | 2012-03-12 12:48:57 +0100 | [diff] [blame] | 2144 | |
| 2145 | case LOG_FMT_UNIQUEID: // %ID |
William Lallemand | 5b7ea3a | 2013-08-28 15:44:19 +0200 | [diff] [blame] | 2146 | ret = NULL; |
William Lallemand | a73203e | 2012-03-12 12:48:57 +0100 | [diff] [blame] | 2147 | src = s->unique_id; |
Thierry FOURNIER | 1be6910 | 2014-04-15 01:38:48 +0200 | [diff] [blame] | 2148 | ret = lf_text(tmplog, src, maxsize - (tmplog - dst), tmp); |
William Lallemand | a73203e | 2012-03-12 12:48:57 +0100 | [diff] [blame] | 2149 | if (ret == NULL) |
| 2150 | goto out; |
| 2151 | tmplog = ret; |
| 2152 | last_isspace = 0; |
| 2153 | break; |
| 2154 | |
William Lallemand | bddd4fd | 2012-02-27 11:23:10 +0100 | [diff] [blame] | 2155 | } |
| 2156 | } |
| 2157 | |
| 2158 | out: |
William Lallemand | 1d70556 | 2012-03-12 12:46:41 +0100 | [diff] [blame] | 2159 | /* *tmplog is a unused character */ |
| 2160 | *tmplog = '\0'; |
Willy Tarreau | df97447 | 2012-12-28 02:44:01 +0100 | [diff] [blame] | 2161 | return tmplog - dst; |
William Lallemand | bddd4fd | 2012-02-27 11:23:10 +0100 | [diff] [blame] | 2162 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2163 | } |
| 2164 | |
William Lallemand | 1d70556 | 2012-03-12 12:46:41 +0100 | [diff] [blame] | 2165 | /* |
Willy Tarreau | 87b0966 | 2015-04-03 00:22:06 +0200 | [diff] [blame] | 2166 | * send a log for the stream when we have enough info about it. |
William Lallemand | 1d70556 | 2012-03-12 12:46:41 +0100 | [diff] [blame] | 2167 | * Will not log if the frontend has no log defined. |
| 2168 | */ |
Willy Tarreau | 87b0966 | 2015-04-03 00:22:06 +0200 | [diff] [blame] | 2169 | void strm_log(struct stream *s) |
William Lallemand | 1d70556 | 2012-03-12 12:46:41 +0100 | [diff] [blame] | 2170 | { |
Willy Tarreau | e36cbcb | 2015-04-03 15:40:56 +0200 | [diff] [blame] | 2171 | struct session *sess = s->sess; |
William Lallemand | 1d70556 | 2012-03-12 12:46:41 +0100 | [diff] [blame] | 2172 | int size, err, level; |
Dragan Dosen | 0b85ece | 2015-09-25 19:17:44 +0200 | [diff] [blame] | 2173 | int sd_size = 0; |
William Lallemand | 1d70556 | 2012-03-12 12:46:41 +0100 | [diff] [blame] | 2174 | |
| 2175 | /* if we don't want to log normal traffic, return now */ |
Willy Tarreau | e7dff02 | 2015-04-03 01:14:29 +0200 | [diff] [blame] | 2176 | err = (s->flags & SF_REDISP) || |
| 2177 | ((s->flags & SF_ERR_MASK) > SF_ERR_LOCAL) || |
| 2178 | (((s->flags & SF_ERR_MASK) == SF_ERR_NONE) && |
Willy Tarreau | 350f487 | 2014-11-28 14:42:25 +0100 | [diff] [blame] | 2179 | (s->si[1].conn_retries != s->be->conn_retries)) || |
Willy Tarreau | eee5b51 | 2015-04-03 23:46:31 +0200 | [diff] [blame] | 2180 | ((sess->fe->mode == PR_MODE_HTTP) && s->txn && s->txn->status >= 500); |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2181 | |
Willy Tarreau | e36cbcb | 2015-04-03 15:40:56 +0200 | [diff] [blame] | 2182 | if (!err && (sess->fe->options2 & PR_O2_NOLOGNORM)) |
William Lallemand | 1d70556 | 2012-03-12 12:46:41 +0100 | [diff] [blame] | 2183 | return; |
William Lallemand | bddd4fd | 2012-02-27 11:23:10 +0100 | [diff] [blame] | 2184 | |
Willy Tarreau | e36cbcb | 2015-04-03 15:40:56 +0200 | [diff] [blame] | 2185 | if (LIST_ISEMPTY(&sess->fe->logsrvs)) |
William Lallemand | 1d70556 | 2012-03-12 12:46:41 +0100 | [diff] [blame] | 2186 | return; |
William Lallemand | bddd4fd | 2012-02-27 11:23:10 +0100 | [diff] [blame] | 2187 | |
Willy Tarreau | abcd514 | 2013-06-11 17:18:02 +0200 | [diff] [blame] | 2188 | if (s->logs.level) { /* loglevel was overridden */ |
| 2189 | if (s->logs.level == -1) { |
| 2190 | s->logs.logwait = 0; /* logs disabled */ |
| 2191 | return; |
| 2192 | } |
| 2193 | level = s->logs.level - 1; |
| 2194 | } |
| 2195 | else { |
| 2196 | level = LOG_INFO; |
Willy Tarreau | e36cbcb | 2015-04-03 15:40:56 +0200 | [diff] [blame] | 2197 | if (err && (sess->fe->options2 & PR_O2_LOGERRORS)) |
Willy Tarreau | abcd514 | 2013-06-11 17:18:02 +0200 | [diff] [blame] | 2198 | level = LOG_ERR; |
| 2199 | } |
William Lallemand | 1d70556 | 2012-03-12 12:46:41 +0100 | [diff] [blame] | 2200 | |
William Lallemand | 5b7ea3a | 2013-08-28 15:44:19 +0200 | [diff] [blame] | 2201 | /* if unique-id was not generated */ |
Willy Tarreau | e36cbcb | 2015-04-03 15:40:56 +0200 | [diff] [blame] | 2202 | if (!s->unique_id && !LIST_ISEMPTY(&sess->fe->format_unique_id)) { |
William Lallemand | 5b7ea3a | 2013-08-28 15:44:19 +0200 | [diff] [blame] | 2203 | if ((s->unique_id = pool_alloc2(pool2_uniqueid)) != NULL) |
Willy Tarreau | e36cbcb | 2015-04-03 15:40:56 +0200 | [diff] [blame] | 2204 | build_logline(s, s->unique_id, UNIQUEID_LEN, &sess->fe->format_unique_id); |
William Lallemand | 5b7ea3a | 2013-08-28 15:44:19 +0200 | [diff] [blame] | 2205 | } |
| 2206 | |
Dragan Dosen | 0b85ece | 2015-09-25 19:17:44 +0200 | [diff] [blame] | 2207 | if (!LIST_ISEMPTY(&sess->fe->logformat_sd)) { |
| 2208 | sd_size = build_logline(s, logline_rfc5424, global.max_syslog_len, |
| 2209 | &sess->fe->logformat_sd); |
| 2210 | } |
| 2211 | |
Dragan Dosen | 59cee97 | 2015-09-19 22:09:02 +0200 | [diff] [blame] | 2212 | size = build_logline(s, logline, global.max_syslog_len, &sess->fe->logformat); |
William Lallemand | 1d70556 | 2012-03-12 12:46:41 +0100 | [diff] [blame] | 2213 | if (size > 0) { |
Willy Tarreau | e36cbcb | 2015-04-03 15:40:56 +0200 | [diff] [blame] | 2214 | sess->fe->log_count++; |
Dragan Dosen | 0b85ece | 2015-09-25 19:17:44 +0200 | [diff] [blame] | 2215 | __send_log(sess->fe, level, logline, size + 1, logline_rfc5424, sd_size); |
William Lallemand | 1d70556 | 2012-03-12 12:46:41 +0100 | [diff] [blame] | 2216 | s->logs.logwait = 0; |
| 2217 | } |
| 2218 | } |
William Lallemand | bddd4fd | 2012-02-27 11:23:10 +0100 | [diff] [blame] | 2219 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2220 | /* |
| 2221 | * Local variables: |
| 2222 | * c-indent-level: 8 |
| 2223 | * c-basic-offset: 8 |
| 2224 | * End: |
| 2225 | */ |