Skip to content
Snippets Groups Projects
Commit 20593164 authored by Kevin P. Fleming's avatar Kevin P. Fleming
Browse files

Put syslog facility/level name into filename field, so it will show in 'logger...

Put syslog facility/level name into filename field, so it will show in 'logger show channels' (bug #3916)


git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@5339 65c4cc65-6c06-0410-ace0-fbb531ad65f3
parent 66177049
No related branches found
No related tags found
No related merge requests found
...@@ -157,105 +157,107 @@ static struct logchannel *make_logchannel(char *channel, char *components, int l ...@@ -157,105 +157,107 @@ static struct logchannel *make_logchannel(char *channel, char *components, int l
return NULL; return NULL;
chan = malloc(sizeof(struct logchannel)); chan = malloc(sizeof(struct logchannel));
if (chan) { if (!chan) /* Can't allocate memory */
memset(chan, 0, sizeof(struct logchannel)); return NULL;
if (!strcasecmp(channel, "console")) {
chan->type = LOGTYPE_CONSOLE; memset(chan, 0, sizeof(struct logchannel));
} else if (!strncasecmp(channel, "syslog", 6)) { if (!strcasecmp(channel, "console")) {
/* chan->type = LOGTYPE_CONSOLE;
* syntax is: } else if (!strncasecmp(channel, "syslog", 6)) {
* syslog.facility => level,level,level /*
*/ * syntax is:
facility = strchr(channel, '.'); * syslog.facility => level,level,level
if(!facility++ || !facility) { */
facility = "local0"; facility = strchr(channel, '.');
} if(!facility++ || !facility) {
facility = "local0";
}
#ifndef SOLARIS #ifndef SOLARIS
/* /*
* Walk through the list of facilitynames (defined in sys/syslog.h) * Walk through the list of facilitynames (defined in sys/syslog.h)
* to see if we can find the one we have been given * to see if we can find the one we have been given
*/ */
chan->facility = -1; chan->facility = -1;
cptr = facilitynames; cptr = facilitynames;
while (cptr->c_name) { while (cptr->c_name) {
if (!strcasecmp(facility, cptr->c_name)) { if (!strcasecmp(facility, cptr->c_name)) {
chan->facility = cptr->c_val; chan->facility = cptr->c_val;
break; break;
}
cptr++;
} }
cptr++;
}
#else #else
chan->facility = -1; chan->facility = -1;
if (!strcasecmp(facility, "kern")) if (!strcasecmp(facility, "kern"))
chan->facility = LOG_KERN; chan->facility = LOG_KERN;
else if (!strcasecmp(facility, "USER")) else if (!strcasecmp(facility, "USER"))
chan->facility = LOG_USER; chan->facility = LOG_USER;
else if (!strcasecmp(facility, "MAIL")) else if (!strcasecmp(facility, "MAIL"))
chan->facility = LOG_MAIL; chan->facility = LOG_MAIL;
else if (!strcasecmp(facility, "DAEMON")) else if (!strcasecmp(facility, "DAEMON"))
chan->facility = LOG_DAEMON; chan->facility = LOG_DAEMON;
else if (!strcasecmp(facility, "AUTH")) else if (!strcasecmp(facility, "AUTH"))
chan->facility = LOG_AUTH; chan->facility = LOG_AUTH;
else if (!strcasecmp(facility, "SYSLOG")) else if (!strcasecmp(facility, "SYSLOG"))
chan->facility = LOG_SYSLOG; chan->facility = LOG_SYSLOG;
else if (!strcasecmp(facility, "LPR")) else if (!strcasecmp(facility, "LPR"))
chan->facility = LOG_LPR; chan->facility = LOG_LPR;
else if (!strcasecmp(facility, "NEWS")) else if (!strcasecmp(facility, "NEWS"))
chan->facility = LOG_NEWS; chan->facility = LOG_NEWS;
else if (!strcasecmp(facility, "UUCP")) else if (!strcasecmp(facility, "UUCP"))
chan->facility = LOG_UUCP; chan->facility = LOG_UUCP;
else if (!strcasecmp(facility, "CRON")) else if (!strcasecmp(facility, "CRON"))
chan->facility = LOG_CRON; chan->facility = LOG_CRON;
else if (!strcasecmp(facility, "LOCAL0")) else if (!strcasecmp(facility, "LOCAL0"))
chan->facility = LOG_LOCAL0; chan->facility = LOG_LOCAL0;
else if (!strcasecmp(facility, "LOCAL1")) else if (!strcasecmp(facility, "LOCAL1"))
chan->facility = LOG_LOCAL1; chan->facility = LOG_LOCAL1;
else if (!strcasecmp(facility, "LOCAL2")) else if (!strcasecmp(facility, "LOCAL2"))
chan->facility = LOG_LOCAL2; chan->facility = LOG_LOCAL2;
else if (!strcasecmp(facility, "LOCAL3")) else if (!strcasecmp(facility, "LOCAL3"))
chan->facility = LOG_LOCAL3; chan->facility = LOG_LOCAL3;
else if (!strcasecmp(facility, "LOCAL4")) else if (!strcasecmp(facility, "LOCAL4"))
chan->facility = LOG_LOCAL4; chan->facility = LOG_LOCAL4;
else if (!strcasecmp(facility, "LOCAL5")) else if (!strcasecmp(facility, "LOCAL5"))
chan->facility = LOG_LOCAL5; chan->facility = LOG_LOCAL5;
else if (!strcasecmp(facility, "LOCAL6")) else if (!strcasecmp(facility, "LOCAL6"))
chan->facility = LOG_LOCAL6; chan->facility = LOG_LOCAL6;
else if (!strcasecmp(facility, "LOCAL7")) else if (!strcasecmp(facility, "LOCAL7"))
chan->facility = LOG_LOCAL7; chan->facility = LOG_LOCAL7;
#endif /* Solaris */ #endif /* Solaris */
if (0 > chan->facility) { if (0 > chan->facility) {
fprintf(stderr, "Logger Warning: bad syslog facility in logger.conf\n"); fprintf(stderr, "Logger Warning: bad syslog facility in logger.conf\n");
free(chan); free(chan);
return NULL; return NULL;
} }
chan->type = LOGTYPE_SYSLOG; chan->type = LOGTYPE_SYSLOG;
openlog("asterisk", LOG_PID, chan->facility); snprintf(chan->filename, sizeof(chan->filename), "%s", channel);
} else { openlog("asterisk", LOG_PID, chan->facility);
if (channel[0] == '/') { } else {
if(!ast_strlen_zero(hostname)) { if (channel[0] == '/') {
snprintf(chan->filename, sizeof(chan->filename) - 1,"%s.%s", channel, hostname); if(!ast_strlen_zero(hostname)) {
} else { snprintf(chan->filename, sizeof(chan->filename) - 1,"%s.%s", channel, hostname);
strncpy(chan->filename, channel, sizeof(chan->filename) - 1);
}
}
if(!ast_strlen_zero(hostname)) {
snprintf(chan->filename, sizeof(chan->filename), "%s/%s.%s",(char *)ast_config_AST_LOG_DIR, channel, hostname);
} else { } else {
snprintf(chan->filename, sizeof(chan->filename), "%s/%s", (char *)ast_config_AST_LOG_DIR, channel); strncpy(chan->filename, channel, sizeof(chan->filename) - 1);
} }
chan->fileptr = fopen(chan->filename, "a"); }
if (!chan->fileptr) {
/* Can't log here, since we're called with a lock */ if(!ast_strlen_zero(hostname)) {
fprintf(stderr, "Logger Warning: Unable to open log file '%s': %s\n", chan->filename, strerror(errno)); snprintf(chan->filename, sizeof(chan->filename), "%s/%s.%s",(char *)ast_config_AST_LOG_DIR, channel, hostname);
} } else {
chan->type = LOGTYPE_FILE; snprintf(chan->filename, sizeof(chan->filename), "%s/%s", (char *)ast_config_AST_LOG_DIR, channel);
} }
chan->logmask = make_components(components, lineno); chan->fileptr = fopen(chan->filename, "a");
if (!chan->fileptr) {
/* Can't log here, since we're called with a lock */
fprintf(stderr, "Logger Warning: Unable to open log file '%s': %s\n", chan->filename, strerror(errno));
}
chan->type = LOGTYPE_FILE;
} }
chan->logmask = make_components(components, lineno);
return chan; return chan;
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment