#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.
Data Structures | |
| struct | msglist |
| struct | logchannel |
| struct | verb |
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 710 of file logger.c. References ast_mutex_lock, ast_mutex_unlock, and malloc. Referenced by main(). 00711 { 00712 struct msglist *m; 00713 struct verb *tmp; 00714 /* XXX Should be more flexible here, taking > 1 verboser XXX */ 00715 if ((tmp = malloc(sizeof (struct verb)))) { 00716 tmp->verboser = v; 00717 ast_mutex_lock(&msglist_lock); 00718 tmp->next = verboser; 00719 verboser = tmp; 00720 m = list; 00721 while(m) { 00722 /* Send all the existing entries that we have queued (i.e. they're likely to have missed) */ 00723 v(m->msg, 0, 0, 1); 00724 m = m->next; 00725 } 00726 ast_mutex_unlock(&msglist_lock); 00727 return 0; 00728 } 00729 return -1; 00730 }
|
|
|
Definition at line 732 of file logger.c. References ast_mutex_lock, ast_mutex_unlock, and free. 00733 { 00734 int res = -1; 00735 struct verb *tmp, *tmpl=NULL; 00736 ast_mutex_lock(&msglist_lock); 00737 tmp = verboser; 00738 while(tmp) { 00739 if (tmp->verboser == v) { 00740 if (tmpl) 00741 tmpl->next = tmp->next; 00742 else 00743 verboser = tmp->next; 00744 free(tmp); 00745 break; 00746 } 00747 tmpl = tmp; 00748 tmp = tmp->next; 00749 } 00750 if (tmp) 00751 res = 0; 00752 ast_mutex_unlock(&msglist_lock); 00753 return res; 00754 }
|
|
||||||||||||
|
Definition at line 632 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_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(). 00633 { 00634 static char stuff[4096]; 00635 static int pos = 0, opos; 00636 static int replacelast = 0, complete; 00637 struct msglist *m; 00638 struct verb *v; 00639 va_list ap; 00640 va_start(ap, fmt); 00641 ast_mutex_lock(&msglist_lock); 00642 vsnprintf(stuff + pos, sizeof(stuff) - pos, fmt, ap); 00643 opos = pos; 00644 pos = strlen(stuff); 00645 if (fmt[strlen(fmt)-1] == '\n') 00646 complete = 1; 00647 else 00648 complete=0; 00649 if (complete) { 00650 if (msgcnt < MAX_MSG_QUEUE) { 00651 /* Allocate new structure */ 00652 m = malloc(sizeof(struct msglist)); 00653 msgcnt++; 00654 } else { 00655 /* Recycle the oldest entry */ 00656 m = list; 00657 list = list->next; 00658 free(m->msg); 00659 } 00660 if (m) { 00661 m->msg = strdup(stuff); 00662 if (m->msg) { 00663 if (last) 00664 last->next = m; 00665 else 00666 list = m; 00667 m->next = NULL; 00668 last = m; 00669 } else { 00670 msgcnt--; 00671 ast_log(LOG_ERROR, "Out of memory\n"); 00672 free(m); 00673 } 00674 } 00675 } 00676 if (verboser) { 00677 v = verboser; 00678 while(v) { 00679 v->verboser(stuff, opos, replacelast, complete); 00680 v = v->next; 00681 } 00682 } /* else 00683 fprintf(stdout, stuff + opos); */ 00684 00685 ast_log(LOG_VERBOSE, "%s", stuff); 00686 00687 if (fmt[strlen(fmt)-1] != '\n') 00688 replacelast = 1; 00689 else 00690 replacelast = pos = 0; 00691 va_end(ap); 00692 00693 ast_mutex_unlock(&msglist_lock); 00694 }
|
|
|
Definition at line 696 of file logger.c. References ast_mutex_lock, and ast_mutex_unlock. 00697 { 00698 struct msglist *m; 00699 ast_mutex_lock(&msglist_lock); 00700 m = list; 00701 while(m) { 00702 /* Send all the existing entries that we have queued (i.e. they're likely to have missed) */ 00703 v(m->msg, 0, 0, 1); 00704 m = m->next; 00705 } 00706 ast_mutex_unlock(&msglist_lock); 00707 return 0; 00708 }
|
|
|
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 }
|
1.4.4