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 | c8f24f8 | 2007-11-30 18:38:35 +0100 | [diff] [blame] | 13 | #include <fcntl.h> |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 14 | #include <stdarg.h> |
| 15 | #include <stdio.h> |
| 16 | #include <stdlib.h> |
| 17 | #include <string.h> |
| 18 | #include <syslog.h> |
| 19 | #include <time.h> |
| 20 | #include <unistd.h> |
Robert Tsai | 81ae195 | 2007-12-05 10:47:29 +0100 | [diff] [blame] | 21 | #include <errno.h> |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 22 | |
| 23 | #include <sys/time.h> |
| 24 | |
Willy Tarreau | e3ba5f0 | 2006-06-29 18:54:54 +0200 | [diff] [blame] | 25 | #include <common/config.h> |
Willy Tarreau | d6d0690 | 2009-08-19 11:22:33 +0200 | [diff] [blame] | 26 | #include <common/compat.h> |
Willy Tarreau | 2dd0d47 | 2006-06-29 17:53:05 +0200 | [diff] [blame] | 27 | #include <common/standard.h> |
Willy Tarreau | fb27867 | 2006-10-15 15:38:50 +0200 | [diff] [blame] | 28 | #include <common/time.h> |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 29 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 30 | #include <types/global.h> |
Willy Tarreau | ec6c5df | 2008-07-15 00:22:45 +0200 | [diff] [blame] | 31 | |
| 32 | #include <proto/log.h> |
Willy Tarreau | 827aee9 | 2011-03-10 16:55:02 +0100 | [diff] [blame] | 33 | #include <proto/stream_interface.h> |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 34 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 35 | const char *log_facilities[NB_LOG_FACILITIES] = { |
| 36 | "kern", "user", "mail", "daemon", |
| 37 | "auth", "syslog", "lpr", "news", |
| 38 | "uucp", "cron", "auth2", "ftp", |
| 39 | "ntp", "audit", "alert", "cron2", |
| 40 | "local0", "local1", "local2", "local3", |
| 41 | "local4", "local5", "local6", "local7" |
| 42 | }; |
| 43 | |
| 44 | |
| 45 | const char *log_levels[NB_LOG_LEVELS] = { |
| 46 | "emerg", "alert", "crit", "err", |
| 47 | "warning", "notice", "info", "debug" |
| 48 | }; |
| 49 | |
| 50 | const char *monthname[12] = { |
| 51 | "Jan", "Feb", "Mar", "Apr", "May", "Jun", |
| 52 | "Jul", "Aug", "Sep", "Oct", "Nov", "Dec" |
| 53 | }; |
| 54 | |
Willy Tarreau | a2a64e9 | 2011-09-07 23:01:56 +0200 | [diff] [blame] | 55 | const char sess_term_cond[10] = "-cCsSPRIDK"; /* normal, CliTo, CliErr, SrvTo, SrvErr, PxErr, Resource, Internal, Down, Killed */ |
Willy Tarreau | b8750a8 | 2006-09-03 09:56:00 +0200 | [diff] [blame] | 56 | 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] | 57 | |
| 58 | /* |
| 59 | * Displays the message on stderr with the date and pid. Overrides the quiet |
| 60 | * mode during startup. |
| 61 | */ |
Willy Tarreau | b17916e | 2006-10-15 15:17:57 +0200 | [diff] [blame] | 62 | void Alert(const char *fmt, ...) |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 63 | { |
| 64 | va_list argp; |
Willy Tarreau | fe94460 | 2007-10-25 10:34:16 +0200 | [diff] [blame] | 65 | struct tm tm; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 66 | |
| 67 | if (!(global.mode & MODE_QUIET) || (global.mode & (MODE_VERBOSE | MODE_STARTING))) { |
| 68 | va_start(argp, fmt); |
| 69 | |
Willy Tarreau | b7f694f | 2008-06-22 17:18:02 +0200 | [diff] [blame] | 70 | get_localtime(date.tv_sec, &tm); |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 71 | fprintf(stderr, "[ALERT] %03d/%02d%02d%02d (%d) : ", |
Willy Tarreau | fe94460 | 2007-10-25 10:34:16 +0200 | [diff] [blame] | 72 | 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] | 73 | vfprintf(stderr, fmt, argp); |
| 74 | fflush(stderr); |
| 75 | va_end(argp); |
| 76 | } |
| 77 | } |
| 78 | |
| 79 | |
| 80 | /* |
| 81 | * Displays the message on stderr with the date and pid. |
| 82 | */ |
Willy Tarreau | b17916e | 2006-10-15 15:17:57 +0200 | [diff] [blame] | 83 | void Warning(const char *fmt, ...) |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 84 | { |
| 85 | va_list argp; |
Willy Tarreau | fe94460 | 2007-10-25 10:34:16 +0200 | [diff] [blame] | 86 | struct tm tm; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 87 | |
| 88 | if (!(global.mode & MODE_QUIET) || (global.mode & MODE_VERBOSE)) { |
| 89 | va_start(argp, fmt); |
| 90 | |
Willy Tarreau | b7f694f | 2008-06-22 17:18:02 +0200 | [diff] [blame] | 91 | get_localtime(date.tv_sec, &tm); |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 92 | fprintf(stderr, "[WARNING] %03d/%02d%02d%02d (%d) : ", |
Willy Tarreau | fe94460 | 2007-10-25 10:34:16 +0200 | [diff] [blame] | 93 | 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] | 94 | vfprintf(stderr, fmt, argp); |
| 95 | fflush(stderr); |
| 96 | va_end(argp); |
| 97 | } |
| 98 | } |
| 99 | |
| 100 | /* |
| 101 | * Displays the message on <out> only if quiet mode is not set. |
| 102 | */ |
Willy Tarreau | b17916e | 2006-10-15 15:17:57 +0200 | [diff] [blame] | 103 | void qfprintf(FILE *out, const char *fmt, ...) |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 104 | { |
| 105 | va_list argp; |
| 106 | |
| 107 | if (!(global.mode & MODE_QUIET) || (global.mode & MODE_VERBOSE)) { |
| 108 | va_start(argp, fmt); |
| 109 | vfprintf(out, fmt, argp); |
| 110 | fflush(out); |
| 111 | va_end(argp); |
| 112 | } |
| 113 | } |
| 114 | |
| 115 | /* |
| 116 | * returns log level for <lev> or -1 if not found. |
| 117 | */ |
| 118 | int get_log_level(const char *lev) |
| 119 | { |
| 120 | int level; |
| 121 | |
| 122 | level = NB_LOG_LEVELS - 1; |
| 123 | while (level >= 0 && strcmp(log_levels[level], lev)) |
| 124 | level--; |
| 125 | |
| 126 | return level; |
| 127 | } |
| 128 | |
| 129 | |
| 130 | /* |
| 131 | * returns log facility for <fac> or -1 if not found. |
| 132 | */ |
| 133 | int get_log_facility(const char *fac) |
| 134 | { |
| 135 | int facility; |
| 136 | |
| 137 | facility = NB_LOG_FACILITIES - 1; |
| 138 | while (facility >= 0 && strcmp(log_facilities[facility], fac)) |
| 139 | facility--; |
| 140 | |
| 141 | return facility; |
| 142 | } |
| 143 | |
Robert Tsai | 81ae195 | 2007-12-05 10:47:29 +0100 | [diff] [blame] | 144 | /* |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 145 | * This function sends a syslog message to both log servers of a proxy, |
| 146 | * or to global log servers if the proxy is NULL. |
| 147 | * It also tries not to waste too much time computing the message header. |
| 148 | * It doesn't care about errors nor does it report them. |
| 149 | */ |
Willy Tarreau | b17916e | 2006-10-15 15:17:57 +0200 | [diff] [blame] | 150 | void send_log(struct proxy *p, int level, const char *message, ...) |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 151 | { |
Robert Tsai | 81ae195 | 2007-12-05 10:47:29 +0100 | [diff] [blame] | 152 | static int logfdunix = -1; /* syslog to AF_UNIX socket */ |
| 153 | static int logfdinet = -1; /* syslog to AF_INET socket */ |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 154 | static long tvsec = -1; /* to force the string to be initialized */ |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 155 | va_list argp; |
| 156 | static char logmsg[MAX_SYSLOG_LEN]; |
| 157 | static char *dataptr = NULL; |
| 158 | int fac_level; |
| 159 | int hdr_len, data_len; |
William Lallemand | 0f99e34 | 2011-10-12 17:50:54 +0200 | [diff] [blame] | 160 | struct list *logsrvs = NULL; |
| 161 | struct logsrv *tmp = NULL; |
Robert Tsai | 81ae195 | 2007-12-05 10:47:29 +0100 | [diff] [blame] | 162 | int nblogger; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 163 | char *log_ptr; |
| 164 | |
Kevinm | 48936af | 2010-12-22 16:08:21 +0000 | [diff] [blame] | 165 | if (level < 0 || message == NULL) |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 166 | return; |
| 167 | |
Willy Tarreau | b7f694f | 2008-06-22 17:18:02 +0200 | [diff] [blame] | 168 | if (unlikely(date.tv_sec != tvsec || dataptr == NULL)) { |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 169 | /* this string is rebuild only once a second */ |
Willy Tarreau | fe94460 | 2007-10-25 10:34:16 +0200 | [diff] [blame] | 170 | struct tm tm; |
| 171 | |
Willy Tarreau | b7f694f | 2008-06-22 17:18:02 +0200 | [diff] [blame] | 172 | tvsec = date.tv_sec; |
Willy Tarreau | fe94460 | 2007-10-25 10:34:16 +0200 | [diff] [blame] | 173 | get_localtime(tvsec, &tm); |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 174 | |
| 175 | hdr_len = snprintf(logmsg, sizeof(logmsg), |
Joe Williams | df5b38f | 2010-12-29 17:05:48 +0100 | [diff] [blame] | 176 | "<<<<>%s %2d %02d:%02d:%02d %s%s[%d]: ", |
Willy Tarreau | fe94460 | 2007-10-25 10:34:16 +0200 | [diff] [blame] | 177 | monthname[tm.tm_mon], |
| 178 | tm.tm_mday, tm.tm_hour, tm.tm_min, tm.tm_sec, |
Joe Williams | df5b38f | 2010-12-29 17:05:48 +0100 | [diff] [blame] | 179 | global.log_send_hostname ? global.log_send_hostname : "", |
Kevinm | 48936af | 2010-12-22 16:08:21 +0000 | [diff] [blame] | 180 | global.log_tag, pid); |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 181 | /* WARNING: depending upon implementations, snprintf may return |
| 182 | * either -1 or the number of bytes that would be needed to store |
| 183 | * the total message. In both cases, we must adjust it. |
| 184 | */ |
| 185 | if (hdr_len < 0 || hdr_len > sizeof(logmsg)) |
| 186 | hdr_len = sizeof(logmsg); |
| 187 | |
| 188 | dataptr = logmsg + hdr_len; |
| 189 | } |
| 190 | |
| 191 | va_start(argp, message); |
Willy Tarreau | 8d5d7f2 | 2007-01-21 19:16:41 +0100 | [diff] [blame] | 192 | /* |
| 193 | * FIXME: we take a huge performance hit here. We might have to replace |
| 194 | * vsnprintf() for a hard-coded log writer. |
| 195 | */ |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 196 | data_len = vsnprintf(dataptr, logmsg + sizeof(logmsg) - dataptr, message, argp); |
| 197 | if (data_len < 0 || data_len > (logmsg + sizeof(logmsg) - dataptr)) |
| 198 | data_len = logmsg + sizeof(logmsg) - dataptr; |
| 199 | va_end(argp); |
| 200 | dataptr[data_len - 1] = '\n'; /* force a break on ultra-long lines */ |
| 201 | |
| 202 | if (p == NULL) { |
William Lallemand | 0f99e34 | 2011-10-12 17:50:54 +0200 | [diff] [blame] | 203 | if (!LIST_ISEMPTY(&global.logsrvs)) { |
| 204 | logsrvs = &global.logsrvs; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 205 | } |
| 206 | } else { |
William Lallemand | 0f99e34 | 2011-10-12 17:50:54 +0200 | [diff] [blame] | 207 | if (!LIST_ISEMPTY(&p->logsrvs)) { |
| 208 | logsrvs = &p->logsrvs; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 209 | } |
Robert Tsai | 81ae195 | 2007-12-05 10:47:29 +0100 | [diff] [blame] | 210 | } |
| 211 | |
William Lallemand | 0f99e34 | 2011-10-12 17:50:54 +0200 | [diff] [blame] | 212 | if (!logsrvs) |
| 213 | return; |
| 214 | |
Robert Tsai | 81ae195 | 2007-12-05 10:47:29 +0100 | [diff] [blame] | 215 | /* Lazily set up syslog sockets for protocol families of configured |
| 216 | * syslog servers. */ |
William Lallemand | 0f99e34 | 2011-10-12 17:50:54 +0200 | [diff] [blame] | 217 | nblogger = 0; |
| 218 | list_for_each_entry(tmp, logsrvs, list) { |
| 219 | const struct logsrv *logsrv = tmp; |
Robert Tsai | 81ae195 | 2007-12-05 10:47:29 +0100 | [diff] [blame] | 220 | int proto, *plogfd; |
William Lallemand | 0f99e34 | 2011-10-12 17:50:54 +0200 | [diff] [blame] | 221 | |
David du Colombier | 11bcb6c | 2011-03-24 12:23:00 +0100 | [diff] [blame] | 222 | if (logsrv->addr.ss_family == AF_UNIX) { |
Robert Tsai | 81ae195 | 2007-12-05 10:47:29 +0100 | [diff] [blame] | 223 | proto = 0; |
| 224 | plogfd = &logfdunix; |
| 225 | } else { |
Robert Tsai | 81ae195 | 2007-12-05 10:47:29 +0100 | [diff] [blame] | 226 | proto = IPPROTO_UDP; |
| 227 | plogfd = &logfdinet; |
| 228 | } |
| 229 | if (*plogfd >= 0) { |
| 230 | /* socket already created. */ |
| 231 | continue; |
| 232 | } |
David du Colombier | 11bcb6c | 2011-03-24 12:23:00 +0100 | [diff] [blame] | 233 | if ((*plogfd = socket(logsrv->addr.ss_family, SOCK_DGRAM, |
Robert Tsai | 81ae195 | 2007-12-05 10:47:29 +0100 | [diff] [blame] | 234 | proto)) < 0) { |
| 235 | Alert("socket for logger #%d failed: %s (errno=%d)\n", |
| 236 | nblogger + 1, strerror(errno), errno); |
| 237 | return; |
| 238 | } |
| 239 | /* we don't want to receive anything on this socket */ |
| 240 | setsockopt(*plogfd, SOL_SOCKET, SO_RCVBUF, &zero, sizeof(zero)); |
| 241 | /* does nothing under Linux, maybe needed for others */ |
| 242 | shutdown(*plogfd, SHUT_RD); |
William Lallemand | 0f99e34 | 2011-10-12 17:50:54 +0200 | [diff] [blame] | 243 | nblogger++; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 244 | } |
| 245 | |
Robert Tsai | 81ae195 | 2007-12-05 10:47:29 +0100 | [diff] [blame] | 246 | /* Send log messages to syslog server. */ |
William Lallemand | 0f99e34 | 2011-10-12 17:50:54 +0200 | [diff] [blame] | 247 | nblogger = 0; |
| 248 | list_for_each_entry(tmp, logsrvs, list) { |
| 249 | const struct logsrv *logsrv = tmp; |
David du Colombier | 11bcb6c | 2011-03-24 12:23:00 +0100 | [diff] [blame] | 250 | int *plogfd = logsrv->addr.ss_family == AF_UNIX ? |
Robert Tsai | 81ae195 | 2007-12-05 10:47:29 +0100 | [diff] [blame] | 251 | &logfdunix : &logfdinet; |
| 252 | int sent; |
| 253 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 254 | /* 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] | 255 | if (level > logsrv->level) |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 256 | continue; |
| 257 | |
| 258 | /* For each target, we may have a different facility. |
| 259 | * We can also have a different log level for each message. |
| 260 | * This induces variations in the message header length. |
| 261 | * Since we don't want to recompute it each time, nor copy it every |
| 262 | * time, we only change the facility in the pre-computed header, |
| 263 | * and we change the pointer to the header accordingly. |
| 264 | */ |
William Lallemand | 0f99e34 | 2011-10-12 17:50:54 +0200 | [diff] [blame] | 265 | fac_level = (logsrv->facility << 3) + MAX(level, logsrv->minlvl); |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 266 | log_ptr = logmsg + 3; /* last digit of the log level */ |
| 267 | do { |
| 268 | *log_ptr = '0' + fac_level % 10; |
| 269 | fac_level /= 10; |
| 270 | log_ptr--; |
| 271 | } while (fac_level && log_ptr > logmsg); |
| 272 | *log_ptr = '<'; |
| 273 | |
| 274 | /* the total syslog message now starts at logptr, for dataptr+data_len-logptr */ |
Robert Tsai | 81ae195 | 2007-12-05 10:47:29 +0100 | [diff] [blame] | 275 | sent = sendto(*plogfd, log_ptr, dataptr + data_len - log_ptr, |
Willy Tarreau | 1b4b7ce | 2011-04-05 16:56:50 +0200 | [diff] [blame] | 276 | MSG_DONTWAIT | MSG_NOSIGNAL, |
| 277 | (struct sockaddr *)&logsrv->addr, get_addr_len(&logsrv->addr)); |
Robert Tsai | 81ae195 | 2007-12-05 10:47:29 +0100 | [diff] [blame] | 278 | if (sent < 0) { |
| 279 | Alert("sendto logger #%d failed: %s (errno=%d)\n", |
| 280 | nblogger, strerror(errno), errno); |
| 281 | } |
William Lallemand | 0f99e34 | 2011-10-12 17:50:54 +0200 | [diff] [blame] | 282 | nblogger++; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 283 | } |
| 284 | } |
| 285 | |
| 286 | |
| 287 | /* |
| 288 | * send a log for the session when we have enough info about it |
| 289 | */ |
Willy Tarreau | 4225058 | 2007-04-01 01:30:43 +0200 | [diff] [blame] | 290 | void tcp_sess_log(struct session *s) |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 291 | { |
Cyril Bonté | acd7d63 | 2010-11-01 19:26:02 +0100 | [diff] [blame] | 292 | char pn[INET6_ADDRSTRLEN]; |
Willy Tarreau | 73de989 | 2006-11-30 11:40:23 +0100 | [diff] [blame] | 293 | struct proxy *fe = s->fe; |
Willy Tarreau | ddb358d | 2006-12-17 22:55:52 +0100 | [diff] [blame] | 294 | struct proxy *be = s->be; |
| 295 | struct proxy *prx_log; |
Willy Tarreau | c9bd0cc | 2009-05-10 11:57:02 +0200 | [diff] [blame] | 296 | int tolog, level, err; |
Willy Tarreau | 4225058 | 2007-04-01 01:30:43 +0200 | [diff] [blame] | 297 | char *svid; |
Willy Tarreau | fe94460 | 2007-10-25 10:34:16 +0200 | [diff] [blame] | 298 | struct tm tm; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 299 | |
Willy Tarreau | c9bd0cc | 2009-05-10 11:57:02 +0200 | [diff] [blame] | 300 | /* if we don't want to log normal traffic, return now */ |
Willy Tarreau | ee28de0 | 2010-06-01 09:51:00 +0200 | [diff] [blame] | 301 | err = (s->flags & (SN_ERR_MASK | SN_REDISP)) || (s->req->cons->conn_retries != be->conn_retries); |
Willy Tarreau | c9bd0cc | 2009-05-10 11:57:02 +0200 | [diff] [blame] | 302 | if (!err && (fe->options2 & PR_O2_NOLOGNORM)) |
| 303 | return; |
| 304 | |
Willy Tarreau | 6471afb | 2011-09-23 10:54:59 +0200 | [diff] [blame] | 305 | addr_to_str(&s->si[0].addr.from, pn, sizeof(pn)); |
Willy Tarreau | fe94460 | 2007-10-25 10:34:16 +0200 | [diff] [blame] | 306 | get_localtime(s->logs.tv_accept.tv_sec, &tm); |
Willy Tarreau | ddb358d | 2006-12-17 22:55:52 +0100 | [diff] [blame] | 307 | |
William Lallemand | 0f99e34 | 2011-10-12 17:50:54 +0200 | [diff] [blame] | 308 | if(LIST_ISEMPTY(&fe->logsrvs)) |
Willy Tarreau | e7ded1f | 2009-08-09 10:11:45 +0200 | [diff] [blame] | 309 | return; |
Willy Tarreau | ddb358d | 2006-12-17 22:55:52 +0100 | [diff] [blame] | 310 | |
Willy Tarreau | e7ded1f | 2009-08-09 10:11:45 +0200 | [diff] [blame] | 311 | prx_log = fe; |
Willy Tarreau | 4225058 | 2007-04-01 01:30:43 +0200 | [diff] [blame] | 312 | tolog = fe->to_log; |
Willy Tarreau | 71904a4 | 2011-02-13 14:30:26 +0100 | [diff] [blame] | 313 | |
| 314 | if (!(tolog & LW_SVID)) |
| 315 | svid = "-"; |
Willy Tarreau | 7b7a8e9 | 2011-03-27 19:53:06 +0200 | [diff] [blame] | 316 | else switch (s->target.type) { |
Willy Tarreau | 71904a4 | 2011-02-13 14:30:26 +0100 | [diff] [blame] | 317 | case TARG_TYPE_SERVER: |
Willy Tarreau | 7b7a8e9 | 2011-03-27 19:53:06 +0200 | [diff] [blame] | 318 | svid = s->target.ptr.s->id; |
Willy Tarreau | 71904a4 | 2011-02-13 14:30:26 +0100 | [diff] [blame] | 319 | break; |
| 320 | case TARG_TYPE_APPLET: |
Willy Tarreau | 7b7a8e9 | 2011-03-27 19:53:06 +0200 | [diff] [blame] | 321 | svid = s->target.ptr.a->name; |
Willy Tarreau | 71904a4 | 2011-02-13 14:30:26 +0100 | [diff] [blame] | 322 | break; |
| 323 | default: |
| 324 | svid = "<NOSRV>"; |
| 325 | break; |
| 326 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 327 | |
Willy Tarreau | c9bd0cc | 2009-05-10 11:57:02 +0200 | [diff] [blame] | 328 | level = LOG_INFO; |
| 329 | if (err && (fe->options2 & PR_O2_LOGERRORS)) |
| 330 | level = LOG_ERR; |
| 331 | |
| 332 | send_log(prx_log, level, "%s:%d [%02d/%s/%04d:%02d:%02d:%02d.%03d]" |
Willy Tarreau | 1772ece | 2009-04-03 14:49:12 +0200 | [diff] [blame] | 333 | " %s %s/%s %ld/%ld/%s%ld %s%lld" |
| 334 | " %c%c %d/%d/%d/%d/%s%u %ld/%ld\n", |
Willy Tarreau | 6471afb | 2011-09-23 10:54:59 +0200 | [diff] [blame] | 335 | s->si[0].addr.from.ss_family == AF_UNIX ? "unix" : pn, |
| 336 | s->si[0].addr.from.ss_family == AF_UNIX ? s->listener->luid : get_host_port(&s->si[0].addr.from), |
Willy Tarreau | fe94460 | 2007-10-25 10:34:16 +0200 | [diff] [blame] | 337 | tm.tm_mday, monthname[tm.tm_mon], tm.tm_year+1900, |
Willy Tarreau | 1772ece | 2009-04-03 14:49:12 +0200 | [diff] [blame] | 338 | tm.tm_hour, tm.tm_min, tm.tm_sec, (int)s->logs.tv_accept.tv_usec/1000, |
Willy Tarreau | 4225058 | 2007-04-01 01:30:43 +0200 | [diff] [blame] | 339 | fe->id, be->id, svid, |
| 340 | (s->logs.t_queue >= 0) ? s->logs.t_queue : -1, |
| 341 | (s->logs.t_connect >= 0) ? s->logs.t_connect - s->logs.t_queue : -1, |
| 342 | (tolog & LW_BYTES) ? "" : "+", s->logs.t_close, |
Willy Tarreau | 8b3977f | 2008-01-18 11:16:32 +0100 | [diff] [blame] | 343 | (tolog & LW_BYTES) ? "" : "+", s->logs.bytes_out, |
Willy Tarreau | 4225058 | 2007-04-01 01:30:43 +0200 | [diff] [blame] | 344 | sess_term_cond[(s->flags & SN_ERR_MASK) >> SN_ERR_SHIFT], |
| 345 | sess_fin_state[(s->flags & SN_FINST_MASK) >> SN_FINST_SHIFT], |
Willy Tarreau | 827aee9 | 2011-03-10 16:55:02 +0100 | [diff] [blame] | 346 | actconn, fe->feconn, be->beconn, target_srv(&s->target) ? target_srv(&s->target)->cur_sess : 0, |
Krzysztof Piotr Oledzki | 25b501a | 2008-01-06 16:36:16 +0100 | [diff] [blame] | 347 | (s->flags & SN_REDISP)?"+":"", |
Willy Tarreau | ee28de0 | 2010-06-01 09:51:00 +0200 | [diff] [blame] | 348 | (s->req->cons->conn_retries>0)?(be->conn_retries - s->req->cons->conn_retries):be->conn_retries, |
Willy Tarreau | 4225058 | 2007-04-01 01:30:43 +0200 | [diff] [blame] | 349 | s->logs.srv_queue_size, s->logs.prx_queue_size); |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 350 | |
| 351 | s->logs.logwait = 0; |
| 352 | } |
| 353 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 354 | |
| 355 | /* |
| 356 | * Local variables: |
| 357 | * c-indent-level: 8 |
| 358 | * c-basic-offset: 8 |
| 359 | * End: |
| 360 | */ |