#include <signal.h>
#include <stdarg.h>
#include <stdio.h>
#include <unistd.h>
#include <time.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 <string.h>
#include <stdlib.h>
#include <errno.h>
#include <sys/stat.h>
#include "asterisk.h"
#include "astconf.h"
#include <syslog.h>
#include <asterisk/logger.h>
Go to the source code of this file.
Defines | |
#define | SYSLOG_NAMES |
#define | SYSLOG_NLEVELS 6 |
#define | MAX_MSG_QUEUE 200 |
#define | GETTID() getpid() |
Functions | |
AST_MUTEX_DEFINE_STATIC (msglist_lock) | |
AST_MUTEX_DEFINE_STATIC (loglock) | |
AST_MUTEX_DEFINE_STATIC (qloglock) | |
void | ast_queue_log (const char *queuename, const char *callid, const char *agent, const char *event, const char *fmt,...) |
int | reload_logger (int rotate) |
int | init_logger (void) |
void | close_logger (void) |
void | ast_log (int level, const char *file, int line, const char *function, const char *fmt,...) |
void | ast_verbose (const char *fmt,...) |
int | ast_verbose_dmesg (void(*v)(const char *string, int opos, int replacelast, int complete)) |
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)) |
|
Definition at line 55 of file logger.c. Referenced by ast_log(). |
|
Definition at line 49 of file logger.c. Referenced by ast_verbose(). |
|
|
|
|
|
|
|
|
|
|
|
|
Definition at line 262 of file logger.c. References ast_mutex_lock, and ast_mutex_unlock. 00263 { 00264 va_list ap; 00265 ast_mutex_lock(&qloglock); 00266 if (qlog) { 00267 va_start(ap, fmt); 00268 fprintf(qlog, "%ld|%s|%s|%s|%s|", (long)time(NULL), callid, queuename, agent, event); 00269 vfprintf(qlog, fmt, ap); 00270 fprintf(qlog, "\n"); 00271 va_end(ap); 00272 fflush(qlog); 00273 } 00274 ast_mutex_unlock(&qloglock); 00275 }
|
|
Definition at line 677 of file logger.c. References ast_mutex_lock, ast_mutex_unlock, and malloc. Referenced by main(). 00678 { 00679 struct msglist *m; 00680 struct verb *tmp; 00681 /* XXX Should be more flexible here, taking > 1 verboser XXX */ 00682 if ((tmp = malloc(sizeof (struct verb)))) { 00683 tmp->verboser = v; 00684 ast_mutex_lock(&msglist_lock); 00685 tmp->next = verboser; 00686 verboser = tmp; 00687 m = list; 00688 while(m) { 00689 /* Send all the existing entries that we have queued (i.e. they're likely to have missed) */ 00690 v(m->msg, 0, 0, 1); 00691 m = m->next; 00692 } 00693 ast_mutex_unlock(&msglist_lock); 00694 return 0; 00695 } 00696 return -1; 00697 }
|
|
Definition at line 699 of file logger.c. References ast_mutex_lock, ast_mutex_unlock, and free. 00700 { 00701 int res = -1; 00702 struct verb *tmp, *tmpl=NULL; 00703 ast_mutex_lock(&msglist_lock); 00704 tmp = verboser; 00705 while(tmp) { 00706 if (tmp->verboser == v) { 00707 if (tmpl) 00708 tmpl->next = tmp->next; 00709 else 00710 verboser = tmp->next; 00711 free(tmp); 00712 break; 00713 } 00714 tmpl = tmp; 00715 tmp = tmp->next; 00716 } 00717 if (tmp) 00718 res = 0; 00719 ast_mutex_unlock(&msglist_lock); 00720 return res; 00721 }
|
|
Definition at line 599 of file logger.c. References ast_log(), ast_mutex_lock, ast_mutex_unlock, free, LOG_ERROR, LOG_VERBOSE, malloc, MAX_MSG_QUEUE, and strdup. Referenced by ast_cdr_unregister(), ast_channel_bridge(), ast_channel_register_ex(), ast_channel_unregister(), ast_context_add_include2(), ast_context_add_switch2(), ast_context_create(), ast_format_register(), ast_format_unregister(), ast_frame_dump(), ast_image_register(), ast_image_unregister(), ast_load_resource(), ast_log(), ast_manager_unregister(), ast_module_reload(), ast_pbx_outgoing_app(), ast_pbx_outgoing_exten(), ast_pbx_run(), ast_pbx_run_app(), ast_play_and_prepend(), ast_play_and_record(), ast_register_application(), ast_register_indication_country(), ast_register_translator(), ast_rtp_reload(), ast_save(), ast_set_indication_country(), ast_streamfile(), ast_unregister_application(), ast_unregister_indication_country(), ast_unregister_translator(), init_logger(), init_manager(), load_modules(), load_pbx(), main(), pbx_builtin_setvar_helper(), and reload_logger(). 00600 { 00601 static char stuff[4096]; 00602 static int pos = 0, opos; 00603 static int replacelast = 0, complete; 00604 struct msglist *m; 00605 struct verb *v; 00606 va_list ap; 00607 va_start(ap, fmt); 00608 ast_mutex_lock(&msglist_lock); 00609 vsnprintf(stuff + pos, sizeof(stuff) - pos, fmt, ap); 00610 opos = pos; 00611 pos = strlen(stuff); 00612 if (fmt[strlen(fmt)-1] == '\n') 00613 complete = 1; 00614 else 00615 complete=0; 00616 if (complete) { 00617 if (msgcnt < MAX_MSG_QUEUE) { 00618 /* Allocate new structure */ 00619 m = malloc(sizeof(struct msglist)); 00620 msgcnt++; 00621 } else { 00622 /* Recycle the oldest entry */ 00623 m = list; 00624 list = list->next; 00625 free(m->msg); 00626 } 00627 if (m) { 00628 m->msg = strdup(stuff); 00629 if (m->msg) { 00630 if (last) 00631 last->next = m; 00632 else 00633 list = m; 00634 m->next = NULL; 00635 last = m; 00636 } else { 00637 msgcnt--; 00638 ast_log(LOG_ERROR, "Out of memory\n"); 00639 free(m); 00640 } 00641 } 00642 } 00643 if (verboser) { 00644 v = verboser; 00645 while(v) { 00646 v->verboser(stuff, opos, replacelast, complete); 00647 v = v->next; 00648 } 00649 } /* else 00650 fprintf(stdout, stuff + opos); */ 00651 00652 ast_log(LOG_VERBOSE, "%s", stuff); 00653 00654 if (fmt[strlen(fmt)-1] != '\n') 00655 replacelast = 1; 00656 else 00657 replacelast = pos = 0; 00658 va_end(ap); 00659 00660 ast_mutex_unlock(&msglist_lock); 00661 }
|
|
Definition at line 663 of file logger.c. References ast_mutex_lock, and ast_mutex_unlock. 00664 { 00665 struct msglist *m; 00666 ast_mutex_lock(&msglist_lock); 00667 m = list; 00668 while(m) { 00669 /* Send all the existing entries that we have queued (i.e. they're likely to have missed) */ 00670 v(m->msg, 0, 0, 1); 00671 m = m->next; 00672 } 00673 ast_mutex_unlock(&msglist_lock); 00674 return 0; 00675 }
|
|
Definition at line 461 of file logger.c. References ast_mutex_lock, ast_mutex_unlock, and free. 00462 { 00463 struct msglist *m, *tmp; 00464 00465 ast_mutex_lock(&msglist_lock); 00466 m = list; 00467 while(m) { 00468 if (m->msg) { 00469 free(m->msg); 00470 } 00471 tmp = m->next; 00472 free(m); 00473 m = tmp; 00474 } 00475 list = last = NULL; 00476 msgcnt = 0; 00477 ast_mutex_unlock(&msglist_lock); 00478 return; 00479 }
|
|
Definition at line 429 of file logger.c. References ast_cli_register(), ast_config_AST_LOG_DIR, ast_log(), ast_verbose(), EVENTLOG, LOG_ERROR, LOG_EVENT, and option_verbose. Referenced by main(). 00430 { 00431 char tmp[256]; 00432 00433 /* auto rotate if sig SIGXFSZ comes a-knockin */ 00434 (void) signal(SIGXFSZ,(void *) handle_SIGXFSZ); 00435 00436 /* register the relaod logger cli command */ 00437 ast_cli_register(&reload_logger_cli); 00438 ast_cli_register(&rotate_logger_cli); 00439 00440 /* initialize queue logger */ 00441 queue_log_init(); 00442 00443 /* create the eventlog */ 00444 mkdir((char *)ast_config_AST_LOG_DIR, 0755); 00445 snprintf(tmp, sizeof(tmp), "%s/%s", (char *)ast_config_AST_LOG_DIR, EVENTLOG); 00446 eventlog = fopen((char *)tmp, "a"); 00447 if (eventlog) { 00448 init_logger_chain(); 00449 ast_log(LOG_EVENT, "Started Asterisk Event Logger\n"); 00450 if (option_verbose) 00451 ast_verbose("Asterisk Event Logger Started %s\n",(char *)tmp); 00452 return 0; 00453 } else 00454 ast_log(LOG_ERROR, "Unable to create event log: %s\n", strerror(errno)); 00455 00456 /* create log channels */ 00457 init_logger_chain(); 00458 return -1; 00459 }
|
|
Definition at line 296 of file logger.c. References ast_config_AST_LOG_DIR, AST_CONFIG_MAX_PATH, ast_log(), ast_mutex_lock, ast_mutex_unlock, ast_verbose(), EVENTLOG, logchannel::filename, logchannel::fileptr, LOG_ERROR, LOG_EVENT, logchannel::next, and option_verbose. Referenced by ast_log(), and main(). 00297 { 00298 char old[AST_CONFIG_MAX_PATH] = ""; 00299 char new[AST_CONFIG_MAX_PATH]; 00300 struct logchannel *f; 00301 FILE *myf; 00302 00303 int x; 00304 ast_mutex_lock(&loglock); 00305 if (eventlog) 00306 fclose(eventlog); 00307 else 00308 rotate = 0; 00309 eventlog = NULL; 00310 00311 00312 00313 mkdir((char *)ast_config_AST_LOG_DIR, 0755); 00314 snprintf(old, sizeof(old), "%s/%s", (char *)ast_config_AST_LOG_DIR, EVENTLOG); 00315 00316 if(rotate) { 00317 for(x=0;;x++) { 00318 snprintf(new, sizeof(new), "%s/%s.%d", (char *)ast_config_AST_LOG_DIR, EVENTLOG,x); 00319 myf = fopen((char *)new, "r"); 00320 if(myf) 00321 fclose(myf); 00322 else 00323 break; 00324 } 00325 00326 /* do it */ 00327 if (rename(old,new)) 00328 fprintf(stderr, "Unable to rename file '%s' to '%s'\n", old, new); 00329 } 00330 00331 eventlog = fopen(old, "a"); 00332 00333 f = logchannels; 00334 while(f) { 00335 if (f->fileptr && (f->fileptr != stdout) && (f->fileptr != stderr)) { 00336 fclose(f->fileptr); 00337 f->fileptr = NULL; 00338 if(rotate) { 00339 strncpy(old, f->filename, sizeof(old) - 1); 00340 00341 for(x=0;;x++) { 00342 snprintf(new, sizeof(new), "%s.%d", f->filename, x); 00343 myf = fopen((char *)new, "r"); 00344 if (myf) { 00345 fclose(myf); 00346 } else { 00347 break; 00348 } 00349 } 00350 00351 /* do it */ 00352 if (rename(old,new)) 00353 fprintf(stderr, "Unable to rename file '%s' to '%s'\n", old, new); 00354 } 00355 } 00356 f = f->next; 00357 } 00358 00359 ast_mutex_unlock(&loglock); 00360 00361 queue_log_init(); 00362 00363 if (eventlog) { 00364 init_logger_chain(); 00365 ast_log(LOG_EVENT, "Restarted Asterisk Event Logger\n"); 00366 if (option_verbose) 00367 ast_verbose("Asterisk Event Logger restarted\n"); 00368 return 0; 00369 } else 00370 ast_log(LOG_ERROR, "Unable to create event log: %s\n", strerror(errno)); 00371 init_logger_chain(); 00372 pending_logger_reload = 0; 00373 return -1; 00374 }
|