diff options
author | Elazar Broad <elazar@thebroadfamily.com> | 2015-09-21 09:16:46 -0400 |
---|---|---|
committer | Matt Jordan <mjordan@digium.com> | 2015-09-22 07:40:57 -0500 |
commit | ec514ad64dbc0014525008977c8c74c2856c9d3a (patch) | |
tree | 74efae0cb9fe3a2cc80e12ae061618b6ce3c1742 | |
parent | 0ce661f0c03461a2ba217065efd19834f34cf2e1 (diff) |
core/logging: Fix logging to more than one syslog channel
Currently, Asterisk will log to the last configured syslog
channel in logger.conf. This is due to the fact that the
final call to openlog() supersedes all of the previous calls.
This commit removes the call to openlog() and passes the
facility to ast_log_vsyslog(), along with utilizing the
LOG_MAKEPRI macro to ensure that the message is routed to
the correct facility and with the correct priority.
ASTERISK-25407 #close
Reported by: Elazar Broad
Tested by: Elazar Broad
Change-Id: Ie2a2416bc00cce1b04e99ef40917c2011953ddd2
-rw-r--r-- | main/logger.c | 7 |
1 files changed, 4 insertions, 3 deletions
diff --git a/main/logger.c b/main/logger.c index 6e540cb52..eccf556db 100644 --- a/main/logger.c +++ b/main/logger.c @@ -323,7 +323,6 @@ static struct logchannel *make_logchannel(const char *channel, const char *compo chan->type = LOGTYPE_SYSLOG; ast_copy_string(chan->filename, channel, sizeof(chan->filename)); - openlog("asterisk", LOG_PID, chan->facility); } else { const char *log_dir_prefix = ""; const char *log_dir_separator = ""; @@ -1307,7 +1306,7 @@ static struct sigaction handle_SIGXFSZ = { .sa_flags = SA_RESTART, }; -static void ast_log_vsyslog(struct logmsg *msg) +static void ast_log_vsyslog(struct logmsg *msg, int facility) { char buf[BUFSIZ]; int syslog_level = ast_syslog_priority_from_loglevel(msg->level); @@ -1325,6 +1324,8 @@ static void ast_log_vsyslog(struct logmsg *msg) return; } + syslog_level = LOG_MAKEPRI(facility, syslog_level); + snprintf(buf, sizeof(buf), "%s[%d]%s: %s:%d in %s: %s", levels[msg->level], msg->lwp, call_identifier_str, msg->file, msg->line, msg->function, msg->message); @@ -1410,7 +1411,7 @@ static void logger_print_normal(struct logmsg *logmsg) /* Check syslog channels */ if (chan->type == LOGTYPE_SYSLOG && (chan->logmask & (1 << logmsg->level))) { - ast_log_vsyslog(logmsg); + ast_log_vsyslog(logmsg, chan->facility); /* Console channels */ } else if (chan->type == LOGTYPE_CONSOLE && (chan->logmask & (1 << logmsg->level))) { char linestr[128]; |