[asterisk-commits] core/logging: Fix logging to more than one syslog channel (asterisk[11])

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Tue Sep 22 13:20:44 CDT 2015


Matt Jordan has submitted this change and it was merged.

Change subject: core/logging: Fix logging to more than one syslog channel
......................................................................


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
---
M main/logger.c
1 file changed, 4 insertions(+), 3 deletions(-)

Approvals:
  Anonymous Coward #1000019: Verified
  Matt Jordan: Looks good to me, approved
  Joshua Colp: Looks good to me, but someone else must approve



diff --git a/main/logger.c b/main/logger.c
index 9f551af..795c85d 100644
--- a/main/logger.c
+++ b/main/logger.c
@@ -316,7 +316,6 @@
 
 		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 = "";
@@ -1019,7 +1018,7 @@
 	.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);
@@ -1036,6 +1035,8 @@
 		fprintf(stderr, "ast_log_vsyslog called with bogus level: %d\n", msg->level);
 		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);
@@ -1122,7 +1123,7 @@
 
 			/* 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];

-- 
To view, visit https://gerrit.asterisk.org/1293
To unsubscribe, visit https://gerrit.asterisk.org/settings

Gerrit-MessageType: merged
Gerrit-Change-Id: Ie2a2416bc00cce1b04e99ef40917c2011953ddd2
Gerrit-PatchSet: 1
Gerrit-Project: asterisk
Gerrit-Branch: 11
Gerrit-Owner: Matt Jordan <mjordan at digium.com>
Gerrit-Reviewer: Anonymous Coward #1000019
Gerrit-Reviewer: Joshua Colp <jcolp at digium.com>
Gerrit-Reviewer: Matt Jordan <mjordan at digium.com>



More information about the asterisk-commits mailing list