mirror of
https://github.com/asterisk/asterisk.git
synced 2025-09-19 03:08:45 +00:00
Merge Brian West's append hostname patch (bug #2372)
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@3725 65c4cc65-6c06-0410-ace0-fbb531ad65f3
This commit is contained in:
@@ -9,7 +9,10 @@
|
|||||||
; this example is the ISO 8601 date format (yyyy-mm-dd HH:MM:SS)
|
; this example is the ISO 8601 date format (yyyy-mm-dd HH:MM:SS)
|
||||||
; see strftime(3) Linux manual for format specifiers
|
; see strftime(3) Linux manual for format specifiers
|
||||||
;dateformat=%F %T
|
;dateformat=%F %T
|
||||||
|
;
|
||||||
|
; This appends the hostname to the name of the log files.
|
||||||
|
;appendhostname = yes
|
||||||
|
;
|
||||||
;
|
;
|
||||||
; For each file, specify what to log.
|
; For each file, specify what to log.
|
||||||
;
|
;
|
||||||
|
36
logger.c
36
logger.c
@@ -58,6 +58,8 @@ static struct msglist {
|
|||||||
struct msglist *next;
|
struct msglist *next;
|
||||||
} *list = NULL, *last = NULL;
|
} *list = NULL, *last = NULL;
|
||||||
|
|
||||||
|
static char hostname[256];
|
||||||
|
|
||||||
struct logchannel {
|
struct logchannel {
|
||||||
int logmask;
|
int logmask;
|
||||||
int facility; /* syslog */
|
int facility; /* syslog */
|
||||||
@@ -167,10 +169,19 @@ static struct logchannel *make_logchannel(char *channel, char *components, int l
|
|||||||
chan->syslog = 1;
|
chan->syslog = 1;
|
||||||
openlog("asterisk", LOG_PID, chan->facility);
|
openlog("asterisk", LOG_PID, chan->facility);
|
||||||
} else {
|
} else {
|
||||||
if (channel[0] == '/')
|
if (channel[0] == '/') {
|
||||||
strncpy(chan->filename, channel, sizeof(chan->filename) - 1);
|
if(!ast_strlen_zero(hostname)) {
|
||||||
else
|
snprintf(chan->filename, sizeof(chan->filename) - 1,"%s.%s", channel, hostname);
|
||||||
|
} else {
|
||||||
|
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 {
|
||||||
snprintf(chan->filename, sizeof(chan->filename), "%s/%s", (char *)ast_config_AST_LOG_DIR, channel);
|
snprintf(chan->filename, sizeof(chan->filename), "%s/%s", (char *)ast_config_AST_LOG_DIR, channel);
|
||||||
|
}
|
||||||
chan->fileptr = fopen(chan->filename, "a");
|
chan->fileptr = fopen(chan->filename, "a");
|
||||||
if (!chan->fileptr) {
|
if (!chan->fileptr) {
|
||||||
/* Can't log here, since we're called with a lock */
|
/* Can't log here, since we're called with a lock */
|
||||||
@@ -199,20 +210,31 @@ static void init_logger_chain(void)
|
|||||||
}
|
}
|
||||||
logchannels = NULL;
|
logchannels = NULL;
|
||||||
ast_mutex_unlock(&loglock);
|
ast_mutex_unlock(&loglock);
|
||||||
|
|
||||||
/* close syslog */
|
/* close syslog */
|
||||||
closelog();
|
closelog();
|
||||||
|
|
||||||
cfg = ast_load("logger.conf");
|
cfg = ast_load("logger.conf");
|
||||||
|
|
||||||
/* If no config file, we're fine */
|
/* If no config file, we're fine */
|
||||||
if (!cfg)
|
if (!cfg)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
ast_mutex_lock(&loglock);
|
ast_mutex_lock(&loglock);
|
||||||
|
if ((s = ast_variable_retrieve(cfg, "general", "appendhostname"))) {
|
||||||
|
if(ast_true(s)) {
|
||||||
|
if(gethostname(hostname, sizeof(hostname))) {
|
||||||
|
strncpy(hostname, "unknown", sizeof(hostname)-1);
|
||||||
|
ast_log(LOG_WARNING, "What box has no hostname???\n");
|
||||||
|
}
|
||||||
|
} else
|
||||||
|
hostname[0] = '\0';
|
||||||
|
} else
|
||||||
|
hostname[0] = '\0';
|
||||||
if ((s = ast_variable_retrieve(cfg, "general", "dateformat"))) {
|
if ((s = ast_variable_retrieve(cfg, "general", "dateformat"))) {
|
||||||
strncpy(dateformat, s, sizeof(dateformat) - 1);
|
strncpy(dateformat, s, sizeof(dateformat) - 1);
|
||||||
}
|
} else
|
||||||
|
strncpy(dateformat, "%b %e %T", sizeof(dateformat) - 1);
|
||||||
var = ast_variable_browse(cfg, "logfiles");
|
var = ast_variable_browse(cfg, "logfiles");
|
||||||
while(var) {
|
while(var) {
|
||||||
chan = make_logchannel(var->name, var->value, var->lineno);
|
chan = make_logchannel(var->name, var->value, var->lineno);
|
||||||
|
Reference in New Issue
Block a user