Index: include/asterisk/logger.h =================================================================== --- include/asterisk/logger.h (revision 7427) +++ include/asterisk/logger.h (working copy) @@ -34,6 +34,7 @@ #endif #define EVENTLOG "event_log" +#define QUEUELOG "queue_log" #define DEBUG_M(a) { \ a; \ Index: logger.c =================================================================== --- logger.c (revision 7427) +++ logger.c (working copy) @@ -51,7 +51,7 @@ LOG_DEBUG }; -#define SYSLOG_NLEVELS 6 +#define SYSLOG_NLEVELS sizeof(syslog_level_map) / sizeof(int) #include "asterisk/logger.h" #include "asterisk/lock.h" @@ -116,6 +116,7 @@ static int msgcnt = 0; static FILE *eventlog = NULL; +static FILE *qlog = NULL; static char *levels[] = { "DEBUG", @@ -350,13 +351,10 @@ ast_mutex_unlock(&loglock); } -static FILE *qlog = NULL; -AST_MUTEX_DEFINE_STATIC(qloglock); - void ast_queue_log(const char *queuename, const char *callid, const char *agent, const char *event, const char *fmt, ...) { va_list ap; - ast_mutex_lock(&qloglock); + ast_mutex_lock(&loglock); if (qlog) { va_start(ap, fmt); fprintf(qlog, "%ld|%s|%s|%s|%s|", (long)time(NULL), callid, queuename, agent, event); @@ -365,68 +363,33 @@ va_end(ap); fflush(qlog); } - ast_mutex_unlock(&qloglock); + ast_mutex_unlock(&loglock); } -static void queue_log_init(void) -{ - char filename[256]; - int reloaded = 0; - - ast_mutex_lock(&qloglock); - if (qlog) { - reloaded = 1; - fclose(qlog); - qlog = NULL; - } - snprintf(filename, sizeof(filename), "%s/%s", (char *)ast_config_AST_LOG_DIR, "queue_log"); - if (logfiles.queue_log) { - qlog = fopen(filename, "a"); - } - ast_mutex_unlock(&qloglock); - if (reloaded) - ast_queue_log("NONE", "NONE", "NONE", "CONFIGRELOAD", "%s", ""); - else - ast_queue_log("NONE", "NONE", "NONE", "QUEUESTART", "%s", ""); -} - int reload_logger(int rotate) { char old[AST_CONFIG_MAX_PATH] = ""; char new[AST_CONFIG_MAX_PATH]; + int event_rotate = rotate, queue_rotate = rotate; struct logchannel *f; FILE *myf; - int x; + int x, res = 0; ast_mutex_lock(&loglock); if (eventlog) fclose(eventlog); else - rotate = 0; + event_rotate = 0; eventlog = NULL; + if (qlog) + fclose(qlog); + else + queue_rotate = 0; + qlog = NULL; + mkdir((char *)ast_config_AST_LOG_DIR, 0755); - snprintf(old, sizeof(old), "%s/%s", (char *)ast_config_AST_LOG_DIR, EVENTLOG); - if (logfiles.event_log) { - if (rotate) { - for (x=0;;x++) { - snprintf(new, sizeof(new), "%s/%s.%d", (char *)ast_config_AST_LOG_DIR, EVENTLOG,x); - myf = fopen((char *)new, "r"); - if (myf) /* File exists */ - fclose(myf); - else - break; - } - - /* do it */ - if (rename(old,new)) - fprintf(stderr, "Unable to rename file '%s' to '%s'\n", old, new); - } - - eventlog = fopen(old, "a"); - } - f = logchannels; while(f) { if (f->disabled) { @@ -457,24 +420,70 @@ f = f->next; } - ast_mutex_unlock(&loglock); - filesize_reload_needed = 0; - queue_log_init(); init_logger_chain(); if (logfiles.event_log) { + snprintf(old, sizeof(old), "%s/%s", (char *)ast_config_AST_LOG_DIR, EVENTLOG); + if (event_rotate) { + for (x=0;;x++) { + snprintf(new, sizeof(new), "%s/%s.%d", (char *)ast_config_AST_LOG_DIR, EVENTLOG,x); + myf = fopen((char *)new, "r"); + if (myf) /* File exists */ + fclose(myf); + else + break; + } + + /* do it */ + if (rename(old,new)) + ast_log(LOG_ERROR, "Unable to rename file '%s' to '%s'\n", old, new); + } + + eventlog = fopen(old, "a"); if (eventlog) { ast_log(LOG_EVENT, "Restarted Asterisk Event Logger\n"); if (option_verbose) ast_verbose("Asterisk Event Logger restarted\n"); - return 0; - } else + } else { ast_log(LOG_ERROR, "Unable to create event log: %s\n", strerror(errno)); - } else - return 0; - return -1; + res = -1; + } + } + + if (logfiles.queue_log) { + snprintf(old, sizeof(old), "%s/%s", (char *)ast_config_AST_LOG_DIR, QUEUELOG); + if (queue_rotate) { + for (x=0;;x++) { + snprintf(new, sizeof(new), "%s/%s.%d", (char *)ast_config_AST_LOG_DIR, QUEUELOG,x); + myf = fopen((char *)new, "r"); + if (myf) /* File exists */ + fclose(myf); + else + break; + } + + /* do it */ + if (rename(old,new)) + ast_log(LOG_ERROR, "Unable to rename file '%s' to '%s'\n", old, new); + } + + qlog = fopen(old, "a"); + if (qlog) { + ast_queue_log("NONE", "NONE", "NONE", "CONFIGRELOAD", "%s", ""); + ast_log(LOG_EVENT, "Restarted Asterisk Queue Logger\n"); + if (option_verbose) + ast_verbose("Asterisk Queue Logger restarted\n"); + } else { + ast_log(LOG_ERROR, "Unable to create queue log: %s\n", strerror(errno)); + res = -1; + } + } + ast_mutex_unlock(&loglock); + + + return res; } static int handle_logger_reload(int fd, int argc, char *argv[]) @@ -580,6 +589,7 @@ int init_logger(void) { char tmp[256]; + int res = 0; /* auto rotate if sig SIGXFSZ comes a-knockin */ (void) signal(SIGXFSZ,(void *) handle_SIGXFSZ); @@ -589,28 +599,31 @@ ast_cli_register(&rotate_logger_cli); ast_cli_register(&logger_show_channels_cli); - /* initialize queue logger */ - queue_log_init(); + mkdir((char *)ast_config_AST_LOG_DIR, 0755); /* create log channels */ init_logger_chain(); /* create the eventlog */ if (logfiles.event_log) { - mkdir((char *)ast_config_AST_LOG_DIR, 0755); snprintf(tmp, sizeof(tmp), "%s/%s", (char *)ast_config_AST_LOG_DIR, EVENTLOG); eventlog = fopen((char *)tmp, "a"); if (eventlog) { ast_log(LOG_EVENT, "Started Asterisk Event Logger\n"); if (option_verbose) ast_verbose("Asterisk Event Logger Started %s\n",(char *)tmp); - return 0; - } else + } else { ast_log(LOG_ERROR, "Unable to create event log: %s\n", strerror(errno)); - } else - return 0; + res = -1; + } + } - return -1; + if (logfiles.queue_log) { + snprintf(tmp, sizeof(tmp), "%s/%s", (char *)ast_config_AST_LOG_DIR, QUEUELOG); + qlog = fopen(tmp, "a"); + ast_queue_log("NONE", "NONE", "NONE", "QUEUESTART", "%s", ""); + } + return res; } void close_logger(void)