mirror of https://github.com/asterisk/asterisk
This has the pleasant side effect of cleaning up the header inclusion process in logger.c. git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@203508 65c4cc65-6c06-0410-ace0-fbb531ad65f3certified/1.8.6
parent
6fad61406c
commit
4535305772
@ -0,0 +1,71 @@
|
||||
/*
|
||||
* Asterisk -- An open source telephony toolkit.
|
||||
*
|
||||
* Copyright (C) 2009, malleable, LLC.
|
||||
*
|
||||
* Sean Bright <sean@malleable.com>
|
||||
*
|
||||
* See http://www.asterisk.org for more information about
|
||||
* the Asterisk project. Please do not directly contact
|
||||
* any of the maintainers of this project for assistance;
|
||||
* the project provides a web site, mailing lists and IRC
|
||||
* channels for your use.
|
||||
*
|
||||
* This program is free software, distributed under the terms of
|
||||
* the GNU General Public License Version 2. See the LICENSE file
|
||||
* at the top of the source tree.
|
||||
*/
|
||||
|
||||
/*!
|
||||
* \file syslog.h
|
||||
* \brief Syslog support functions for Asterisk logging.
|
||||
*/
|
||||
|
||||
#ifndef _ASTERISK_SYSLOG_H
|
||||
#define _ASTERISK_SYSLOG_H
|
||||
|
||||
#if defined(__cplusplus) || defined(c_plusplus)
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/*!
|
||||
* \since 1.6.3
|
||||
* \brief Maps a syslog facility name from a string to a syslog facility
|
||||
* constant.
|
||||
*
|
||||
* \param facility Facility name to map (i.e. "daemon")
|
||||
*
|
||||
* \retval syslog facility constant (i.e. LOG_DAEMON) if found
|
||||
* \retval -1 if facility is not found
|
||||
*/
|
||||
int ast_syslog_facility(const char *facility);
|
||||
|
||||
/*!
|
||||
* \since 1.6.3
|
||||
* \brief Maps a syslog priority name from a string to a syslog priority
|
||||
* constant.
|
||||
*
|
||||
* \param priority Priority name to map (i.e. "notice")
|
||||
*
|
||||
* \retval syslog priority constant (i.e. LOG_NOTICE) if found
|
||||
* \retval -1 if priority is not found
|
||||
*/
|
||||
int ast_syslog_priority(const char *priority);
|
||||
|
||||
/*!
|
||||
* \since 1.6.3
|
||||
* \brief Maps an Asterisk log level (i.e. LOG_ERROR) to a syslog priority
|
||||
* constant.
|
||||
*
|
||||
* \param level Asterisk log level constant (i.e. LOG_ERROR)
|
||||
*
|
||||
* \retval syslog priority constant (i.e. LOG_ERR) if found
|
||||
* \retval -1 if priority is not found
|
||||
*/
|
||||
int ast_syslog_priority_from_loglevel(int level);
|
||||
|
||||
#if defined(__cplusplus) || defined(c_plusplus)
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* _ASTERISK_SYSLOG_H */
|
||||
@ -0,0 +1,120 @@
|
||||
/*
|
||||
* Asterisk -- An open source telephony toolkit.
|
||||
*
|
||||
* Copyright (C) 2009, malleable, LLC.
|
||||
*
|
||||
* Sean Bright <sean@malleable.com>
|
||||
*
|
||||
* See http://www.asterisk.org for more information about
|
||||
* the Asterisk project. Please do not directly contact
|
||||
* any of the maintainers of this project for assistance;
|
||||
* the project provides a web site, mailing lists and IRC
|
||||
* channels for your use.
|
||||
*
|
||||
* This program is free software, distributed under the terms of
|
||||
* the GNU General Public License Version 2. See the LICENSE file
|
||||
* at the top of the source tree.
|
||||
*/
|
||||
|
||||
/*! \file
|
||||
*
|
||||
* \brief Asterisk Syslog Utility Functions
|
||||
* \author Sean Bright <sean@malleable.com>
|
||||
*/
|
||||
|
||||
#include "asterisk.h"
|
||||
#include "asterisk/utils.h"
|
||||
#include "asterisk/syslog.h"
|
||||
|
||||
ASTERISK_FILE_VERSION(__FILE__, "$Revision$")
|
||||
|
||||
#include <syslog.h>
|
||||
|
||||
int ast_syslog_facility(const char *facility)
|
||||
{
|
||||
if (!strcasecmp(facility, "KERN")) {
|
||||
return LOG_KERN;
|
||||
} else if (!strcasecmp(facility, "USER")) {
|
||||
return LOG_USER;
|
||||
} else if (!strcasecmp(facility, "MAIL")) {
|
||||
return LOG_MAIL;
|
||||
} else if (!strcasecmp(facility, "DAEMON")) {
|
||||
return LOG_DAEMON;
|
||||
} else if (!strcasecmp(facility, "AUTH")) {
|
||||
return LOG_AUTH;
|
||||
} else if (!strcasecmp(facility, "AUTHPRIV")) {
|
||||
return LOG_AUTHPRIV;
|
||||
} else if (!strcasecmp(facility, "SYSLOG")) {
|
||||
return LOG_SYSLOG;
|
||||
} else if (!strcasecmp(facility, "SECURITY")) {
|
||||
return LOG_AUTH;
|
||||
} else if (!strcasecmp(facility, "FTP")) {
|
||||
return LOG_FTP;
|
||||
} else if (!strcasecmp(facility, "LPR")) {
|
||||
return LOG_LPR;
|
||||
} else if (!strcasecmp(facility, "NEWS")) {
|
||||
return LOG_NEWS;
|
||||
} else if (!strcasecmp(facility, "UUCP")) {
|
||||
return LOG_UUCP;
|
||||
} else if (!strcasecmp(facility, "CRON")) {
|
||||
return LOG_CRON;
|
||||
} else if (!strcasecmp(facility, "LOCAL0")) {
|
||||
return LOG_LOCAL0;
|
||||
} else if (!strcasecmp(facility, "LOCAL1")) {
|
||||
return LOG_LOCAL1;
|
||||
} else if (!strcasecmp(facility, "LOCAL2")) {
|
||||
return LOG_LOCAL2;
|
||||
} else if (!strcasecmp(facility, "LOCAL3")) {
|
||||
return LOG_LOCAL3;
|
||||
} else if (!strcasecmp(facility, "LOCAL4")) {
|
||||
return LOG_LOCAL4;
|
||||
} else if (!strcasecmp(facility, "LOCAL5")) {
|
||||
return LOG_LOCAL5;
|
||||
} else if (!strcasecmp(facility, "LOCAL6")) {
|
||||
return LOG_LOCAL6;
|
||||
} else if (!strcasecmp(facility, "LOCAL7")) {
|
||||
return LOG_LOCAL7;
|
||||
}
|
||||
|
||||
return -1;
|
||||
}
|
||||
|
||||
int ast_syslog_priority(const char *priority)
|
||||
{
|
||||
if (!strcasecmp(priority, "ALERT")) {
|
||||
return LOG_ALERT;
|
||||
} else if (!strcasecmp(priority, "CRIT")) {
|
||||
return LOG_CRIT;
|
||||
} else if (!strcasecmp(priority, "DEBUG")) {
|
||||
return LOG_DEBUG;
|
||||
} else if (!strcasecmp(priority, "EMERG")) {
|
||||
return LOG_EMERG;
|
||||
} else if (!strcasecmp(priority, "ERR")) {
|
||||
return LOG_ERR;
|
||||
} else if (!strcasecmp(priority, "INFO")) {
|
||||
return LOG_INFO;
|
||||
} else if (!strcasecmp(priority, "NOTICE")) {
|
||||
return LOG_NOTICE;
|
||||
} else if (!strcasecmp(priority, "WARNING")) {
|
||||
return LOG_WARNING;
|
||||
}
|
||||
|
||||
return -1;
|
||||
}
|
||||
|
||||
static const int logger_level_to_syslog_map[] = {
|
||||
[__LOG_DEBUG] = LOG_DEBUG,
|
||||
[1] = LOG_INFO, /* Only kept for backwards compatibility */
|
||||
[__LOG_NOTICE] = LOG_NOTICE,
|
||||
[__LOG_WARNING] = LOG_WARNING,
|
||||
[__LOG_ERROR] = LOG_ERR,
|
||||
[__LOG_VERBOSE] = LOG_DEBUG,
|
||||
[__LOG_DTMF] = LOG_DEBUG,
|
||||
};
|
||||
|
||||
int ast_syslog_priority_from_loglevel(int level) {
|
||||
if (level < 0 || level >= ARRAY_LEN(logger_level_to_syslog_map)) {
|
||||
return -1;
|
||||
}
|
||||
return logger_level_to_syslog_map[level];
|
||||
}
|
||||
Loading…
Reference in new issue