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