|
@@ -0,0 +1,360 @@
|
|
1
|
+From dc2695cc531bd7fc98f09df5f6e1e57290ab1a14 Mon Sep 17 00:00:00 2001
|
|
2
|
+From: Willy Tarreau <w@1wt.eu>
|
|
3
|
+Date: Fri, 27 Jun 2014 18:10:07 +0200
|
|
4
|
+Subject: [PATCH 9/9] MEDIUM: log: support a user-configurable max log line
|
|
5
|
+ length
|
|
6
|
+
|
|
7
|
+With all the goodies supported by logformat, people find that the limit
|
|
8
|
+of 1024 chars for log lines is too short. Some servers do not support
|
|
9
|
+larger lines and can simply drop them, so changing the default value is
|
|
10
|
+not always the best choice.
|
|
11
|
+
|
|
12
|
+This patch takes a different approach. Log line length is specified per
|
|
13
|
+log server on the "log" line, with a value between 80 and 65535. That
|
|
14
|
+way it's possibly to satisfy all needs, even with some fat local servers
|
|
15
|
+and small remote ones.
|
|
16
|
+(cherry picked from commit 18324f574f349d510622ff45635de899437a3a11)
|
|
17
|
+---
|
|
18
|
+ doc/configuration.txt | 28 ++++++++++++++++--
|
|
19
|
+ include/proto/log.h | 1 +
|
|
20
|
+ include/types/global.h | 1 +
|
|
21
|
+ include/types/log.h | 1 +
|
|
22
|
+ src/cfgparse.c | 80 ++++++++++++++++++++++++++++++++++++++++----------
|
|
23
|
+ src/log.c | 36 ++++++++++++++++-------
|
|
24
|
+ 6 files changed, 118 insertions(+), 29 deletions(-)
|
|
25
|
+
|
|
26
|
+diff --git a/doc/configuration.txt b/doc/configuration.txt
|
|
27
|
+index 080d8fc..e53bb21 100644
|
|
28
|
+--- a/doc/configuration.txt
|
|
29
|
++++ b/doc/configuration.txt
|
|
30
|
+@@ -559,7 +559,7 @@ group <group name>
|
|
31
|
+ Similar to "gid" but uses the GID of group name <group name> from /etc/group.
|
|
32
|
+ See also "gid" and "user".
|
|
33
|
+
|
|
34
|
+-log <address> <facility> [max level [min level]]
|
|
35
|
++log <address> [len <length>] <facility> [max level [min level]]
|
|
36
|
+ Adds a global syslog server. Up to two global servers can be defined. They
|
|
37
|
+ will receive logs for startups and exits, as well as all logs from proxies
|
|
38
|
+ configured with "log global".
|
|
39
|
+@@ -584,6 +584,18 @@ log <address> <facility> [max level [min level]]
|
|
40
|
+ optionally enclosing them with braces ('{}'), similarly to what is done
|
|
41
|
+ in Bourne shell.
|
|
42
|
+
|
|
43
|
++ <length> is an optional maximum line length. Log lines larger than this value
|
|
44
|
++ will be truncated before being sent. The reason is that syslog
|
|
45
|
++ servers act differently on log line length. All servers support the
|
|
46
|
++ default value of 1024, but some servers simply drop larger lines
|
|
47
|
++ while others do log them. If a server supports long lines, it may
|
|
48
|
++ make sense to set this value here in order to avoid truncating long
|
|
49
|
++ lines. Similarly, if a server drops long lines, it is preferable to
|
|
50
|
++ truncate them before sending them. Accepted values are 80 to 65535
|
|
51
|
++ inclusive. The default value of 1024 is generally fine for all
|
|
52
|
++ standard usages. Some specific cases of long captures or
|
|
53
|
++ JSON-formated logs may require larger values.
|
|
54
|
++
|
|
55
|
+ <facility> must be one of the 24 standard syslog facilities :
|
|
56
|
+
|
|
57
|
+ kern user mail daemon auth syslog lpr news
|
|
58
|
+@@ -3349,7 +3361,7 @@ ignore-persist { if | unless } <condition>
|
|
59
|
+
|
|
60
|
+
|
|
61
|
+ log global
|
|
62
|
+-log <address> <facility> [<level> [<minlevel>]]
|
|
63
|
++log <address> [len <length>] <facility> [<level> [<minlevel>]]
|
|
64
|
+ no log
|
|
65
|
+ Enable per-instance logging of events and traffic.
|
|
66
|
+ May be used in sections : defaults | frontend | listen | backend
|
|
67
|
+@@ -3389,6 +3401,18 @@ no log
|
|
68
|
+ sign ('$') and optionally enclosing them with braces ('{}'),
|
|
69
|
+ similarly to what is done in Bourne shell.
|
|
70
|
+
|
|
71
|
++ <length> is an optional maximum line length. Log lines larger than this
|
|
72
|
++ value will be truncated before being sent. The reason is that
|
|
73
|
++ syslog servers act differently on log line length. All servers
|
|
74
|
++ support the default value of 1024, but some servers simply drop
|
|
75
|
++ larger lines while others do log them. If a server supports long
|
|
76
|
++ lines, it may make sense to set this value here in order to avoid
|
|
77
|
++ truncating long lines. Similarly, if a server drops long lines,
|
|
78
|
++ it is preferable to truncate them before sending them. Accepted
|
|
79
|
++ values are 80 to 65535 inclusive. The default value of 1024 is
|
|
80
|
++ generally fine for all standard usages. Some specific cases of
|
|
81
|
++ long captures or JSON-formated logs may require larger values.
|
|
82
|
++
|
|
83
|
+ <facility> must be one of the 24 standard syslog facilities :
|
|
84
|
+
|
|
85
|
+ kern user mail daemon auth syslog lpr news
|
|
86
|
+diff --git a/include/proto/log.h b/include/proto/log.h
|
|
87
|
+index e3c1a75..54c51d1 100644
|
|
88
|
+--- a/include/proto/log.h
|
|
89
|
++++ b/include/proto/log.h
|
|
90
|
+@@ -39,6 +39,7 @@ extern char *log_format;
|
|
91
|
+ extern char default_tcp_log_format[];
|
|
92
|
+ extern char default_http_log_format[];
|
|
93
|
+ extern char clf_http_log_format[];
|
|
94
|
++extern char *logline;
|
|
95
|
+
|
|
96
|
+
|
|
97
|
+ int build_logline(struct session *s, char *dst, size_t maxsize, struct list *list_format);
|
|
98
|
+diff --git a/include/types/global.h b/include/types/global.h
|
|
99
|
+index 23e3f3d..77df1dd 100644
|
|
100
|
+--- a/include/types/global.h
|
|
101
|
++++ b/include/types/global.h
|
|
102
|
+@@ -110,6 +110,7 @@ struct global {
|
|
103
|
+ int last_checks;
|
|
104
|
+ int spread_checks;
|
|
105
|
+ int max_spread_checks;
|
|
106
|
++ int max_syslog_len;
|
|
107
|
+ char *chroot;
|
|
108
|
+ char *pidfile;
|
|
109
|
+ char *node, *desc; /* node name & description */
|
|
110
|
+diff --git a/include/types/log.h b/include/types/log.h
|
|
111
|
+index b3288bd..c7e47ea 100644
|
|
112
|
+--- a/include/types/log.h
|
|
113
|
++++ b/include/types/log.h
|
|
114
|
+@@ -152,6 +152,7 @@ struct logsrv {
|
|
115
|
+ int facility;
|
|
116
|
+ int level;
|
|
117
|
+ int minlvl;
|
|
118
|
++ int maxlen;
|
|
119
|
+ };
|
|
120
|
+
|
|
121
|
+ #endif /* _TYPES_LOG_H */
|
|
122
|
+diff --git a/src/cfgparse.c b/src/cfgparse.c
|
|
123
|
+index 762978a..e6e65b4 100644
|
|
124
|
+--- a/src/cfgparse.c
|
|
125
|
++++ b/src/cfgparse.c
|
|
126
|
+@@ -1254,6 +1254,8 @@ int cfg_parse_global(const char *file, int linenum, char **args, int kwm)
|
|
127
|
+ struct sockaddr_storage *sk;
|
|
128
|
+ int port1, port2;
|
|
129
|
+ struct logsrv *logsrv;
|
|
130
|
++ int arg = 0;
|
|
131
|
++ int len = 0;
|
|
132
|
+
|
|
133
|
+ if (*(args[1]) == 0 || *(args[2]) == 0) {
|
|
134
|
+ Alert("parsing [%s:%d] : '%s' expects <address> and <facility> as arguments.\n", file, linenum, args[0]);
|
|
135
|
+@@ -1263,28 +1265,50 @@ int cfg_parse_global(const char *file, int linenum, char **args, int kwm)
|
|
136
|
+
|
|
137
|
+ logsrv = calloc(1, sizeof(struct logsrv));
|
|
138
|
+
|
|
139
|
+- logsrv->facility = get_log_facility(args[2]);
|
|
140
|
++ /* just after the address, a length may be specified */
|
|
141
|
++ if (strcmp(args[arg+2], "len") == 0) {
|
|
142
|
++ len = atoi(args[arg+3]);
|
|
143
|
++ if (len < 80 || len > 65535) {
|
|
144
|
++ Alert("parsing [%s:%d] : invalid log length '%s', must be between 80 and 65535.\n",
|
|
145
|
++ file, linenum, args[arg+3]);
|
|
146
|
++ err_code |= ERR_ALERT | ERR_FATAL;
|
|
147
|
++ goto out;
|
|
148
|
++ }
|
|
149
|
++ logsrv->maxlen = len;
|
|
150
|
++
|
|
151
|
++ /* skip these two args */
|
|
152
|
++ arg += 2;
|
|
153
|
++ }
|
|
154
|
++ else
|
|
155
|
++ logsrv->maxlen = MAX_SYSLOG_LEN;
|
|
156
|
++
|
|
157
|
++ if (logsrv->maxlen > global.max_syslog_len) {
|
|
158
|
++ global.max_syslog_len = logsrv->maxlen;
|
|
159
|
++ logline = realloc(logline, global.max_syslog_len + 1);
|
|
160
|
++ }
|
|
161
|
++
|
|
162
|
++ logsrv->facility = get_log_facility(args[arg+2]);
|
|
163
|
+ if (logsrv->facility < 0) {
|
|
164
|
+- Alert("parsing [%s:%d] : unknown log facility '%s'\n", file, linenum, args[2]);
|
|
165
|
++ Alert("parsing [%s:%d] : unknown log facility '%s'\n", file, linenum, args[arg+2]);
|
|
166
|
+ err_code |= ERR_ALERT | ERR_FATAL;
|
|
167
|
+ logsrv->facility = 0;
|
|
168
|
+ }
|
|
169
|
+
|
|
170
|
+ logsrv->level = 7; /* max syslog level = debug */
|
|
171
|
+- if (*(args[3])) {
|
|
172
|
+- logsrv->level = get_log_level(args[3]);
|
|
173
|
++ if (*(args[arg+3])) {
|
|
174
|
++ logsrv->level = get_log_level(args[arg+3]);
|
|
175
|
+ if (logsrv->level < 0) {
|
|
176
|
+- Alert("parsing [%s:%d] : unknown optional log level '%s'\n", file, linenum, args[3]);
|
|
177
|
++ Alert("parsing [%s:%d] : unknown optional log level '%s'\n", file, linenum, args[arg+3]);
|
|
178
|
+ err_code |= ERR_ALERT | ERR_FATAL;
|
|
179
|
+ logsrv->level = 0;
|
|
180
|
+ }
|
|
181
|
+ }
|
|
182
|
+
|
|
183
|
+ logsrv->minlvl = 0; /* limit syslog level to this level (emerg) */
|
|
184
|
+- if (*(args[4])) {
|
|
185
|
+- logsrv->minlvl = get_log_level(args[4]);
|
|
186
|
++ if (*(args[arg+4])) {
|
|
187
|
++ logsrv->minlvl = get_log_level(args[arg+4]);
|
|
188
|
+ if (logsrv->minlvl < 0) {
|
|
189
|
+- Alert("parsing [%s:%d] : unknown optional minimum log level '%s'\n", file, linenum, args[4]);
|
|
190
|
++ Alert("parsing [%s:%d] : unknown optional minimum log level '%s'\n", file, linenum, args[arg+4]);
|
|
191
|
+ err_code |= ERR_ALERT | ERR_FATAL;
|
|
192
|
+ logsrv->minlvl = 0;
|
|
193
|
+ }
|
|
194
|
+@@ -4791,22 +4815,46 @@ stats_error_parsing:
|
|
195
|
+ else if (*(args[1]) && *(args[2])) {
|
|
196
|
+ struct sockaddr_storage *sk;
|
|
197
|
+ int port1, port2;
|
|
198
|
++ int arg = 0;
|
|
199
|
++ int len = 0;
|
|
200
|
+
|
|
201
|
+ logsrv = calloc(1, sizeof(struct logsrv));
|
|
202
|
+
|
|
203
|
+- logsrv->facility = get_log_facility(args[2]);
|
|
204
|
++ /* just after the address, a length may be specified */
|
|
205
|
++ if (strcmp(args[arg+2], "len") == 0) {
|
|
206
|
++ len = atoi(args[arg+3]);
|
|
207
|
++ if (len < 80 || len > 65535) {
|
|
208
|
++ Alert("parsing [%s:%d] : invalid log length '%s', must be between 80 and 65535.\n",
|
|
209
|
++ file, linenum, args[arg+3]);
|
|
210
|
++ err_code |= ERR_ALERT | ERR_FATAL;
|
|
211
|
++ goto out;
|
|
212
|
++ }
|
|
213
|
++ logsrv->maxlen = len;
|
|
214
|
++
|
|
215
|
++ /* skip these two args */
|
|
216
|
++ arg += 2;
|
|
217
|
++ }
|
|
218
|
++ else
|
|
219
|
++ logsrv->maxlen = MAX_SYSLOG_LEN;
|
|
220
|
++
|
|
221
|
++ if (logsrv->maxlen > global.max_syslog_len) {
|
|
222
|
++ global.max_syslog_len = logsrv->maxlen;
|
|
223
|
++ logline = realloc(logline, global.max_syslog_len + 1);
|
|
224
|
++ }
|
|
225
|
++
|
|
226
|
++ logsrv->facility = get_log_facility(args[arg+2]);
|
|
227
|
+ if (logsrv->facility < 0) {
|
|
228
|
+- Alert("parsing [%s:%d] : unknown log facility '%s'\n", file, linenum, args[2]);
|
|
229
|
++ Alert("parsing [%s:%d] : unknown log facility '%s'\n", file, linenum, args[arg+2]);
|
|
230
|
+ err_code |= ERR_ALERT | ERR_FATAL;
|
|
231
|
+ goto out;
|
|
232
|
+
|
|
233
|
+ }
|
|
234
|
+
|
|
235
|
+ logsrv->level = 7; /* max syslog level = debug */
|
|
236
|
+- if (*(args[3])) {
|
|
237
|
+- logsrv->level = get_log_level(args[3]);
|
|
238
|
++ if (*(args[arg+3])) {
|
|
239
|
++ logsrv->level = get_log_level(args[arg+3]);
|
|
240
|
+ if (logsrv->level < 0) {
|
|
241
|
+- Alert("parsing [%s:%d] : unknown optional log level '%s'\n", file, linenum, args[3]);
|
|
242
|
++ Alert("parsing [%s:%d] : unknown optional log level '%s'\n", file, linenum, args[arg+3]);
|
|
243
|
+ err_code |= ERR_ALERT | ERR_FATAL;
|
|
244
|
+ goto out;
|
|
245
|
+
|
|
246
|
+@@ -4814,10 +4862,10 @@ stats_error_parsing:
|
|
247
|
+ }
|
|
248
|
+
|
|
249
|
+ logsrv->minlvl = 0; /* limit syslog level to this level (emerg) */
|
|
250
|
+- if (*(args[4])) {
|
|
251
|
+- logsrv->minlvl = get_log_level(args[4]);
|
|
252
|
++ if (*(args[arg+4])) {
|
|
253
|
++ logsrv->minlvl = get_log_level(args[arg+4]);
|
|
254
|
+ if (logsrv->minlvl < 0) {
|
|
255
|
+- Alert("parsing [%s:%d] : unknown optional minimum log level '%s'\n", file, linenum, args[4]);
|
|
256
|
++ Alert("parsing [%s:%d] : unknown optional minimum log level '%s'\n", file, linenum, args[arg+4]);
|
|
257
|
+ err_code |= ERR_ALERT | ERR_FATAL;
|
|
258
|
+ goto out;
|
|
259
|
+
|
|
260
|
+diff --git a/src/log.c b/src/log.c
|
|
261
|
+index 114ab7b..3e3acb4 100644
|
|
262
|
+--- a/src/log.c
|
|
263
|
++++ b/src/log.c
|
|
264
|
+@@ -146,7 +146,7 @@ char *log_format = NULL;
|
|
265
|
+ /* This is a global syslog line, common to all outgoing messages. It begins
|
|
266
|
+ * with the syslog tag and the date that are updated by update_log_hdr().
|
|
267
|
+ */
|
|
268
|
+-static char logline[MAX_SYSLOG_LEN];
|
|
269
|
++char *logline = NULL;
|
|
270
|
+
|
|
271
|
+ struct logformat_var_args {
|
|
272
|
+ char *name;
|
|
273
|
+@@ -736,7 +736,7 @@ static char *update_log_hdr()
|
|
274
|
+ tvsec = date.tv_sec;
|
|
275
|
+ get_localtime(tvsec, &tm);
|
|
276
|
+
|
|
277
|
+- hdr_len = snprintf(logline, MAX_SYSLOG_LEN,
|
|
278
|
++ hdr_len = snprintf(logline, global.max_syslog_len,
|
|
279
|
+ "<<<<>%s %2d %02d:%02d:%02d %s%s[%d]: ",
|
|
280
|
+ monthname[tm.tm_mon],
|
|
281
|
+ tm.tm_mday, tm.tm_hour, tm.tm_min, tm.tm_sec,
|
|
282
|
+@@ -746,8 +746,8 @@ static char *update_log_hdr()
|
|
283
|
+ * either -1 or the number of bytes that would be needed to store
|
|
284
|
+ * the total message. In both cases, we must adjust it.
|
|
285
|
+ */
|
|
286
|
+- if (hdr_len < 0 || hdr_len > MAX_SYSLOG_LEN)
|
|
287
|
+- hdr_len = MAX_SYSLOG_LEN;
|
|
288
|
++ if (hdr_len < 0 || hdr_len > global.max_syslog_len)
|
|
289
|
++ hdr_len = global.max_syslog_len;
|
|
290
|
+
|
|
291
|
+ dataptr = logline + hdr_len;
|
|
292
|
+ }
|
|
293
|
+@@ -772,9 +772,9 @@ void send_log(struct proxy *p, int level, const char *format, ...)
|
|
294
|
+ data_len = dataptr - logline;
|
|
295
|
+
|
|
296
|
+ va_start(argp, format);
|
|
297
|
+- data_len += vsnprintf(dataptr, logline + sizeof(logline) - dataptr, format, argp);
|
|
298
|
+- if (data_len < 0 || data_len > MAX_SYSLOG_LEN)
|
|
299
|
+- data_len = MAX_SYSLOG_LEN;
|
|
300
|
++ data_len += vsnprintf(dataptr, logline + global.max_syslog_len - dataptr, format, argp);
|
|
301
|
++ if (data_len < 0 || data_len > global.max_syslog_len)
|
|
302
|
++ data_len = global.max_syslog_len;
|
|
303
|
+ va_end(argp);
|
|
304
|
+
|
|
305
|
+ __send_log(p, level, logline, data_len);
|
|
306
|
+@@ -811,8 +811,6 @@ void __send_log(struct proxy *p, int level, char *message, size_t size)
|
|
307
|
+ if (!logsrvs)
|
|
308
|
+ return;
|
|
309
|
+
|
|
310
|
+- message[size - 1] = '\n';
|
|
311
|
+-
|
|
312
|
+ /* Send log messages to syslog server. */
|
|
313
|
+ nblogger = 0;
|
|
314
|
+ list_for_each_entry(tmp, logsrvs, list) {
|
|
315
|
+@@ -820,6 +818,8 @@ void __send_log(struct proxy *p, int level, char *message, size_t size)
|
|
316
|
+ int *plogfd = logsrv->addr.ss_family == AF_UNIX ?
|
|
317
|
+ &logfdunix : &logfdinet;
|
|
318
|
+ int sent;
|
|
319
|
++ int max;
|
|
320
|
++ char backup;
|
|
321
|
+
|
|
322
|
+ nblogger++;
|
|
323
|
+
|
|
324
|
+@@ -858,9 +858,23 @@ void __send_log(struct proxy *p, int level, char *message, size_t size)
|
|
325
|
+ } while (fac_level && log_ptr > dataptr);
|
|
326
|
+ *log_ptr = '<';
|
|
327
|
+
|
|
328
|
+- sent = sendto(*plogfd, log_ptr, size - (log_ptr - dataptr),
|
|
329
|
++ max = size - (log_ptr - dataptr);
|
|
330
|
++ if (max > logsrv->maxlen)
|
|
331
|
++ max = logsrv->maxlen;
|
|
332
|
++
|
|
333
|
++ /* insert a \n at the end of the message, but save what was
|
|
334
|
++ * there first because we could have different max lengths
|
|
335
|
++ * for different log targets.
|
|
336
|
++ */
|
|
337
|
++ backup = log_ptr[max - 1];
|
|
338
|
++ log_ptr[max - 1] = '\n';
|
|
339
|
++
|
|
340
|
++ sent = sendto(*plogfd, log_ptr, max,
|
|
341
|
+ MSG_DONTWAIT | MSG_NOSIGNAL,
|
|
342
|
+ (struct sockaddr *)&logsrv->addr, get_addr_len(&logsrv->addr));
|
|
343
|
++
|
|
344
|
++ log_ptr[max - 1] = backup;
|
|
345
|
++
|
|
346
|
+ if (sent < 0) {
|
|
347
|
+ Alert("sendto logger #%d failed: %s (errno=%d)\n",
|
|
348
|
+ nblogger, strerror(errno), errno);
|
|
349
|
+@@ -1604,7 +1618,7 @@ void sess_log(struct session *s)
|
|
350
|
+
|
|
351
|
+ tmplog = update_log_hdr();
|
|
352
|
+ size = tmplog - logline;
|
|
353
|
+- size += build_logline(s, tmplog, sizeof(logline) - size, &s->fe->logformat);
|
|
354
|
++ size += build_logline(s, tmplog, global.max_syslog_len - size, &s->fe->logformat);
|
|
355
|
+ if (size > 0) {
|
|
356
|
+ __send_log(s->fe, level, logline, size + 1);
|
|
357
|
+ s->logs.logwait = 0;
|
|
358
|
+--
|
|
359
|
+1.8.5.5
|
|
360
|
+
|