#include <signal.h>
#include <stdarg.h>
#include <stdio.h>
#include <unistd.h>
#include <time.h>
#include <string.h>
#include <stdlib.h>
#include <errno.h>
#include <sys/stat.h>
#include <syslog.h>
#include "asterisk.h"
#include "asterisk/logger.h"
#include "asterisk/lock.h"
#include "asterisk/options.h"
#include "asterisk/channel.h"
#include "asterisk/config.h"
#include "asterisk/term.h"
#include "asterisk/cli.h"
#include "asterisk/utils.h"
#include "asterisk/manager.h"
Go to the source code of this file.
Data Structures | |
struct | logchannel |
struct | msglist |
struct | verb |
Defines | |
#define | FORMATL "%-35.35s %-8.8s %-9.9s " |
#define | GETTID() getpid() |
#define | MAX_MSG_QUEUE 200 |
#define | SYSLOG_NAMES |
#define | SYSLOG_NLEVELS sizeof(syslog_level_map) / sizeof(int) |
Enumerations | |
enum | logtypes { LOGTYPE_SYSLOG, LOGTYPE_FILE, LOGTYPE_CONSOLE } |
Functions | |
void | ast_log (int level, const char *file, int line, const char *function, const char *fmt,...) |
static void | ast_log_vsyslog (int level, const char *file, int line, const char *function, const char *fmt, va_list args) |
AST_MUTEX_DEFINE_STATIC (loglock) | |
AST_MUTEX_DEFINE_STATIC (msglist_lock) | |
void | ast_queue_log (const char *queuename, const char *callid, const char *agent, const char *event, const char *fmt,...) |
int | ast_register_verbose (void(*v)(const char *string, int opos, int replacelast, int complete)) |
int | ast_unregister_verbose (void(*v)(const char *string, int opos, int replacelast, int complete)) |
void | ast_verbose (const char *fmt,...) |
int | ast_verbose_dmesg (void(*v)(const char *string, int opos, int replacelast, int complete)) |
void | close_logger (void) |
static int | handle_logger_reload (int fd, int argc, char *argv[]) |
static int | handle_logger_rotate (int fd, int argc, char *argv[]) |
static int | handle_logger_show_channels (int fd, int argc, char *argv[]) |
static int | handle_SIGXFSZ (int sig) |
int | init_logger (void) |
static void | init_logger_chain (void) |
static int | make_components (char *s, int lineno) |
static struct logchannel * | make_logchannel (char *channel, char *components, int lineno) |
int | reload_logger (int rotate) |
Variables | |
static int | colors [] |
static char | dateformat [256] = "%b %e %T" |
static FILE * | eventlog = NULL |
static int | filesize_reload_needed = 0 |
static int | global_logmask = -1 |
static char | hostname [MAXHOSTNAMELEN] |
static struct msglist * | last |
static char * | levels [] |
static struct msglist * | list |
static struct logchannel * | logchannels = NULL |
struct { | |
int alarm | |
char * description | |
unsigned int event_log:1 | |
enum queue_result id | |
char * name | |
char * name | |
char * name | |
rtpPayloadType payloadType | |
unsigned int queue_log:1 | |
char * subtype | |
char * text | |
char * type | |
int val | |
} | logfiles |
static char | logger_reload_help [] |
static char | logger_rotate_help [] |
static struct ast_cli_entry | logger_show_channels_cli |
static char | logger_show_channels_help [] |
static int | msgcnt = 0 |
static FILE * | qlog = NULL |
static struct ast_cli_entry | reload_logger_cli |
static struct ast_cli_entry | rotate_logger_cli |
static int | syslog_level_map [] |
static struct verb * | verboser |
Logging routines
Definition in file logger.c.
|
Referenced by handle_logger_show_channels(). |
|
Definition at line 75 of file logger.c. Referenced by ast_log(), and ast_log_vsyslog(). |
|
Definition at line 66 of file logger.c. Referenced by ast_verbose(). |
|
|
|
Definition at line 54 of file logger.c. Referenced by ast_log_vsyslog(). |
|
Definition at line 98 of file logger.c. 00098 { 00099 LOGTYPE_SYSLOG, 00100 LOGTYPE_FILE, 00101 LOGTYPE_CONSOLE, 00102 };
|
|
|
Definition at line 664 of file logger.c. References __LOG_DEBUG, __LOG_DTMF, __LOG_VERBOSE, GETTID, levels, s, syslog_level_map, SYSLOG_NLEVELS, and term_strip(). Referenced by ast_log(). 00665 { 00666 char buf[BUFSIZ]; 00667 char *s; 00668 00669 if (level >= SYSLOG_NLEVELS) { 00670 /* we are locked here, so cannot ast_log() */ 00671 fprintf(stderr, "ast_log_vsyslog called with bogus level: %d\n", level); 00672 return; 00673 } 00674 if (level == __LOG_VERBOSE) { 00675 snprintf(buf, sizeof(buf), "VERBOSE[%ld]: ", (long)GETTID()); 00676 level = __LOG_DEBUG; 00677 } else if (level == __LOG_DTMF) { 00678 snprintf(buf, sizeof(buf), "DTMF[%ld]: ", (long)GETTID()); 00679 level = __LOG_DEBUG; 00680 } else { 00681 snprintf(buf, sizeof(buf), "%s[%ld]: %s:%d in %s: ", 00682 levels[level], (long)GETTID(), file, line, function); 00683 } 00684 s = buf + strlen(buf); 00685 vsnprintf(s, sizeof(buf) - strlen(buf), fmt, args); 00686 term_strip(s, s, strlen(s) + 1); 00687 syslog(syslog_level_map[level], "%s", buf); 00688 }
|
|
|
|
|
|
Definition at line 367 of file logger.c. References ast_mutex_lock(), ast_mutex_unlock(), and qlog. Referenced by __login_exec(), action_agent_callback_login(), agent_hangup(), init_logger(), queue_exec(), and set_member_paused(). 00368 { 00369 va_list ap; 00370 ast_mutex_lock(&loglock); 00371 if (qlog) { 00372 va_start(ap, fmt); 00373 fprintf(qlog, "%ld|%s|%s|%s|%s|", (long)time(NULL), callid, queuename, agent, event); 00374 vfprintf(qlog, fmt, ap); 00375 fprintf(qlog, "\n"); 00376 va_end(ap); 00377 fflush(qlog); 00378 } 00379 ast_mutex_unlock(&loglock); 00380 }
|
|
Definition at line 932 of file logger.c. References ast_mutex_lock(), ast_mutex_unlock(), list, malloc, msglist::msg, verb::next, msglist::next, verb::verboser, and verboser. Referenced by ast_makesocket(), and show_console(). 00933 { 00934 struct msglist *m; 00935 struct verb *tmp; 00936 /* XXX Should be more flexible here, taking > 1 verboser XXX */ 00937 if ((tmp = malloc(sizeof (struct verb)))) { 00938 tmp->verboser = v; 00939 ast_mutex_lock(&msglist_lock); 00940 tmp->next = verboser; 00941 verboser = tmp; 00942 m = list; 00943 while(m) { 00944 /* Send all the existing entries that we have queued (i.e. they're likely to have missed) */ 00945 v(m->msg, 0, 0, 1); 00946 m = m->next; 00947 } 00948 ast_mutex_unlock(&msglist_lock); 00949 return 0; 00950 } 00951 return -1; 00952 }
|
|
Definition at line 954 of file logger.c. References ast_mutex_lock(), ast_mutex_unlock(), free, verb::next, verboser, and verb::verboser. Referenced by exit_now(). 00955 { 00956 int res = -1; 00957 struct verb *tmp, *tmpl=NULL; 00958 ast_mutex_lock(&msglist_lock); 00959 tmp = verboser; 00960 while(tmp) { 00961 if (tmp->verboser == v) { 00962 if (tmpl) 00963 tmpl->next = tmp->next; 00964 else 00965 verboser = tmp->next; 00966 free(tmp); 00967 break; 00968 } 00969 tmpl = tmp; 00970 tmp = tmp->next; 00971 } 00972 if (tmp) 00973 res = 0; 00974 ast_mutex_unlock(&msglist_lock); 00975 return res; 00976 }
|
|
|
Definition at line 918 of file logger.c. References ast_mutex_lock(), ast_mutex_unlock(), list, msglist::msg, and msglist::next. 00919 { 00920 struct msglist *m; 00921 ast_mutex_lock(&msglist_lock); 00922 m = list; 00923 while(m) { 00924 /* Send all the existing entries that we have queued (i.e. they're likely to have missed) */ 00925 v(m->msg, 0, 0, 1); 00926 m = m->next; 00927 } 00928 ast_mutex_unlock(&msglist_lock); 00929 return 0; 00930 }
|
|
Definition at line 644 of file logger.c. References ast_mutex_lock(), ast_mutex_unlock(), free, last, list, msglist::msg, msgcnt, and msglist::next. 00645 { 00646 struct msglist *m, *tmp; 00647 00648 ast_mutex_lock(&msglist_lock); 00649 m = list; 00650 while(m) { 00651 if (m->msg) { 00652 free(m->msg); 00653 } 00654 tmp = m->next; 00655 free(m); 00656 m = tmp; 00657 } 00658 list = last = NULL; 00659 msgcnt = 0; 00660 ast_mutex_unlock(&msglist_lock); 00661 return; 00662 }
|
|
Definition at line 503 of file logger.c. References ast_cli(), reload_logger(), RESULT_FAILURE, and RESULT_SUCCESS. 00504 { 00505 if(reload_logger(0)) { 00506 ast_cli(fd, "Failed to reload the logger\n"); 00507 return RESULT_FAILURE; 00508 } else 00509 return RESULT_SUCCESS; 00510 }
|
|
Definition at line 512 of file logger.c. References ast_cli(), reload_logger(), RESULT_FAILURE, and RESULT_SUCCESS. 00513 { 00514 if(reload_logger(1)) { 00515 ast_cli(fd, "Failed to reload the logger and rotate log files\n"); 00516 return RESULT_FAILURE; 00517 } else 00518 return RESULT_SUCCESS; 00519 }
|
|
Definition at line 523 of file logger.c. References __LOG_DEBUG, __LOG_DTMF, __LOG_ERROR, __LOG_EVENT, __LOG_NOTICE, __LOG_VERBOSE, __LOG_WARNING, ast_cli(), ast_mutex_lock(), ast_mutex_unlock(), logchannel::disabled, logchannel::filename, FORMATL, logchannels, logchannel::logmask, LOGTYPE_CONSOLE, LOGTYPE_SYSLOG, logchannel::next, RESULT_SUCCESS, and logchannel::type. 00524 { 00525 #define FORMATL "%-35.35s %-8.8s %-9.9s " 00526 struct logchannel *chan; 00527 00528 ast_mutex_lock(&loglock); 00529 00530 chan = logchannels; 00531 ast_cli(fd,FORMATL, "Channel", "Type", "Status"); 00532 ast_cli(fd, "Configuration\n"); 00533 ast_cli(fd,FORMATL, "-------", "----", "------"); 00534 ast_cli(fd, "-------------\n"); 00535 while (chan) { 00536 ast_cli(fd, FORMATL, chan->filename, chan->type==LOGTYPE_CONSOLE ? "Console" : (chan->type==LOGTYPE_SYSLOG ? "Syslog" : "File"), 00537 chan->disabled ? "Disabled" : "Enabled"); 00538 ast_cli(fd, " - "); 00539 if (chan->logmask & (1 << __LOG_DEBUG)) 00540 ast_cli(fd, "Debug "); 00541 if (chan->logmask & (1 << __LOG_DTMF)) 00542 ast_cli(fd, "DTMF "); 00543 if (chan->logmask & (1 << __LOG_VERBOSE)) 00544 ast_cli(fd, "Verbose "); 00545 if (chan->logmask & (1 << __LOG_WARNING)) 00546 ast_cli(fd, "Warning "); 00547 if (chan->logmask & (1 << __LOG_NOTICE)) 00548 ast_cli(fd, "Notice "); 00549 if (chan->logmask & (1 << __LOG_ERROR)) 00550 ast_cli(fd, "Error "); 00551 if (chan->logmask & (1 << __LOG_EVENT)) 00552 ast_cli(fd, "Event "); 00553 ast_cli(fd, "\n"); 00554 chan = chan->next; 00555 } 00556 ast_cli(fd, "\n"); 00557 00558 ast_mutex_unlock(&loglock); 00559 00560 return RESULT_SUCCESS; 00561 }
|
|
Definition at line 596 of file logger.c. References filesize_reload_needed. Referenced by init_logger(). 00597 { 00598 /* Indicate need to reload */ 00599 filesize_reload_needed = 1; 00600 return 0; 00601 }
|
|
Definition at line 603 of file logger.c. References ast_cli_register(), ast_log(), ast_queue_log(), ast_verbose(), EVENTLOG, eventlog, handle_SIGXFSZ(), init_logger_chain(), LOG_ERROR, LOG_EVENT, logfiles, logger_show_channels_cli, option_verbose, qlog, QUEUELOG, reload_logger_cli, and rotate_logger_cli. 00604 { 00605 char tmp[256]; 00606 int res = 0; 00607 00608 /* auto rotate if sig SIGXFSZ comes a-knockin */ 00609 (void) signal(SIGXFSZ,(void *) handle_SIGXFSZ); 00610 00611 /* register the relaod logger cli command */ 00612 ast_cli_register(&reload_logger_cli); 00613 ast_cli_register(&rotate_logger_cli); 00614 ast_cli_register(&logger_show_channels_cli); 00615 00616 mkdir((char *)ast_config_AST_LOG_DIR, 0755); 00617 00618 /* create log channels */ 00619 init_logger_chain(); 00620 00621 /* create the eventlog */ 00622 if (logfiles.event_log) { 00623 mkdir((char *)ast_config_AST_LOG_DIR, 0755); 00624 snprintf(tmp, sizeof(tmp), "%s/%s", (char *)ast_config_AST_LOG_DIR, EVENTLOG); 00625 eventlog = fopen((char *)tmp, "a"); 00626 if (eventlog) { 00627 ast_log(LOG_EVENT, "Started Asterisk Event Logger\n"); 00628 if (option_verbose) 00629 ast_verbose("Asterisk Event Logger Started %s\n",(char *)tmp); 00630 } else { 00631 ast_log(LOG_ERROR, "Unable to create event log: %s\n", strerror(errno)); 00632 res = -1; 00633 } 00634 } 00635 00636 if (logfiles.queue_log) { 00637 snprintf(tmp, sizeof(tmp), "%s/%s", (char *)ast_config_AST_LOG_DIR, QUEUELOG); 00638 qlog = fopen(tmp, "a"); 00639 ast_queue_log("NONE", "NONE", "NONE", "QUEUESTART", "%s", ""); 00640 } 00641 return res; 00642 }
|
|
Definition at line 289 of file logger.c. References ast_config_destroy(), ast_config_load(), ast_log(), ast_mutex_lock(), ast_mutex_unlock(), ast_true(), ast_variable_browse(), ast_variable_retrieve(), cfg, dateformat, free, global_logmask, hostname, LOG_WARNING, logchannels, logfiles, logchannel::logmask, LOGTYPE_CONSOLE, make_logchannel(), malloc, logchannel::next, s, logchannel::type, and var. Referenced by init_logger(). 00290 { 00291 struct logchannel *chan, *cur; 00292 struct ast_config *cfg; 00293 struct ast_variable *var; 00294 char *s; 00295 00296 /* delete our list of log channels */ 00297 ast_mutex_lock(&loglock); 00298 chan = logchannels; 00299 while (chan) { 00300 cur = chan->next; 00301 free(chan); 00302 chan = cur; 00303 } 00304 logchannels = NULL; 00305 ast_mutex_unlock(&loglock); 00306 00307 global_logmask = 0; 00308 errno = 0; 00309 /* close syslog */ 00310 closelog(); 00311 00312 cfg = ast_config_load("logger.conf"); 00313 00314 /* If no config file, we're fine, set default options. */ 00315 if (!cfg) { 00316 if (errno) 00317 fprintf(stderr, "Unable to open logger.conf: %s; default settings will be used.\n", strerror(errno)); 00318 else 00319 fprintf(stderr, "Errors detected in logger.conf: see above; default settings will be used.\n"); 00320 chan = malloc(sizeof(struct logchannel)); 00321 memset(chan, 0, sizeof(struct logchannel)); 00322 chan->type = LOGTYPE_CONSOLE; 00323 chan->logmask = 28; /*warning,notice,error */ 00324 chan->next = logchannels; 00325 logchannels = chan; 00326 global_logmask |= chan->logmask; 00327 return; 00328 } 00329 00330 ast_mutex_lock(&loglock); 00331 if ((s = ast_variable_retrieve(cfg, "general", "appendhostname"))) { 00332 if(ast_true(s)) { 00333 if(gethostname(hostname, sizeof(hostname)-1)) { 00334 ast_copy_string(hostname, "unknown", sizeof(hostname)); 00335 ast_log(LOG_WARNING, "What box has no hostname???\n"); 00336 } 00337 } else 00338 hostname[0] = '\0'; 00339 } else 00340 hostname[0] = '\0'; 00341 if ((s = ast_variable_retrieve(cfg, "general", "dateformat"))) { 00342 ast_copy_string(dateformat, s, sizeof(dateformat)); 00343 } else 00344 ast_copy_string(dateformat, "%b %e %T", sizeof(dateformat)); 00345 if ((s = ast_variable_retrieve(cfg, "general", "queue_log"))) { 00346 logfiles.queue_log = ast_true(s); 00347 } 00348 if ((s = ast_variable_retrieve(cfg, "general", "event_log"))) { 00349 logfiles.event_log = ast_true(s); 00350 } 00351 00352 var = ast_variable_browse(cfg, "logfiles"); 00353 while(var) { 00354 chan = make_logchannel(var->name, var->value, var->lineno); 00355 if (chan) { 00356 chan->next = logchannels; 00357 logchannels = chan; 00358 global_logmask |= chan->logmask; 00359 } 00360 var = var->next; 00361 } 00362 00363 ast_config_destroy(cfg); 00364 ast_mutex_unlock(&loglock); 00365 }
|
|
Definition at line 141 of file logger.c. References __LOG_DEBUG, __LOG_DTMF, __LOG_ERROR, __LOG_EVENT, __LOG_NOTICE, __LOG_VERBOSE, __LOG_WARNING, and strsep(). Referenced by make_logchannel(). 00142 { 00143 char *w; 00144 int res = 0; 00145 char *stringp=NULL; 00146 stringp=s; 00147 w = strsep(&stringp, ","); 00148 while(w) { 00149 while(*w && (*w < 33)) 00150 w++; 00151 if (!strcasecmp(w, "error")) 00152 res |= (1 << __LOG_ERROR); 00153 else if (!strcasecmp(w, "warning")) 00154 res |= (1 << __LOG_WARNING); 00155 else if (!strcasecmp(w, "notice")) 00156 res |= (1 << __LOG_NOTICE); 00157 else if (!strcasecmp(w, "event")) 00158 res |= (1 << __LOG_EVENT); 00159 else if (!strcasecmp(w, "debug")) 00160 res |= (1 << __LOG_DEBUG); 00161 else if (!strcasecmp(w, "verbose")) 00162 res |= (1 << __LOG_VERBOSE); 00163 else if (!strcasecmp(w, "dtmf")) 00164 res |= (1 << __LOG_DTMF); 00165 else { 00166 fprintf(stderr, "Logfile Warning: Unknown keyword '%s' at line %d of logger.conf\n", w, lineno); 00167 } 00168 w = strsep(&stringp, ","); 00169 } 00170 return res; 00171 }
|
|
Definition at line 173 of file logger.c. References ast_config_AST_LOG_DIR, ast_strlen_zero(), logchannel::facility, logchannel::filename, logchannel::fileptr, free, hostname, logchannel::logmask, LOGTYPE_CONSOLE, LOGTYPE_FILE, LOGTYPE_SYSLOG, make_components(), malloc, and logchannel::type. Referenced by init_logger_chain(). 00174 { 00175 struct logchannel *chan; 00176 char *facility; 00177 #ifndef SOLARIS 00178 CODE *cptr; 00179 #endif 00180 00181 if (ast_strlen_zero(channel)) 00182 return NULL; 00183 chan = malloc(sizeof(struct logchannel)); 00184 00185 if (!chan) /* Can't allocate memory */ 00186 return NULL; 00187 00188 memset(chan, 0, sizeof(struct logchannel)); 00189 if (!strcasecmp(channel, "console")) { 00190 chan->type = LOGTYPE_CONSOLE; 00191 } else if (!strncasecmp(channel, "syslog", 6)) { 00192 /* 00193 * syntax is: 00194 * syslog.facility => level,level,level 00195 */ 00196 facility = strchr(channel, '.'); 00197 if(!facility++ || !facility) { 00198 facility = "local0"; 00199 } 00200 00201 #ifndef SOLARIS 00202 /* 00203 * Walk through the list of facilitynames (defined in sys/syslog.h) 00204 * to see if we can find the one we have been given 00205 */ 00206 chan->facility = -1; 00207 cptr = facilitynames; 00208 while (cptr->c_name) { 00209 if (!strcasecmp(facility, cptr->c_name)) { 00210 chan->facility = cptr->c_val; 00211 break; 00212 } 00213 cptr++; 00214 } 00215 #else 00216 chan->facility = -1; 00217 if (!strcasecmp(facility, "kern")) 00218 chan->facility = LOG_KERN; 00219 else if (!strcasecmp(facility, "USER")) 00220 chan->facility = LOG_USER; 00221 else if (!strcasecmp(facility, "MAIL")) 00222 chan->facility = LOG_MAIL; 00223 else if (!strcasecmp(facility, "DAEMON")) 00224 chan->facility = LOG_DAEMON; 00225 else if (!strcasecmp(facility, "AUTH")) 00226 chan->facility = LOG_AUTH; 00227 else if (!strcasecmp(facility, "SYSLOG")) 00228 chan->facility = LOG_SYSLOG; 00229 else if (!strcasecmp(facility, "LPR")) 00230 chan->facility = LOG_LPR; 00231 else if (!strcasecmp(facility, "NEWS")) 00232 chan->facility = LOG_NEWS; 00233 else if (!strcasecmp(facility, "UUCP")) 00234 chan->facility = LOG_UUCP; 00235 else if (!strcasecmp(facility, "CRON")) 00236 chan->facility = LOG_CRON; 00237 else if (!strcasecmp(facility, "LOCAL0")) 00238 chan->facility = LOG_LOCAL0; 00239 else if (!strcasecmp(facility, "LOCAL1")) 00240 chan->facility = LOG_LOCAL1; 00241 else if (!strcasecmp(facility, "LOCAL2")) 00242 chan->facility = LOG_LOCAL2; 00243 else if (!strcasecmp(facility, "LOCAL3")) 00244 chan->facility = LOG_LOCAL3; 00245 else if (!strcasecmp(facility, "LOCAL4")) 00246 chan->facility = LOG_LOCAL4; 00247 else if (!strcasecmp(facility, "LOCAL5")) 00248 chan->facility = LOG_LOCAL5; 00249 else if (!strcasecmp(facility, "LOCAL6")) 00250 chan->facility = LOG_LOCAL6; 00251 else if (!strcasecmp(facility, "LOCAL7")) 00252 chan->facility = LOG_LOCAL7; 00253 #endif /* Solaris */ 00254 00255 if (0 > chan->facility) { 00256 fprintf(stderr, "Logger Warning: bad syslog facility in logger.conf\n"); 00257 free(chan); 00258 return NULL; 00259 } 00260 00261 chan->type = LOGTYPE_SYSLOG; 00262 snprintf(chan->filename, sizeof(chan->filename), "%s", channel); 00263 openlog("asterisk", LOG_PID, chan->facility); 00264 } else { 00265 if (channel[0] == '/') { 00266 if(!ast_strlen_zero(hostname)) { 00267 snprintf(chan->filename, sizeof(chan->filename) - 1,"%s.%s", channel, hostname); 00268 } else { 00269 ast_copy_string(chan->filename, channel, sizeof(chan->filename)); 00270 } 00271 } 00272 00273 if(!ast_strlen_zero(hostname)) { 00274 snprintf(chan->filename, sizeof(chan->filename), "%s/%s.%s",(char *)ast_config_AST_LOG_DIR, channel, hostname); 00275 } else { 00276 snprintf(chan->filename, sizeof(chan->filename), "%s/%s", (char *)ast_config_AST_LOG_DIR, channel); 00277 } 00278 chan->fileptr = fopen(chan->filename, "a"); 00279 if (!chan->fileptr) { 00280 /* Can't log here, since we're called with a lock */ 00281 fprintf(stderr, "Logger Warning: Unable to open log file '%s': %s\n", chan->filename, strerror(errno)); 00282 } 00283 chan->type = LOGTYPE_FILE; 00284 } 00285 chan->logmask = make_components(components, lineno); 00286 return chan; 00287 }
|
|
Definition at line 382 of file logger.c. References ast_config_AST_LOG_DIR, AST_CONFIG_MAX_PATH, ast_mutex_lock(), logchannel::disabled, EVENT_FLAG_SYSTEM, eventlog, logchannel::filename, logchannel::fileptr, logchannels, manager_event(), and qlog. Referenced by ast_log(), handle_logger_reload(), and handle_logger_rotate(). 00383 { 00384 char old[AST_CONFIG_MAX_PATH] = ""; 00385 char new[AST_CONFIG_MAX_PATH]; 00386 int event_rotate = rotate, queue_rotate = rotate; 00387 struct logchannel *f; 00388 FILE *myf; 00389 int x, res = 0; 00390 00391 ast_mutex_lock(&msglist_lock); /* to avoid deadlock */ 00392 ast_mutex_lock(&loglock); 00393 if (eventlog) 00394 fclose(eventlog); 00395 else 00396 event_rotate = 0; 00397 eventlog = NULL; 00398 00399 if (qlog) 00400 fclose(qlog); 00401 else 00402 queue_rotate = 0; 00403 qlog = NULL; 00404 00405 mkdir((char *)ast_config_AST_LOG_DIR, 0755); 00406 00407 f = logchannels; 00408 while(f) { 00409 if (f->disabled) { 00410 f->disabled = 0; /* Re-enable logging at reload */ 00411 manager_event(EVENT_FLAG_SYSTEM, "LogChannel", "Channel: %s\r\nEnabled: Yes\r\n", f->filename); 00412 } 00413 if (f->fileptr && (f->fileptr != stdout) && (f->fileptr != stderr)) { 00414 fclose(f->fileptr); /* Close file */ 00415 f->fileptr = NULL; 00416 if(rotate) { 00417 ast_copy_string(old, f->filename, sizeof(old)); 00418 00419 for(x=0;;x++) { 00420 snprintf(new, sizeof(new), "%s.%d", f->filename, x); 00421 myf = fopen((char *)new, "r"); 00422 if (myf) { 00423 fclose(myf); 00424 } else { 00425 break; 00426 } 00427 } 00428 00429 /* do it */ 00430 if (rename(old,new)) 00431 fprintf(stderr, "Unable to rename file '%s' to '%s'\n", old, new); 00432 } 00433 } 00434 f = f->next; 00435 } 00436 00437 filesize_reload_needed = 0; 00438 00439 init_logger_chain(); 00440 00441 if (logfiles.event_log) { 00442 snprintf(old, sizeof(old), "%s/%s", (char *)ast_config_AST_LOG_DIR, EVENTLOG); 00443 if (event_rotate) { 00444 for (x=0;;x++) { 00445 snprintf(new, sizeof(new), "%s/%s.%d", (char *)ast_config_AST_LOG_DIR, EVENTLOG,x); 00446 myf = fopen((char *)new, "r"); 00447 if (myf) /* File exists */ 00448 fclose(myf); 00449 else 00450 break; 00451 } 00452 00453 /* do it */ 00454 if (rename(old,new)) 00455 ast_log(LOG_ERROR, "Unable to rename file '%s' to '%s'\n", old, new); 00456 } 00457 00458 eventlog = fopen(old, "a"); 00459 if (eventlog) { 00460 ast_log(LOG_EVENT, "Restarted Asterisk Event Logger\n"); 00461 if (option_verbose) 00462 ast_verbose("Asterisk Event Logger restarted\n"); 00463 } else { 00464 ast_log(LOG_ERROR, "Unable to create event log: %s\n", strerror(errno)); 00465 res = -1; 00466 } 00467 } 00468 00469 if (logfiles.queue_log) { 00470 snprintf(old, sizeof(old), "%s/%s", (char *)ast_config_AST_LOG_DIR, QUEUELOG); 00471 if (queue_rotate) { 00472 for (x = 0; ; x++) { 00473 snprintf(new, sizeof(new), "%s/%s.%d", (char *)ast_config_AST_LOG_DIR, QUEUELOG, x); 00474 myf = fopen((char *)new, "r"); 00475 if (myf) /* File exists */ 00476 fclose(myf); 00477 else 00478 break; 00479 } 00480 00481 /* do it */ 00482 if (rename(old, new)) 00483 ast_log(LOG_ERROR, "Unable to rename file '%s' to '%s'\n", old, new); 00484 } 00485 00486 qlog = fopen(old, "a"); 00487 if (qlog) { 00488 ast_queue_log("NONE", "NONE", "NONE", "CONFIGRELOAD", "%s", ""); 00489 ast_log(LOG_EVENT, "Restarted Asterisk Queue Logger\n"); 00490 if (option_verbose) 00491 ast_verbose("Asterisk Queue Logger restarted\n"); 00492 } else { 00493 ast_log(LOG_ERROR, "Unable to create queue log: %s\n", strerror(errno)); 00494 res = -1; 00495 } 00496 } 00497 ast_mutex_unlock(&loglock); 00498 ast_mutex_unlock(&msglist_lock); 00499 00500 return res; 00501 }
|
|
Definition at line 131 of file logger.c. Referenced by ast_log(). |
|
Definition at line 79 of file logger.c. Referenced by ast_log(), ast_verbose(), and init_logger_chain(). |
|
|
|
Definition at line 118 of file logger.c. Referenced by ast_log(), init_logger(), and reload_logger(). |
|
Definition at line 83 of file logger.c. Referenced by ast_log(), and handle_SIGXFSZ(). |
|
Definition at line 84 of file logger.c. Referenced by ast_log(), and init_logger_chain(). |
|
Definition at line 96 of file logger.c. Referenced by ast_remotecontrol(), cli_prompt(), iax2_register(), init_logger_chain(), main(), make_logchannel(), netconsole(), set_destination(), and sip_register(). |
|
|
Definition at line 121 of file logger.c. Referenced by ast_log(), and ast_log_vsyslog(). |
|
|
|
Definition at line 114 of file logger.c. Referenced by ast_log(), handle_logger_show_channels(), init_logger_chain(), and reload_logger(). |
|
Referenced by ast_log(), init_logger(), and init_logger_chain(). |
|
Initial value: "Usage: logger reload\n" " Reloads the logger subsystem state. Use after restarting syslogd(8) if you are using syslog logging.\n" |
|
Initial value: "Usage: logger rotate\n" " Rotates and Reopens the log files.\n" |
|
Initial value: { { "logger", "show", "channels", NULL }, handle_logger_show_channels, "List configured log channels", logger_show_channels_help } Definition at line 581 of file logger.c. Referenced by init_logger(). |
|
Initial value: "Usage: logger show channels\n" " Show configured logger channels.\n" |
|
Definition at line 116 of file logger.c. Referenced by ast_verbose(), and close_logger(). |
|
Definition at line 119 of file logger.c. Referenced by ast_queue_log(), init_logger(), and reload_logger(). |
|
|
|
Initial value: { { "logger", "reload", NULL }, handle_logger_reload, "Reopens the log files", logger_reload_help } Definition at line 586 of file logger.c. Referenced by init_logger(). |
|
Initial value: { { "logger", "rotate", NULL }, handle_logger_rotate, "Rotates and reopens the log files", logger_rotate_help } Definition at line 591 of file logger.c. Referenced by init_logger(). |
|
Definition at line 44 of file logger.c. Referenced by ast_log_vsyslog(). |
|
Referenced by ast_register_verbose(), ast_unregister_verbose(), ast_verbose(), exit_now(), and show_console(). |