![]() |
Home page |
Mailing list |
Docs
Asterisk developer's documentation :: Codename Pineapple
logger.c File Reference
Logging routines
Definition in file logger.c.
#include "asterisk.h"
#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/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"
#include "asterisk/threadstorage.h"
#include "asterisk/strings.h"
Include dependency graph for logger.c:

Go to the source code of this file.
Data Structures | |
| struct | logchannel |
| struct | logmsg |
| struct | verb |
Defines | |
| #define | FORMATL "%-35.35s %-8.8s %-9.9s " |
| #define | GETTID() getpid() |
| #define | LOG_BUF_INIT_SIZE 256 |
| #define | SYSLOG_NAMES |
| #define | SYSLOG_NLEVELS sizeof(syslog_level_map) / sizeof(int) |
| #define | VERBOSE_BUF_INIT_SIZE 256 |
Enumerations | |
| enum | logmsgtypes { LOGMSG_NORMAL = 0, LOGMSG_VERBOSE } |
| enum | logtypes { LOGTYPE_SYSLOG, LOGTYPE_FILE, LOGTYPE_CONSOLE } |
Functions | |
| void | ast_backtrace (void) |
| static | AST_LIST_HEAD_STATIC (verbosers, verb) |
| static | AST_LIST_HEAD_STATIC (logmsgs, logmsg) |
| static | AST_LIST_HEAD_STATIC (logchannels, logchannel) |
| void | ast_log (int level, const char *file, int line, const char *function, const char *fmt,...) |
| send log messages to syslog and/or the console | |
| static void | ast_log_vsyslog (int level, const char *file, int line, const char *function, char *str) |
| 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)) |
| AST_THREADSTORAGE (log_buf) | |
| AST_THREADSTORAGE (verbose_buf) | |
| int | ast_unregister_verbose (void(*v)(const char *string)) |
| void | ast_verbose (const char *fmt,...) |
| 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[]) |
| CLI command to show logging system configuration. | |
| static int | handle_SIGXFSZ (int sig) |
| int | init_logger (void) |
| static void | init_logger_chain (void) |
| static void | logger_print_normal (struct logmsg *logmsg) |
| static void | logger_print_verbose (struct logmsg *logmsg) |
| static void * | logger_thread (void *data) |
| 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 struct ast_cli_entry | cli_logger [] |
| static int | close_logger_thread |
| static int | colors [] |
| static char | dateformat [256] = "%b %e %T" |
| static FILE * | eventlog |
| static int | filesize_reload_needed |
| static int | global_logmask = -1 |
| static char | hostname [MAXHOSTNAMELEN] |
| static char * | levels [] |
| static ast_cond_t | logcond |
| struct { | |
| int alarm | |
| const char * description | |
| unsigned int event_log:1 | |
| char * ext | |
| char * mtype | |
| char * name | |
| const char * name | |
| rtpPayloadType payloadType | |
| unsigned int queue_log:1 | |
| char * subtype | |
| char * type | |
| int val | |
| } | logfiles |
| static char | logger_reload_help [] |
| static char | logger_rotate_help [] |
| static char | logger_show_channels_help [] |
| static pthread_t | logthread = AST_PTHREADT_NULL |
| static FILE * | qlog |
| static char | queue_log_name [256] = QUEUELOG |
| static int | rotatetimestamp |
| static int | syslog_level_map [] |
|
|
Referenced by handle_logger_show_channels(). |
|
|
Definition at line 81 of file logger.c. Referenced by ast_log_vsyslog(), and logger_print_normal(). |
|
|
Definition at line 166 of file logger.c. Referenced by ast_log(). |
|
|
|
|
|
Definition at line 60 of file logger.c. Referenced by ast_log_vsyslog(). |
|
|
Definition at line 163 of file logger.c. Referenced by ast_verbose(). |
|
|
Definition at line 118 of file logger.c. 00118 { 00119 LOGMSG_NORMAL = 0, 00120 LOGMSG_VERBOSE, 00121 };
|
|
|
Definition at line 100 of file logger.c. 00100 { 00101 LOGTYPE_SYSLOG, 00102 LOGTYPE_FILE, 00103 LOGTYPE_CONSOLE, 00104 };
|
|
|
Definition at line 955 of file logger.c. References ast_calloc, ast_log(), free, and option_debug. 00956 { 00957 #ifdef STACK_BACKTRACES 00958 int count=0, i=0; 00959 void **addresses; 00960 char **strings; 00961 00962 if ((addresses = ast_calloc(MAX_BACKTRACE_FRAMES, sizeof(*addresses)))) { 00963 count = backtrace(addresses, MAX_BACKTRACE_FRAMES); 00964 if ((strings = backtrace_symbols(addresses, count))) { 00965 if (option_debug) 00966 ast_log(LOG_DEBUG, "Got %d backtrace record%c\n", count, count != 1 ? 's' : ' '); 00967 for (i=0; i < count ; i++) { 00968 if (option_debug) 00969 ast_log(LOG_DEBUG, "#%d: [%08X] %s\n", i, (unsigned int)addresses[i], strings[i]); 00970 } 00971 free(strings); 00972 } else { 00973 if (option_debug) 00974 ast_log(LOG_DEBUG, "Could not allocate memory for backtrace\n"); 00975 } 00976 free(addresses); 00977 } 00978 #else 00979 #ifdef Linux 00980 ast_log(LOG_WARNING, "Must compile with 'make dont-optimize' for stack backtraces\n"); 00981 #else 00982 ast_log(LOG_WARNING, "Inline stack backtraces are only available on the Linux platform.\n"); 00983 #endif 00984 #endif 00985 }
|
|
||||||||||||
|
|
|
||||||||||||
|
|
|
||||||||||||
|
|
|
||||||||||||||||||||||||||||
|
||||||||||||||||||||||||
|
Definition at line 619 of file logger.c. References __LOG_DEBUG, __LOG_DTMF, __LOG_VERBOSE, GETTID, levels, SYSLOG_NLEVELS, and term_strip(). Referenced by logger_print_normal(). 00620 { 00621 char buf[BUFSIZ]; 00622 00623 if (level >= SYSLOG_NLEVELS) { 00624 /* we are locked here, so cannot ast_log() */ 00625 fprintf(stderr, "ast_log_vsyslog called with bogus level: %d\n", level); 00626 return; 00627 } 00628 00629 if (level == __LOG_VERBOSE) { 00630 snprintf(buf, sizeof(buf), "VERBOSE[%ld]: %s", (long)GETTID(), str); 00631 level = __LOG_DEBUG; 00632 } else if (level == __LOG_DTMF) { 00633 snprintf(buf, sizeof(buf), "DTMF[%ld]: %s", (long)GETTID(), str); 00634 level = __LOG_DEBUG; 00635 } else { 00636 snprintf(buf, sizeof(buf), "%s[%ld]: %s:%d in %s: %s", 00637 levels[level], (long)GETTID(), file, line, function, str); 00638 } 00639 00640 term_strip(buf, buf, strlen(buf) + 1); 00641 syslog(syslog_level_map[level], "%s", buf); 00642 }
|
|
||||||||||||||||||||||||||||
|
Definition at line 382 of file logger.c. References AST_LIST_LOCK, AST_LIST_UNLOCK, and qlog. Referenced by __login_exec(), agent_logoff_maintenance(), and init_logger(). 00383 { 00384 va_list ap; 00385 AST_LIST_LOCK(&logchannels); 00386 if (qlog) { 00387 va_start(ap, fmt); 00388 fprintf(qlog, "%ld|%s|%s|%s|%s|", (long)time(NULL), callid, queuename, agent, event); 00389 vfprintf(qlog, fmt, ap); 00390 fprintf(qlog, "\n"); 00391 va_end(ap); 00392 fflush(qlog); 00393 } 00394 AST_LIST_UNLOCK(&logchannels); 00395 }
|
|
|
Definition at line 1040 of file logger.c. References AST_LIST_INSERT_HEAD, AST_LIST_LOCK, AST_LIST_UNLOCK, ast_malloc, and verb. Referenced by ast_makesocket(), and show_console(). 01041 { 01042 struct verb *verb; 01043 01044 if (!(verb = ast_malloc(sizeof(*verb)))) 01045 return -1; 01046 01047 verb->verboser = v; 01048 01049 AST_LIST_LOCK(&verbosers); 01050 AST_LIST_INSERT_HEAD(&verbosers, verb, list); 01051 AST_LIST_UNLOCK(&verbosers); 01052 01053 return 0; 01054 }
|
|
|
|
|
|
|
|
|
Definition at line 1056 of file logger.c. References AST_LIST_LOCK, AST_LIST_REMOVE_CURRENT, AST_LIST_TRAVERSE_SAFE_BEGIN, AST_LIST_TRAVERSE_SAFE_END, AST_LIST_UNLOCK, free, and verb::verboser. Referenced by exit_now(). 01057 { 01058 struct verb *cur; 01059 01060 AST_LIST_LOCK(&verbosers); 01061 AST_LIST_TRAVERSE_SAFE_BEGIN(&verbosers, cur, list) { 01062 if (cur->verboser == v) { 01063 AST_LIST_REMOVE_CURRENT(&verbosers, list); 01064 free(cur); 01065 break; 01066 } 01067 } 01068 AST_LIST_TRAVERSE_SAFE_END 01069 AST_LIST_UNLOCK(&verbosers); 01070 01071 return cur ? 0 : -1; 01072 }
|
|
||||||||||||
|
|
Provided by logger.c Definition at line 825 of file logger.c. References ast_cond_signal(), AST_LIST_LOCK, AST_LIST_TRAVERSE, AST_LIST_UNLOCK, close_logger_thread, eventlog, logchannel::fileptr, logcond, and qlog. 00826 { 00827 struct logchannel *f = NULL; 00828 00829 /* Stop logger thread */ 00830 AST_LIST_LOCK(&logmsgs); 00831 close_logger_thread = 1; 00832 ast_cond_signal(&logcond); 00833 AST_LIST_UNLOCK(&logmsgs); 00834 00835 AST_LIST_LOCK(&logchannels); 00836 00837 if (eventlog) { 00838 fclose(eventlog); 00839 eventlog = NULL; 00840 } 00841 00842 if (qlog) { 00843 fclose(qlog); 00844 qlog = NULL; 00845 } 00846 00847 AST_LIST_TRAVERSE(&logchannels, f, list) { 00848 if (f->fileptr && (f->fileptr != stdout) && (f->fileptr != stderr)) { 00849 fclose(f->fileptr); 00850 f->fileptr = NULL; 00851 } 00852 } 00853 00854 closelog(); /* syslog */ 00855 00856 AST_LIST_UNLOCK(&logchannels); 00857 00858 return; 00859 }
|
|
||||||||||||||||
|
Definition at line 524 of file logger.c. References ast_cli(), reload_logger(), RESULT_FAILURE, and RESULT_SUCCESS. 00525 { 00526 if (reload_logger(0)) { 00527 ast_cli(fd, "Failed to reload the logger\n"); 00528 return RESULT_FAILURE; 00529 } else 00530 return RESULT_SUCCESS; 00531 }
|
|
||||||||||||||||
|
Definition at line 533 of file logger.c. References ast_cli(), reload_logger(), RESULT_FAILURE, and RESULT_SUCCESS. 00534 { 00535 if (reload_logger(1)) { 00536 ast_cli(fd, "Failed to reload the logger and rotate log files\n"); 00537 return RESULT_FAILURE; 00538 } else 00539 return RESULT_SUCCESS; 00540 }
|
|
||||||||||||||||
|
CLI command to show logging system configuration.
Definition at line 543 of file logger.c. References __LOG_DEBUG, __LOG_DTMF, __LOG_ERROR, __LOG_EVENT, __LOG_NOTICE, __LOG_VERBOSE, __LOG_WARNING, ast_cli(), AST_LIST_LOCK, AST_LIST_TRAVERSE, AST_LIST_UNLOCK, logchannel::disabled, logchannel::filename, FORMATL, logchannel::logmask, LOGTYPE_CONSOLE, LOGTYPE_SYSLOG, RESULT_SUCCESS, and logchannel::type. 00544 { 00545 #define FORMATL "%-35.35s %-8.8s %-9.9s " 00546 struct logchannel *chan; 00547 00548 ast_cli(fd,FORMATL, "Channel", "Type", "Status"); 00549 ast_cli(fd, "Configuration\n"); 00550 ast_cli(fd,FORMATL, "-------", "----", "------"); 00551 ast_cli(fd, "-------------\n"); 00552 AST_LIST_LOCK(&logchannels); 00553 AST_LIST_TRAVERSE(&logchannels, chan, list) { 00554 ast_cli(fd, FORMATL, chan->filename, chan->type==LOGTYPE_CONSOLE ? "Console" : (chan->type==LOGTYPE_SYSLOG ? "Syslog" : "File"), 00555 chan->disabled ? "Disabled" : "Enabled"); 00556 ast_cli(fd, " - "); 00557 if (chan->logmask & (1 << __LOG_DEBUG)) 00558 ast_cli(fd, "Debug "); 00559 if (chan->logmask & (1 << __LOG_DTMF)) 00560 ast_cli(fd, "DTMF "); 00561 if (chan->logmask & (1 << __LOG_VERBOSE)) 00562 ast_cli(fd, "Verbose "); 00563 if (chan->logmask & (1 << __LOG_WARNING)) 00564 ast_cli(fd, "Warning "); 00565 if (chan->logmask & (1 << __LOG_NOTICE)) 00566 ast_cli(fd, "Notice "); 00567 if (chan->logmask & (1 << __LOG_ERROR)) 00568 ast_cli(fd, "Error "); 00569 if (chan->logmask & (1 << __LOG_EVENT)) 00570 ast_cli(fd, "Event "); 00571 ast_cli(fd, "\n"); 00572 } 00573 AST_LIST_UNLOCK(&logchannels); 00574 ast_cli(fd, "\n"); 00575 00576 return RESULT_SUCCESS; 00577 }
|
|
|
Definition at line 612 of file logger.c. Referenced by init_logger(). 00613 { 00614 /* Indicate need to reload */ 00615 filesize_reload_needed = 1; 00616 return 0; 00617 }
|
|
|
Provided by logger.c Definition at line 779 of file logger.c. References ast_cli_register_multiple(), ast_cond_destroy(), ast_cond_init(), ast_config_AST_LOG_DIR, ast_log(), ast_pthread_create, ast_queue_log(), ast_verbose(), cli_logger, EVENTLOG, eventlog, handle_SIGXFSZ(), init_logger_chain(), LOG_ERROR, LOG_EVENT, logcond, logfiles, logger_thread(), logthread, option_verbose, and qlog. 00780 { 00781 char tmp[256]; 00782 int res = 0; 00783 00784 /* auto rotate if sig SIGXFSZ comes a-knockin */ 00785 (void) signal(SIGXFSZ,(void *) handle_SIGXFSZ); 00786 00787 /* start logger thread */ 00788 ast_cond_init(&logcond, NULL); 00789 if (ast_pthread_create(&logthread, NULL, logger_thread, NULL) < 0) { 00790 ast_cond_destroy(&logcond); 00791 return -1; 00792 } 00793 00794 /* register the logger cli commands */ 00795 ast_cli_register_multiple(cli_logger, sizeof(cli_logger) / sizeof(struct ast_cli_entry)); 00796 00797 mkdir(ast_config_AST_LOG_DIR, 0755); 00798 00799 /* create log channels */ 00800 init_logger_chain(); 00801 00802 /* create the eventlog */ 00803 if (logfiles.event_log) { 00804 mkdir(ast_config_AST_LOG_DIR, 0755); 00805 snprintf(tmp, sizeof(tmp), "%s/%s", ast_config_AST_LOG_DIR, EVENTLOG); 00806 eventlog = fopen(tmp, "a"); 00807 if (eventlog) { 00808 ast_log(LOG_EVENT, "Started Asterisk Event Logger\n"); 00809 if (option_verbose) 00810 ast_verbose("Asterisk Event Logger Started %s\n", tmp); 00811 } else { 00812 ast_log(LOG_ERROR, "Unable to create event log: %s\n", strerror(errno)); 00813 res = -1; 00814 } 00815 } 00816 00817 if (logfiles.queue_log) { 00818 snprintf(tmp, sizeof(tmp), "%s/%s", ast_config_AST_LOG_DIR, queue_log_name); 00819 qlog = fopen(tmp, "a"); 00820 ast_queue_log("NONE", "NONE", "NONE", "QUEUESTART", "%s", ""); 00821 } 00822 return res; 00823 }
|
|
|
Definition at line 309 of file logger.c. References ast_calloc, ast_config_load(), AST_LIST_INSERT_HEAD, AST_LIST_LOCK, AST_LIST_REMOVE_HEAD, AST_LIST_UNLOCK, ast_log(), ast_true(), ast_variable_browse(), ast_variable_retrieve(), free, LOG_WARNING, logfiles, LOGTYPE_CONSOLE, make_logchannel(), s, and var. Referenced by init_logger(). 00310 { 00311 struct logchannel *chan; 00312 struct ast_config *cfg; 00313 struct ast_variable *var; 00314 const char *s; 00315 00316 /* delete our list of log channels */ 00317 AST_LIST_LOCK(&logchannels); 00318 while ((chan = AST_LIST_REMOVE_HEAD(&logchannels, list))) 00319 free(chan); 00320 AST_LIST_UNLOCK(&logchannels); 00321 00322 global_logmask = 0; 00323 errno = 0; 00324 /* close syslog */ 00325 closelog(); 00326 00327 cfg = ast_config_load("logger.conf"); 00328 00329 /* If no config file, we're fine, set default options. */ 00330 if (!cfg) { 00331 if (errno) 00332 fprintf(stderr, "Unable to open logger.conf: %s; default settings will be used.\n", strerror(errno)); 00333 else 00334 fprintf(stderr, "Errors detected in logger.conf: see above; default settings will be used.\n"); 00335 if (!(chan = ast_calloc(1, sizeof(*chan)))) 00336 return; 00337 chan->type = LOGTYPE_CONSOLE; 00338 chan->logmask = 28; /*warning,notice,error */ 00339 AST_LIST_LOCK(&logchannels); 00340 AST_LIST_INSERT_HEAD(&logchannels, chan, list); 00341 AST_LIST_UNLOCK(&logchannels); 00342 global_logmask |= chan->logmask; 00343 return; 00344 } 00345 00346 if ((s = ast_variable_retrieve(cfg, "general", "appendhostname"))) { 00347 if (ast_true(s)) { 00348 if (gethostname(hostname, sizeof(hostname) - 1)) { 00349 ast_copy_string(hostname, "unknown", sizeof(hostname)); 00350 ast_log(LOG_WARNING, "What box has no hostname???\n"); 00351 } 00352 } else 00353 hostname[0] = '\0'; 00354 } else 00355 hostname[0] = '\0'; 00356 if ((s = ast_variable_retrieve(cfg, "general", "dateformat"))) 00357 ast_copy_string(dateformat, s, sizeof(dateformat)); 00358 else 00359 ast_copy_string(dateformat, "%b %e %T", sizeof(dateformat)); 00360 if ((s = ast_variable_retrieve(cfg, "general", "queue_log"))) 00361 logfiles.queue_log = ast_true(s); 00362 if ((s = ast_variable_retrieve(cfg, "general", "event_log"))) 00363 logfiles.event_log = ast_true(s); 00364 if ((s = ast_variable_retrieve(cfg, "general", "queue_log_name"))) 00365 ast_copy_string(queue_log_name, s, sizeof(queue_log_name)); 00366 if ((s = ast_variable_retrieve(cfg, "general", "rotatetimestamp"))) 00367 rotatetimestamp = ast_true(s); 00368 00369 AST_LIST_LOCK(&logchannels); 00370 var = ast_variable_browse(cfg, "logfiles"); 00371 for (; var; var = var->next) { 00372 if (!(chan = make_logchannel(var->name, var->value, var->lineno))) 00373 continue; 00374 AST_LIST_INSERT_HEAD(&logchannels, chan, list); 00375 global_logmask |= chan->logmask; 00376 } 00377 AST_LIST_UNLOCK(&logchannels); 00378 00379 ast_config_destroy(cfg); 00380 }
|
|
|
Definition at line 645 of file logger.c. References __LOG_EVENT, __LOG_VERBOSE, ast_console_puts_mutable(), AST_LIST_EMPTY, AST_LIST_LOCK, AST_LIST_TRAVERSE, AST_LIST_UNLOCK, ast_log(), ast_log_vsyslog(), ast_strlen_zero(), ast_verbose(), COLOR_BRWHITE, colors, logmsg::date, logchannel::disabled, EVENT_FLAG_SYSTEM, eventlog, logmsg::file, logchannel::filename, logchannel::fileptr, logmsg::function, GETTID, logmsg::level, levels, logmsg::line, LOG_EVENT, logfiles, logchannel::logmask, LOGTYPE_CONSOLE, LOGTYPE_FILE, LOGTYPE_SYSLOG, manager_event, option_verbose, reload_logger(), term_color(), and logchannel::type. Referenced by ast_log(), and logger_thread(). 00646 { 00647 struct logchannel *chan = NULL; 00648 char buf[BUFSIZ]; 00649 00650 AST_LIST_LOCK(&logchannels); 00651 00652 if (logfiles.event_log && logmsg->level == __LOG_EVENT) { 00653 fprintf(eventlog, "%s asterisk[%ld]: %s", logmsg->date, (long)getpid(), logmsg->str); 00654 fflush(eventlog); 00655 AST_LIST_UNLOCK(&logchannels); 00656 return; 00657 } 00658 00659 if (!AST_LIST_EMPTY(&logchannels)) { 00660 AST_LIST_TRAVERSE(&logchannels, chan, list) { 00661 /* If the channel is disabled, then move on to the next one */ 00662 if (chan->disabled) 00663 continue; 00664 /* Check syslog channels */ 00665 if (chan->type == LOGTYPE_SYSLOG && (chan->logmask & (1 << logmsg->level))) { 00666 ast_log_vsyslog(logmsg->level, logmsg->file, logmsg->line, logmsg->function, logmsg->str); 00667 /* Console channels */ 00668 } else if (chan->type == LOGTYPE_CONSOLE && (chan->logmask & (1 << logmsg->level))) { 00669 char linestr[128]; 00670 char tmp1[80], tmp2[80], tmp3[80], tmp4[80]; 00671 00672 /* If the level is verbose, then skip it */ 00673 if (logmsg->level == __LOG_VERBOSE) 00674 continue; 00675 00676 /* Turn the numerical line number into a string */ 00677 snprintf(linestr, sizeof(linestr), "%d", logmsg->line); 00678 /* Build string to print out */ 00679 snprintf(buf, sizeof(buf), "[%s] %s[%ld]: %s:%s %s: %s", 00680 logmsg->date, 00681 term_color(tmp1, levels[logmsg->level], colors[logmsg->level], 0, sizeof(tmp1)), 00682 (long)GETTID(), 00683 term_color(tmp2, logmsg->file, COLOR_BRWHITE, 0, sizeof(tmp2)), 00684 term_color(tmp3, linestr, COLOR_BRWHITE, 0, sizeof(tmp3)), 00685 term_color(tmp4, logmsg->function, COLOR_BRWHITE, 0, sizeof(tmp4)), 00686 logmsg->str); 00687 /* Print out */ 00688 ast_console_puts_mutable(buf); 00689 /* File channels */ 00690 } else if (chan->type == LOGTYPE_FILE && (chan->logmask & (1 << logmsg->level))) { 00691 int res = 0; 00692 00693 /* If no file pointer exists, skip it */ 00694 if (!chan->fileptr) 00695 continue; 00696 00697 /* Print out to the file */ 00698 res = fprintf(chan->fileptr, "[%s] %s[%ld] %s: %s", 00699 logmsg->date, levels[logmsg->level], (long)GETTID(), logmsg->file, logmsg->str); 00700 if (res <= 0 && !ast_strlen_zero(logmsg->str)) { 00701 fprintf(stderr, "**** Asterisk Logging Error: ***********\n"); 00702 if (errno == ENOMEM || errno == ENOSPC) 00703 fprintf(stderr, "Asterisk logging error: Out of disk space, can't log to log file %s\n", chan->filename); 00704 else 00705 fprintf(stderr, "Logger Warning: Unable to write to log file '%s': %s (disabled)\n", chan->filename, strerror(errno)); 00706 manager_event(EVENT_FLAG_SYSTEM, "LogChannel", "Channel: %s\r\nEnabled: No\r\nReason: %d - %s\r\n", chan->filename, errno, strerror(errno)); 00707 chan->disabled = 1; 00708 } 00709 } 00710 } 00711 } else if (logmsg->level != __LOG_VERBOSE) { 00712 fputs(logmsg->str, stdout); 00713 } 00714 00715 AST_LIST_UNLOCK(&logchannels); 00716 00717 /* If we need to reload because of the file size, then do so */ 00718 if (filesize_reload_needed) { 00719 reload_logger(1); 00720 ast_log(LOG_EVENT, "Rotated Logs Per SIGXFSZ (Exceeded file size limit)\n"); 00721 if (option_verbose) 00722 ast_verbose("Rotated Logs Per SIGXFSZ (Exceeded file size limit)\n"); 00723 } 00724 00725 return; 00726 }
|
|
|
Definition at line 729 of file logger.c. References AST_LIST_LOCK, AST_LIST_TRAVERSE, AST_LIST_UNLOCK, and verb::verboser. Referenced by ast_verbose(), and logger_thread(). 00730 { 00731 struct verb *v = NULL; 00732 00733 /* Iterate through the list of verbosers and pass them the log message string */ 00734 AST_LIST_LOCK(&verbosers); 00735 AST_LIST_TRAVERSE(&verbosers, v, list) 00736 v->verboser(logmsg->str); 00737 AST_LIST_UNLOCK(&verbosers); 00738 00739 return; 00740 }
|
|
|
Definition at line 743 of file logger.c. References ast_cond_wait(), AST_LIST_EMPTY, AST_LIST_FIRST, AST_LIST_HEAD_INIT_NOLOCK, AST_LIST_LOCK, AST_LIST_NEXT, AST_LIST_UNLOCK, close_logger_thread, free, logcond, logger_print_normal(), logger_print_verbose(), LOGMSG_NORMAL, and LOGMSG_VERBOSE. Referenced by init_logger(). 00744 { 00745 struct logmsg *next = NULL, *msg = NULL; 00746 00747 for (;;) { 00748 /* We lock the message list, and see if any message exists... if not we wait on the condition to be signalled */ 00749 AST_LIST_LOCK(&logmsgs); 00750 if (AST_LIST_EMPTY(&logmsgs)) 00751 ast_cond_wait(&logcond, &logmsgs.lock); 00752 next = AST_LIST_FIRST(&logmsgs); 00753 AST_LIST_HEAD_INIT_NOLOCK(&logmsgs); 00754 AST_LIST_UNLOCK(&logmsgs); 00755 00756 /* If we should stop, then stop */ 00757 if (close_logger_thread) 00758 break; 00759 00760 /* Otherwise go through and process each message in the order added */ 00761 while ((msg = next)) { 00762 /* Get the next entry now so that we can free our current structure later */ 00763 next = AST_LIST_NEXT(msg, list); 00764 00765 /* Depending on the type, send it to the proper function */ 00766 if (msg->type == LOGMSG_NORMAL) 00767 logger_print_normal(msg); 00768 else if (msg->type == LOGMSG_VERBOSE) 00769 logger_print_verbose(msg); 00770 00771 /* Free the data since we are done */ 00772 free(msg); 00773 } 00774 } 00775 00776 return NULL; 00777 }
|
|
||||||||||||
|
Definition at line 168 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(). 00169 { 00170 char *w; 00171 int res = 0; 00172 char *stringp = s; 00173 00174 while ((w = strsep(&stringp, ","))) { 00175 w = ast_skip_blanks(w); 00176 if (!strcasecmp(w, "error")) 00177 res |= (1 << __LOG_ERROR); 00178 else if (!strcasecmp(w, "warning")) 00179 res |= (1 << __LOG_WARNING); 00180 else if (!strcasecmp(w, "notice")) 00181 res |= (1 << __LOG_NOTICE); 00182 else if (!strcasecmp(w, "event")) 00183 res |= (1 << __LOG_EVENT); 00184 else if (!strcasecmp(w, "debug")) 00185 res |= (1 << __LOG_DEBUG); 00186 else if (!strcasecmp(w, "verbose")) 00187 res |= (1 << __LOG_VERBOSE); 00188 else if (!strcasecmp(w, "dtmf")) 00189 res |= (1 << __LOG_DTMF); 00190 else { 00191 fprintf(stderr, "Logfile Warning: Unknown keyword '%s' at line %d of logger.conf\n", w, lineno); 00192 } 00193 } 00194 00195 return res; 00196 }
|
|
||||||||||||||||
|
Definition at line 198 of file logger.c. References ast_calloc, ast_config_AST_LOG_DIR, ast_strlen_zero(), logchannel::facility, free, LOGTYPE_CONSOLE, LOGTYPE_FILE, LOGTYPE_SYSLOG, and make_components(). Referenced by init_logger_chain(). 00199 { 00200 struct logchannel *chan; 00201 char *facility; 00202 #ifndef SOLARIS 00203 CODE *cptr; 00204 #endif 00205 00206 if (ast_strlen_zero(channel) || !(chan = ast_calloc(1, sizeof(*chan)))) 00207 return NULL; 00208 00209 if (!strcasecmp(channel, "console")) { 00210 chan->type = LOGTYPE_CONSOLE; 00211 } else if (!strncasecmp(channel, "syslog", 6)) { 00212 /* 00213 * syntax is: 00214 * syslog.facility => level,level,level 00215 */ 00216 facility = strchr(channel, '.'); 00217 if (!facility++ || !facility) { 00218 facility = "local0"; 00219 } 00220 00221 #ifndef SOLARIS 00222 /* 00223 * Walk through the list of facilitynames (defined in sys/syslog.h) 00224 * to see if we can find the one we have been given 00225 */ 00226 chan->facility = -1; 00227 cptr = facilitynames; 00228 while (cptr->c_name) { 00229 if (!strcasecmp(facility, cptr->c_name)) { 00230 chan->facility = cptr->c_val; 00231 break; 00232 } 00233 cptr++; 00234 } 00235 #else 00236 chan->facility = -1; 00237 if (!strcasecmp(facility, "kern")) 00238 chan->facility = LOG_KERN; 00239 else if (!strcasecmp(facility, "USER")) 00240 chan->facility = LOG_USER; 00241 else if (!strcasecmp(facility, "MAIL")) 00242 chan->facility = LOG_MAIL; 00243 else if (!strcasecmp(facility, "DAEMON")) 00244 chan->facility = LOG_DAEMON; 00245 else if (!strcasecmp(facility, "AUTH")) 00246 chan->facility = LOG_AUTH; 00247 else if (!strcasecmp(facility, "SYSLOG")) 00248 chan->facility = LOG_SYSLOG; 00249 else if (!strcasecmp(facility, "LPR")) 00250 chan->facility = LOG_LPR; 00251 else if (!strcasecmp(facility, "NEWS")) 00252 chan->facility = LOG_NEWS; 00253 else if (!strcasecmp(facility, "UUCP")) 00254 chan->facility = LOG_UUCP; 00255 else if (!strcasecmp(facility, "CRON")) 00256 chan->facility = LOG_CRON; 00257 else if (!strcasecmp(facility, "LOCAL0")) 00258 chan->facility = LOG_LOCAL0; 00259 else if (!strcasecmp(facility, "LOCAL1")) 00260 chan->facility = LOG_LOCAL1; 00261 else if (!strcasecmp(facility, "LOCAL2")) 00262 chan->facility = LOG_LOCAL2; 00263 else if (!strcasecmp(facility, "LOCAL3")) 00264 chan->facility = LOG_LOCAL3; 00265 else if (!strcasecmp(facility, "LOCAL4")) 00266 chan->facility = LOG_LOCAL4; 00267 else if (!strcasecmp(facility, "LOCAL5")) 00268 chan->facility = LOG_LOCAL5; 00269 else if (!strcasecmp(facility, "LOCAL6")) 00270 chan->facility = LOG_LOCAL6; 00271 else if (!strcasecmp(facility, "LOCAL7")) 00272 chan->facility = LOG_LOCAL7; 00273 #endif /* Solaris */ 00274 00275 if (0 > chan->facility) { 00276 fprintf(stderr, "Logger Warning: bad syslog facility in logger.conf\n"); 00277 free(chan); 00278 return NULL; 00279 } 00280 00281 chan->type = LOGTYPE_SYSLOG; 00282 snprintf(chan->filename, sizeof(chan->filename), "%s", channel); 00283 openlog("asterisk", LOG_PID, chan->facility); 00284 } else { 00285 if (channel[0] == '/') { 00286 if (!ast_strlen_zero(hostname)) { 00287 snprintf(chan->filename, sizeof(chan->filename) - 1,"%s.%s", channel, hostname); 00288 } else { 00289 ast_copy_string(chan->filename, channel, sizeof(chan->filename)); 00290 } 00291 } 00292 00293 if (!ast_strlen_zero(hostname)) { 00294 snprintf(chan->filename, sizeof(chan->filename), "%s/%s.%s", ast_config_AST_LOG_DIR, channel, hostname); 00295 } else { 00296 snprintf(chan->filename, sizeof(chan->filename), "%s/%s", ast_config_AST_LOG_DIR, channel); 00297 } 00298 chan->fileptr = fopen(chan->filename, "a"); 00299 if (!chan->fileptr) { 00300 /* Can't log here, since we're called with a lock */ 00301 fprintf(stderr, "Logger Warning: Unable to open log file '%s': %s\n", chan->filename, strerror(errno)); 00302 } 00303 chan->type = LOGTYPE_FILE; 00304 } 00305 chan->logmask = make_components(components, lineno); 00306 return chan; 00307 }
|
|
|
Provided by logger.c Definition at line 397 of file logger.c. References ast_config_AST_LOG_DIR, AST_LIST_LOCK, AST_LIST_TRAVERSE, logchannel::disabled, EVENT_FLAG_SYSTEM, eventlog, logchannel::filename, logchannel::fileptr, manager_event, and qlog. Referenced by handle_logger_reload(), handle_logger_rotate(), and logger_print_normal(). 00398 { 00399 char old[PATH_MAX] = ""; 00400 char new[PATH_MAX]; 00401 int event_rotate = rotate, queue_rotate = rotate; 00402 struct logchannel *f; 00403 FILE *myf; 00404 int x, res = 0; 00405 00406 AST_LIST_LOCK(&logchannels); 00407 00408 if (eventlog) 00409 fclose(eventlog); 00410 else 00411 event_rotate = 0; 00412 eventlog = NULL; 00413 00414 if (qlog) 00415 fclose(qlog); 00416 else 00417 queue_rotate = 0; 00418 qlog = NULL; 00419 00420 mkdir(ast_config_AST_LOG_DIR, 0755); 00421 00422 AST_LIST_TRAVERSE(&logchannels, f, list) { 00423 if (f->disabled) { 00424 f->disabled = 0; /* Re-enable logging at reload */ 00425 manager_event(EVENT_FLAG_SYSTEM, "LogChannel", "Channel: %s\r\nEnabled: Yes\r\n", f->filename); 00426 } 00427 if (f->fileptr && (f->fileptr != stdout) && (f->fileptr != stderr)) { 00428 fclose(f->fileptr); /* Close file */ 00429 f->fileptr = NULL; 00430 if (rotate) { 00431 ast_copy_string(old, f->filename, sizeof(old)); 00432 00433 if (!rotatetimestamp) { 00434 for (x = 0; ; x++) { 00435 snprintf(new, sizeof(new), "%s.%d", f->filename, x); 00436 myf = fopen(new, "r"); 00437 if (myf) 00438 fclose(myf); 00439 else 00440 break; 00441 } 00442 } else 00443 snprintf(new, sizeof(new), "%s.%ld", f->filename, (long)time(NULL)); 00444 00445 /* do it */ 00446 if (rename(old,new)) 00447 fprintf(stderr, "Unable to rename file '%s' to '%s'\n", old, new); 00448 } 00449 } 00450 } 00451 00452 filesize_reload_needed = 0; 00453 00454 init_logger_chain(); 00455 00456 if (logfiles.event_log) { 00457 snprintf(old, sizeof(old), "%s/%s", ast_config_AST_LOG_DIR, EVENTLOG); 00458 if (event_rotate) { 00459 if (!rotatetimestamp) { 00460 for (x=0;;x++) { 00461 snprintf(new, sizeof(new), "%s/%s.%d", ast_config_AST_LOG_DIR, EVENTLOG,x); 00462 myf = fopen(new, "r"); 00463 if (myf) /* File exists */ 00464 fclose(myf); 00465 else 00466 break; 00467 } 00468 } else 00469 snprintf(new, sizeof(new), "%s/%s.%ld", ast_config_AST_LOG_DIR, EVENTLOG,(long)time(NULL)); 00470 00471 /* do it */ 00472 if (rename(old,new)) 00473 ast_log(LOG_ERROR, "Unable to rename file '%s' to '%s'\n", old, new); 00474 } 00475 00476 eventlog = fopen(old, "a"); 00477 if (eventlog) { 00478 ast_log(LOG_EVENT, "Restarted Asterisk Event Logger\n"); 00479 if (option_verbose) 00480 ast_verbose("Asterisk Event Logger restarted\n"); 00481 } else { 00482 ast_log(LOG_ERROR, "Unable to create event log: %s\n", strerror(errno)); 00483 res = -1; 00484 } 00485 } 00486 00487 if (logfiles.queue_log) { 00488 snprintf(old, sizeof(old), "%s/%s", ast_config_AST_LOG_DIR, queue_log_name); 00489 if (queue_rotate) { 00490 if (!rotatetimestamp) { 00491 for (x = 0; ; x++) { 00492 snprintf(new, sizeof(new), "%s/%s.%d", ast_config_AST_LOG_DIR, queue_log_name, x); 00493 myf = fopen(new, "r"); 00494 if (myf) /* File exists */ 00495 fclose(myf); 00496 else 00497 break; 00498 } 00499 00500 } else 00501 snprintf(new, sizeof(new), "%s/%s.%ld", ast_config_AST_LOG_DIR, queue_log_name,(long)time(NULL)); 00502 /* do it */ 00503 if (rename(old, new)) 00504 ast_log(LOG_ERROR, "Unable to rename file '%s' to '%s'\n", old, new); 00505 } 00506 00507 qlog = fopen(old, "a"); 00508 if (qlog) { 00509 ast_queue_log("NONE", "NONE", "NONE", "CONFIGRELOAD", "%s", ""); 00510 ast_log(LOG_EVENT, "Restarted Asterisk Queue Logger\n"); 00511 if (option_verbose) 00512 ast_verbose("Asterisk Queue Logger restarted\n"); 00513 } else { 00514 ast_log(LOG_ERROR, "Unable to create queue log: %s\n", strerror(errno)); 00515 res = -1; 00516 } 00517 } 00518 00519 AST_LIST_UNLOCK(&logchannels); 00520 00521 return res; 00522 }
|
|
|
Definition at line 598 of file logger.c. Referenced by init_logger(). |
|
|
Definition at line 137 of file logger.c. Referenced by close_logger(), and logger_thread(). |
|
|
Definition at line 152 of file logger.c. Referenced by logger_print_normal(). |
|
|
|
|
|
|
|
|
Definition at line 139 of file logger.c. Referenced by close_logger(), init_logger(), logger_print_normal(), and reload_logger(). |
|
|
|
|
|
|
|
|
Definition at line 98 of file logger.c. Referenced by ast_remotecontrol(), cli_prompt(), iax2_register(), main(), netconsole(), set_destination(), and sip_register(). |
|
|
Definition at line 142 of file logger.c. Referenced by ast_log_vsyslog(), and logger_print_normal(). |
|
|
Definition at line 136 of file logger.c. Referenced by ast_log(), ast_verbose(), close_logger(), init_logger(), and logger_thread(). |
|
|
Referenced by init_logger(), init_logger_chain(), and logger_print_normal(). |
|
|
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: "Usage: logger show channels\n" " List configured logger channels.\n" |
|
|
Definition at line 135 of file logger.c. Referenced by ast_log(), ast_verbose(), and init_logger(). |
|
|
Definition at line 140 of file logger.c. Referenced by ast_queue_log(), close_logger(), init_logger(), and reload_logger(). |
|
|
|
|
|
|
|
|
|
|
|
|