mirror of
http://git.haproxy.org/git/haproxy.git/
synced 2025-04-01 22:48:25 +00:00
MEDIUM: logs: have global.log_send_hostname not contain the trailing space
This patch unifies global.log_send_hostname addition in the log header processing.
This commit is contained in:
parent
7ad3154cb8
commit
c8cfa7b4f3
@ -40,9 +40,6 @@ extern char default_tcp_log_format[];
|
||||
extern char default_http_log_format[];
|
||||
extern char clf_http_log_format[];
|
||||
|
||||
extern char default_host_tag_pid_log_format[];
|
||||
extern char rfc5424_host_tag_pid_log_format[];
|
||||
|
||||
extern char default_rfc5424_sd_log_format[];
|
||||
|
||||
extern char *logheader;
|
||||
@ -154,7 +151,7 @@ char *lf_port(char *dst, struct sockaddr *sockaddr, size_t size, struct logforma
|
||||
/*
|
||||
* Write hostname, log_tag and pid to the log string
|
||||
*/
|
||||
char *lf_host_tag_pid(char *dst, const char *format, const char *hostname, const char *log_tag, int pid, size_t size);
|
||||
char *lf_host_tag_pid(char *dst, int format, const char *hostname, const char *log_tag, int pid, size_t size);
|
||||
|
||||
|
||||
#endif /* _PROTO_LOG_H */
|
||||
|
@ -1647,7 +1647,6 @@ int cfg_parse_global(const char *file, int linenum, char **args, int kwm)
|
||||
}
|
||||
else if (!strcmp(args[0], "log-send-hostname")) { /* set the hostname in syslog header */
|
||||
char *name;
|
||||
int len;
|
||||
|
||||
if (global.log_send_hostname != NULL) {
|
||||
Alert("parsing [%s:%d] : '%s' already specified. Continuing.\n", file, linenum, args[0]);
|
||||
@ -1660,12 +1659,9 @@ int cfg_parse_global(const char *file, int linenum, char **args, int kwm)
|
||||
else
|
||||
name = hostname;
|
||||
|
||||
len = strlen(name);
|
||||
|
||||
/* We'll add a space after the name to respect the log format */
|
||||
free(global.log_send_hostname);
|
||||
global.log_send_hostname = malloc(len + 2);
|
||||
snprintf(global.log_send_hostname, len + 2, "%s ", name);
|
||||
global.log_send_hostname = strdup(name);
|
||||
}
|
||||
else if (!strcmp(args[0], "server-state-base")) { /* path base where HAProxy can find server state files */
|
||||
if (global.server_state_base != NULL) {
|
||||
@ -7897,23 +7893,19 @@ out_uri_auth_compat:
|
||||
list_for_each_entry(tmplogsrv, &curproxy->logsrvs, list) {
|
||||
char *hdr;
|
||||
struct chunk *htp;
|
||||
char *htp_fmt;
|
||||
char *host = global.log_send_hostname;
|
||||
|
||||
switch (tmplogsrv->format) {
|
||||
case LOG_FORMAT_RFC3164:
|
||||
hdr = logheader;
|
||||
htp = &curproxy->log_htp;
|
||||
htp_fmt = default_host_tag_pid_log_format;
|
||||
host = host ? host : "";
|
||||
break;
|
||||
|
||||
case LOG_FORMAT_RFC5424:
|
||||
hdr = logheader_rfc5424;
|
||||
htp = &curproxy->log_htp_rfc5424;
|
||||
htp_fmt = rfc5424_host_tag_pid_log_format;
|
||||
if (!curproxy->conf.logformat_sd_string)
|
||||
curproxy->conf.logformat_sd_string = default_rfc5424_sd_log_format;
|
||||
host = host ? host : hostname;
|
||||
break;
|
||||
|
||||
default:
|
||||
@ -7923,19 +7915,10 @@ out_uri_auth_compat:
|
||||
if (htp->str)
|
||||
continue;
|
||||
|
||||
if (!host) {
|
||||
int len = strlen(hostname);
|
||||
host = malloc(len + 2);
|
||||
snprintf(host, len + 2, "%s ", hostname);
|
||||
}
|
||||
|
||||
htp->str = lf_host_tag_pid(hdr, htp_fmt, host,
|
||||
htp->str = lf_host_tag_pid(hdr, tmplogsrv->format, host,
|
||||
curproxy->log_tag ? curproxy->log_tag : global.log_tag,
|
||||
pid, global.max_syslog_len);
|
||||
|
||||
if ((host != global.log_send_hostname) && strlen(host))
|
||||
free(host);
|
||||
|
||||
if ((htp->str == NULL) ||
|
||||
((htp->len = htp->str - hdr) >= global.max_syslog_len)) {
|
||||
Alert("Proxy '%s': cannot write a syslog header string that contains "
|
||||
|
22
src/log.c
22
src/log.c
@ -158,8 +158,8 @@ char *log_format = NULL;
|
||||
/* Common printf format strings for hostname, log_tag and pid used in all
|
||||
* outgoing syslog messages.
|
||||
*/
|
||||
char default_host_tag_pid_log_format[] = "%s%s[%d]: ";
|
||||
char rfc5424_host_tag_pid_log_format[] = "%s%s %d - ";
|
||||
static char default_host_tag_pid_log_format[] = "%s%s%s[%d]: ";
|
||||
static char rfc5424_host_tag_pid_log_format[] = "%s%s%s %d - ";
|
||||
|
||||
/* Default string used for structured-data part in RFC5424 formatted
|
||||
* syslog messages.
|
||||
@ -780,12 +780,26 @@ char *lf_port(char *dst, struct sockaddr *sockaddr, size_t size, struct logforma
|
||||
return ret;
|
||||
}
|
||||
|
||||
char *lf_host_tag_pid(char *dst, const char *format, const char *hostname, const char *log_tag, int pid, size_t size)
|
||||
char *lf_host_tag_pid(char *dst, int format, const char *hostname, const char *log_tag, int pid, size_t size)
|
||||
{
|
||||
char *ret = dst;
|
||||
char *fmt;
|
||||
int iret;
|
||||
|
||||
iret = snprintf(dst, size, format, hostname, log_tag, pid);
|
||||
switch (format) {
|
||||
case LOG_FORMAT_RFC3164:
|
||||
fmt = default_host_tag_pid_log_format;
|
||||
break;
|
||||
|
||||
case LOG_FORMAT_RFC5424:
|
||||
fmt = rfc5424_host_tag_pid_log_format;
|
||||
break;
|
||||
|
||||
default:
|
||||
return NULL;
|
||||
}
|
||||
|
||||
iret = snprintf(dst, size, fmt, hostname, strlen(hostname) ? " " : "", log_tag, pid);
|
||||
if (iret < 0 || iret > size)
|
||||
return NULL;
|
||||
ret += iret;
|
||||
|
Loading…
Reference in New Issue
Block a user