]> git.ipfire.org Git - thirdparty/asterisk.git/commitdiff
main/syslog: Allow dynamic logs, such as security events, to log to the syslog
authorMatthew Jordan <mjordan@digium.com>
Mon, 12 Jan 2015 18:00:24 +0000 (18:00 +0000)
committerMatthew Jordan <mjordan@digium.com>
Mon, 12 Jan 2015 18:00:24 +0000 (18:00 +0000)
The security event log uses a dynamic log level (SECURITY) that is registered
with the Asterisk logging core. Unfortunately, the syslog would ignore log
statements that had a dynamic log level associated with them. Because the
syslog cannot handle ad hoc dynamic log levels, this patch treats any dynamic
log entries sent to the syslog as logs with a level of NOTICE.

ASTERISK-20744 #close
Reported by: Michael Keuter
Tested by: Michael L. Young, Jacek Konieczny
patches:
  asterisk-20744-syslog-dynamic-logging_trunk.diff uploaded by Michael L. Young (license 5026)

git-svn-id: https://origsvn.digium.com/svn/asterisk/branches/11@430506 65c4cc65-6c06-0410-ace0-fbb531ad65f3

include/asterisk/syslog.h
main/syslog.c

index a0dc9e9cf4a3355757a402f26710c70820c65921..45d351a73194a9b231e99614d2fa0ddcf2b28942 100644 (file)
@@ -28,6 +28,8 @@
 extern "C" {
 #endif
 
+#define ASTNUMLOGLEVELS 32
+
 /*!
  * \since 1.8
  * \brief Maps a syslog facility name from a string to a syslog facility
index 9171be40b4f5a83cbe1b2a1831d2e8563c525b71..51da69a8c34aa9ee50e8c203bd76124985843996 100644 (file)
@@ -163,8 +163,16 @@ static const int logger_level_to_syslog_map[] = {
 
 int ast_syslog_priority_from_loglevel(int level)
 {
+       /* First 16 levels are reserved for system use.
+        * Default to using LOG_NOTICE for dynamic logging.
+        */
+       if (level >= 16 && level < ASTNUMLOGLEVELS) {
+               return LOG_NOTICE;
+       }
+
        if (level < 0 || level >= ARRAY_LEN(logger_level_to_syslog_map)) {
                return -1;
        }
+
        return logger_level_to_syslog_map[level];
 }