mirror of
http://git.haproxy.org/git/haproxy.git/
synced 2025-03-11 05:48:41 +00:00
[MINOR] log: ability to override the syslog tag
One of the requirements we have is to run multiple instances of haproxy on a single host; this is so that we can split the responsibilities (and change permissions) between product teams. An issue we ran up against is how we would distinguish between the logs generated by each instance. The solution we came up with (please let me know if there is a better way) is to override the application tag written to syslog. We can then configure syslog to write these to different files. I have attached a patch adding a global option 'log-tag' to override the default syslog tag 'haproxy' (actually defaults to argv[0]).
This commit is contained in:
parent
48a7e72c5d
commit
48936af9a2
@ -535,6 +535,12 @@ log-send-hostname [<string>]
|
||||
intermediate syslog server or for simply customizing the hostname printed in
|
||||
the logs.
|
||||
|
||||
log-tag <string>
|
||||
Sets the tag field in the syslog header to this string. It defaults to the
|
||||
program name as launched from the command line, which usually is "haproxy".
|
||||
Sometimes it can be useful to differentiate between multiple processes
|
||||
running on the same host.
|
||||
|
||||
nbproc <number>
|
||||
Creates <number> processes when going daemon. This requires the "daemon"
|
||||
mode. By default, only one process is created, which is the recommended mode
|
||||
|
@ -76,6 +76,7 @@ struct global {
|
||||
char *chroot;
|
||||
char *pidfile;
|
||||
char *node, *desc; /* node name & description */
|
||||
char *log_tag; /* name for syslog */
|
||||
int logfac1, logfac2;
|
||||
int loglev1, loglev2;
|
||||
int minlvl1, minlvl2;
|
||||
@ -108,7 +109,6 @@ struct global {
|
||||
};
|
||||
|
||||
extern struct global global;
|
||||
extern char *progname; /* program name */
|
||||
extern int pid; /* current process id */
|
||||
extern int relative_pid; /* process id starting at 1 */
|
||||
extern int actconn; /* # of active sessions */
|
||||
|
@ -988,6 +988,15 @@ int cfg_parse_global(const char *file, int linenum, char **args, int kwm)
|
||||
global.log_send_hostname = malloc(len + 2);
|
||||
snprintf(global.log_send_hostname, len + 2, "%s ", name);
|
||||
}
|
||||
else if (!strcmp(args[0], "log-tag")) { /* tag to report to syslog */
|
||||
if (*(args[1]) == 0) {
|
||||
Alert("parsing [%s:%d] : '%s' expects a tag for use in syslog.\n", file, linenum, args[0]);
|
||||
err_code |= ERR_ALERT | ERR_FATAL;
|
||||
goto out;
|
||||
}
|
||||
free(global.log_tag);
|
||||
global.log_tag = strdup(args[1]);
|
||||
}
|
||||
else if (!strcmp(args[0], "spread-checks")) { /* random time between checks (0-50) */
|
||||
if (global.spread_checks != 0) {
|
||||
Alert("parsing [%s:%d]: spread-checks already specified. Continuing.\n", file, linenum);
|
||||
|
@ -94,7 +94,6 @@
|
||||
|
||||
/* list of config files */
|
||||
static struct list cfg_cfgfiles = LIST_HEAD_INIT(cfg_cfgfiles);
|
||||
char *progname = NULL; /* program name */
|
||||
int pid; /* current process id */
|
||||
int relative_pid = 1; /* process id starting at 1 */
|
||||
|
||||
@ -352,6 +351,7 @@ void init(int argc, char **argv)
|
||||
char *cfg_pidfile = NULL;
|
||||
int err_code = 0;
|
||||
struct wordlist *wl;
|
||||
char *progname;
|
||||
|
||||
/* NB: POSIX does not make it mandatory for gethostname() to NULL-terminate
|
||||
* the string in case of truncation, and at least FreeBSD appears not to do
|
||||
@ -405,6 +405,9 @@ void init(int argc, char **argv)
|
||||
while ((tmp = strchr(progname, '/')) != NULL)
|
||||
progname = tmp + 1;
|
||||
|
||||
/* the process name is used for the logs only */
|
||||
global.log_tag = strdup(progname);
|
||||
|
||||
argc--; argv++;
|
||||
while (argc > 0) {
|
||||
char *flag;
|
||||
@ -868,6 +871,7 @@ void deinit(void)
|
||||
protocol_unbind_all();
|
||||
|
||||
free(global.log_send_hostname); global.log_send_hostname = NULL;
|
||||
free(global.log_tag); global.log_tag = NULL;
|
||||
free(global.chroot); global.chroot = NULL;
|
||||
free(global.pidfile); global.pidfile = NULL;
|
||||
free(global.node); global.node = NULL;
|
||||
|
@ -178,7 +178,7 @@ void send_log(struct proxy *p, int level, const char *message, ...)
|
||||
int nbloggers = 0;
|
||||
char *log_ptr;
|
||||
|
||||
if (level < 0 || progname == NULL || message == NULL)
|
||||
if (level < 0 || message == NULL)
|
||||
return;
|
||||
|
||||
if (unlikely(date.tv_sec != tvsec || dataptr == NULL)) {
|
||||
@ -193,7 +193,7 @@ void send_log(struct proxy *p, int level, const char *message, ...)
|
||||
monthname[tm.tm_mon],
|
||||
tm.tm_mday, tm.tm_hour, tm.tm_min, tm.tm_sec,
|
||||
global.log_send_hostname ? global.log_send_hostname : "",
|
||||
progname, pid);
|
||||
global.log_tag, pid);
|
||||
/* WARNING: depending upon implementations, snprintf may return
|
||||
* either -1 or the number of bytes that would be needed to store
|
||||
* the total message. In both cases, we must adjust it.
|
||||
|
Loading…
Reference in New Issue
Block a user