2009-06-25 23:54:03 +00:00
|
|
|
/*
|
|
|
|
* 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)
|
|
|
|
{
|
2009-06-26 00:21:09 +00:00
|
|
|
if (!strcasecmp(facility, "KERN")) {
|
2009-06-25 23:54:03 +00:00
|
|
|
return LOG_KERN;
|
2009-06-26 00:21:09 +00:00
|
|
|
} else if (!strcasecmp(facility, "USER")) {
|
2009-06-25 23:54:03 +00:00
|
|
|
return LOG_USER;
|
2009-06-26 00:21:09 +00:00
|
|
|
} else if (!strcasecmp(facility, "MAIL")) {
|
2009-06-25 23:54:03 +00:00
|
|
|
return LOG_MAIL;
|
2009-06-26 00:21:09 +00:00
|
|
|
} else if (!strcasecmp(facility, "DAEMON")) {
|
2009-06-25 23:54:03 +00:00
|
|
|
return LOG_DAEMON;
|
2009-06-26 00:21:09 +00:00
|
|
|
} else if (!strcasecmp(facility, "AUTH")) {
|
2009-06-25 23:54:03 +00:00
|
|
|
return LOG_AUTH;
|
|
|
|
} else if (!strcasecmp(facility, "AUTHPRIV")) {
|
|
|
|
return LOG_AUTHPRIV;
|
2009-06-26 00:21:09 +00:00
|
|
|
} else if (!strcasecmp(facility, "SYSLOG")) {
|
2009-06-25 23:54:03 +00:00
|
|
|
return LOG_SYSLOG;
|
|
|
|
} else if (!strcasecmp(facility, "SECURITY")) {
|
|
|
|
return LOG_AUTH;
|
|
|
|
} else if (!strcasecmp(facility, "FTP")) {
|
|
|
|
return LOG_FTP;
|
2009-06-26 00:21:09 +00:00
|
|
|
} else if (!strcasecmp(facility, "LPR")) {
|
2009-06-25 23:54:03 +00:00
|
|
|
return LOG_LPR;
|
2009-06-26 00:21:09 +00:00
|
|
|
} else if (!strcasecmp(facility, "NEWS")) {
|
2009-06-25 23:54:03 +00:00
|
|
|
return LOG_NEWS;
|
2009-06-26 00:21:09 +00:00
|
|
|
} else if (!strcasecmp(facility, "UUCP")) {
|
2009-06-25 23:54:03 +00:00
|
|
|
return LOG_UUCP;
|
2009-06-26 00:21:09 +00:00
|
|
|
} else if (!strcasecmp(facility, "CRON")) {
|
2009-06-25 23:54:03 +00:00
|
|
|
return LOG_CRON;
|
2009-06-26 00:21:09 +00:00
|
|
|
} else if (!strcasecmp(facility, "LOCAL0")) {
|
2009-06-25 23:54:03 +00:00
|
|
|
return LOG_LOCAL0;
|
2009-06-26 00:21:09 +00:00
|
|
|
} else if (!strcasecmp(facility, "LOCAL1")) {
|
2009-06-25 23:54:03 +00:00
|
|
|
return LOG_LOCAL1;
|
2009-06-26 00:21:09 +00:00
|
|
|
} else if (!strcasecmp(facility, "LOCAL2")) {
|
2009-06-25 23:54:03 +00:00
|
|
|
return LOG_LOCAL2;
|
2009-06-26 00:21:09 +00:00
|
|
|
} else if (!strcasecmp(facility, "LOCAL3")) {
|
2009-06-25 23:54:03 +00:00
|
|
|
return LOG_LOCAL3;
|
2009-06-26 00:21:09 +00:00
|
|
|
} else if (!strcasecmp(facility, "LOCAL4")) {
|
2009-06-25 23:54:03 +00:00
|
|
|
return LOG_LOCAL4;
|
2009-06-26 00:21:09 +00:00
|
|
|
} else if (!strcasecmp(facility, "LOCAL5")) {
|
2009-06-25 23:54:03 +00:00
|
|
|
return LOG_LOCAL5;
|
2009-06-26 00:21:09 +00:00
|
|
|
} else if (!strcasecmp(facility, "LOCAL6")) {
|
2009-06-25 23:54:03 +00:00
|
|
|
return LOG_LOCAL6;
|
2009-06-26 00:21:09 +00:00
|
|
|
} else if (!strcasecmp(facility, "LOCAL7")) {
|
2009-06-25 23:54:03 +00:00
|
|
|
return LOG_LOCAL7;
|
2009-06-26 00:21:09 +00:00
|
|
|
}
|
2009-06-25 23:54:03 +00:00
|
|
|
|
2009-06-26 00:21:09 +00:00
|
|
|
return -1;
|
2009-06-25 23:54:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
int ast_syslog_priority(const char *priority)
|
|
|
|
{
|
2009-06-26 00:21:09 +00:00
|
|
|
if (!strcasecmp(priority, "ALERT")) {
|
2009-06-25 23:54:03 +00:00
|
|
|
return LOG_ALERT;
|
2009-06-26 00:21:09 +00:00
|
|
|
} else if (!strcasecmp(priority, "CRIT")) {
|
2009-06-25 23:54:03 +00:00
|
|
|
return LOG_CRIT;
|
2009-06-26 00:21:09 +00:00
|
|
|
} else if (!strcasecmp(priority, "DEBUG")) {
|
2009-06-25 23:54:03 +00:00
|
|
|
return LOG_DEBUG;
|
2009-06-26 00:21:09 +00:00
|
|
|
} else if (!strcasecmp(priority, "EMERG")) {
|
2009-06-25 23:54:03 +00:00
|
|
|
return LOG_EMERG;
|
2009-06-26 00:21:09 +00:00
|
|
|
} else if (!strcasecmp(priority, "ERR")) {
|
2009-06-25 23:54:03 +00:00
|
|
|
return LOG_ERR;
|
2009-06-26 00:21:09 +00:00
|
|
|
} else if (!strcasecmp(priority, "INFO")) {
|
2009-06-25 23:54:03 +00:00
|
|
|
return LOG_INFO;
|
2009-06-26 00:21:09 +00:00
|
|
|
} else if (!strcasecmp(priority, "NOTICE")) {
|
2009-06-25 23:54:03 +00:00
|
|
|
return LOG_NOTICE;
|
2009-06-26 00:21:09 +00:00
|
|
|
} else if (!strcasecmp(priority, "WARNING")) {
|
2009-06-25 23:54:03 +00:00
|
|
|
return LOG_WARNING;
|
2009-06-26 00:21:09 +00:00
|
|
|
}
|
2009-06-25 23:54:03 +00:00
|
|
|
|
2009-06-26 00:21:09 +00:00
|
|
|
return -1;
|
2009-06-25 23:54:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static const int logger_level_to_syslog_map[] = {
|
|
|
|
[__LOG_DEBUG] = LOG_DEBUG,
|
2009-06-26 00:21:09 +00:00
|
|
|
[1] = LOG_INFO, /* Only kept for backwards compatibility */
|
2009-06-25 23:54:03 +00:00
|
|
|
[__LOG_NOTICE] = LOG_NOTICE,
|
|
|
|
[__LOG_WARNING] = LOG_WARNING,
|
|
|
|
[__LOG_ERROR] = LOG_ERR,
|
|
|
|
[__LOG_VERBOSE] = LOG_DEBUG,
|
2009-06-26 00:21:09 +00:00
|
|
|
[__LOG_DTMF] = LOG_DEBUG,
|
2009-06-25 23:54:03 +00:00
|
|
|
};
|
|
|
|
|
2009-06-26 00:21:09 +00:00
|
|
|
int ast_syslog_priority_from_loglevel(int level)
|
|
|
|
{
|
2009-06-25 23:54:03 +00:00
|
|
|
if (level < 0 || level >= ARRAY_LEN(logger_level_to_syslog_map)) {
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
return logger_level_to_syslog_map[level];
|
|
|
|
}
|