MEDIUM: log: support a user-configurable max log line length

With all the goodies supported by logformat, people find that the limit
of 1024 chars for log lines is too short. Some servers do not support
larger lines and can simply drop them, so changing the default value is
not always the best choice.

This patch takes a different approach. Log line length is specified per
log server on the "log" line, with a value between 80 and 65535. That
way it's possibly to satisfy all needs, even with some fat local servers
and small remote ones.
(cherry picked from commit 18324f574f349d510622ff45635de899437a3a11)
diff --git a/src/log.c b/src/log.c
index 114ab7b..3e3acb4 100644
--- a/src/log.c
+++ b/src/log.c
@@ -146,7 +146,7 @@
 /* This is a global syslog line, common to all outgoing messages. It begins
  * with the syslog tag and the date that are updated by update_log_hdr().
  */
-static char logline[MAX_SYSLOG_LEN];
+char *logline = NULL;
 
 struct logformat_var_args {
 	char *name;
@@ -736,7 +736,7 @@
 		tvsec = date.tv_sec;
 		get_localtime(tvsec, &tm);
 
-		hdr_len = snprintf(logline, MAX_SYSLOG_LEN,
+		hdr_len = snprintf(logline, global.max_syslog_len,
 				   "<<<<>%s %2d %02d:%02d:%02d %s%s[%d]: ",
 				   monthname[tm.tm_mon],
 				   tm.tm_mday, tm.tm_hour, tm.tm_min, tm.tm_sec,
@@ -746,8 +746,8 @@
 		 * either -1 or the number of bytes that would be needed to store
 		 * the total message. In both cases, we must adjust it.
 		 */
-		if (hdr_len < 0 || hdr_len > MAX_SYSLOG_LEN)
-			hdr_len = MAX_SYSLOG_LEN;
+		if (hdr_len < 0 || hdr_len > global.max_syslog_len)
+			hdr_len = global.max_syslog_len;
 
 		dataptr = logline + hdr_len;
 	}
@@ -772,9 +772,9 @@
 	data_len = dataptr - logline;
 
 	va_start(argp, format);
-	data_len += vsnprintf(dataptr, logline + sizeof(logline) - dataptr, format, argp);
-	if (data_len < 0 || data_len > MAX_SYSLOG_LEN)
-		data_len =  MAX_SYSLOG_LEN;
+	data_len += vsnprintf(dataptr, logline + global.max_syslog_len - dataptr, format, argp);
+	if (data_len < 0 || data_len > global.max_syslog_len)
+		data_len = global.max_syslog_len;
 	va_end(argp);
 
 	__send_log(p, level, logline, data_len);
@@ -811,8 +811,6 @@
 	if (!logsrvs)
 		return;
 
-	message[size - 1] = '\n';
-
 	/* Send log messages to syslog server. */
 	nblogger = 0;
 	list_for_each_entry(tmp, logsrvs, list) {
@@ -820,6 +818,8 @@
 		int *plogfd = logsrv->addr.ss_family == AF_UNIX ?
 			&logfdunix : &logfdinet;
 		int sent;
+		int max;
+		char backup;
 
 		nblogger++;
 
@@ -858,9 +858,23 @@
 		} while (fac_level && log_ptr > dataptr);
 		*log_ptr = '<';
 
+		max = size - (log_ptr - dataptr);
+		if (max > logsrv->maxlen)
+			max = logsrv->maxlen;
+
+		/* insert a \n at the end of the message, but save what was
+		 * there first because we could have different max lengths
+		 * for different log targets.
+		 */
+		backup = log_ptr[max - 1];
+		log_ptr[max - 1] = '\n';
+
-		sent = sendto(*plogfd, log_ptr, size - (log_ptr - dataptr),
+		sent = sendto(*plogfd, log_ptr, max,
 			      MSG_DONTWAIT | MSG_NOSIGNAL,
 			      (struct sockaddr *)&logsrv->addr, get_addr_len(&logsrv->addr));
+
+		log_ptr[max - 1] = backup;
+
 		if (sent < 0) {
 			Alert("sendto logger #%d failed: %s (errno=%d)\n",
 				nblogger, strerror(errno), errno);
@@ -1604,7 +1618,7 @@
 
 	tmplog = update_log_hdr();
 	size = tmplog - logline;
-	size += build_logline(s, tmplog, sizeof(logline) - size, &s->fe->logformat);
+	size += build_logline(s, tmplog, global.max_syslog_len - size, &s->fe->logformat);
 	if (size > 0) {
 		__send_log(s->fe, level, logline, size + 1);
 		s->logs.logwait = 0;