25 #ifndef _ASTERISK_LOGGER_H 26 #define _ASTERISK_LOGGER_H 30 #if defined(__cplusplus) || defined(c_plusplus) 34 #define EVENTLOG "event_log" 35 #define QUEUELOG "queue_log" 37 #define DEBUG_M(a) { \ 41 #define VERBOSE_PREFIX_1 " " 42 #define VERBOSE_PREFIX_2 " == " 43 #define VERBOSE_PREFIX_3 " -- " 44 #define VERBOSE_PREFIX_4 " > " 46 #define AST_CALLID_BUFFER_LENGTH 13 69 void ast_log(
int level,
const char *
file,
int line,
const char *
function,
const char *fmt, ...)
70 __attribute__((
format(printf, 5, 6)));
72 void ast_log_ap(
int level, const
char *file,
int line, const
char *function, const
char *fmt, va_list ap)
73 __attribute__((
format(printf, 5, 0)));
83 void ast_log_safe(
int level, const
char *file,
int line, const
char *function, const
char *fmt, ...)
84 __attribute__((
format(printf, 5, 6)));
101 void ast_log_callid(
int level, const
char *file,
int line, const
char *function, ast_callid callid, const
char *fmt, ...)
102 __attribute__((
format(printf, 6, 7)));
117 const
char *
status, const
char *configuration,
void *data),
void *data);
149 void __attribute__((
format(printf, 5, 6)))
ast_queue_log(const
char *queuename, const
char *callid, const
char *agent, const
char *
event, const
char *fmt, ...);
165 void __attribute__((
format(printf, 5, 6)))
__ast_verbose(const
char *file,
int line, const
char *func,
int level, const
char *fmt, ...);
175 void __attribute__((
format(printf, 6, 7)))
__ast_verbose_callid(const
char *file,
int line, const
char *func,
int level, ast_callid callid, const
char *fmt, ...);
177 #define ast_verbose(...) __ast_verbose(__FILE__, __LINE__, __PRETTY_FUNCTION__, -1, __VA_ARGS__) 178 #define ast_verbose_callid(callid, ...) __ast_verbose_callid(__FILE__, __LINE__, __PRETTY_FUNCTION__, -1, callid, __VA_ARGS__) 180 void __attribute__((
format(printf, 6, 0)))
__ast_verbose_ap(const
char *file,
int line, const
char *func,
int level, ast_callid callid, const
char *fmt, va_list ap);
192 #define VERBOSE_MAGIC2LEVEL(x) (((char) -*(signed char *) (x)) - 1) 193 #define VERBOSE_HASMAGIC(x) (*(signed char *) (x) < 0) 235 #define _A_ __FILE__, __LINE__, __PRETTY_FUNCTION__ 240 #define __LOG_DEBUG 0 241 #define LOG_DEBUG __LOG_DEBUG, _A_ 246 #define AST_LOG_DEBUG __LOG_DEBUG, _A_ 251 #define __LOG_TRACE 1 252 #define LOG_TRACE __LOG_TRACE, _A_ 257 #define AST_LOG_TRACE __LOG_TRACE, _A_ 262 #define __LOG_NOTICE 2 263 #define LOG_NOTICE __LOG_NOTICE, _A_ 265 #ifdef AST_LOG_NOTICE 266 #undef AST_LOG_NOTICE 268 #define AST_LOG_NOTICE __LOG_NOTICE, _A_ 273 #define __LOG_WARNING 3 274 #define LOG_WARNING __LOG_WARNING, _A_ 276 #ifdef AST_LOG_WARNING 277 #undef AST_LOG_WARNING 279 #define AST_LOG_WARNING __LOG_WARNING, _A_ 284 #define __LOG_ERROR 4 285 #define LOG_ERROR __LOG_ERROR, _A_ 290 #define AST_LOG_ERROR __LOG_ERROR, _A_ 295 #define __LOG_VERBOSE 5 296 #define LOG_VERBOSE __LOG_VERBOSE, _A_ 298 #ifdef AST_LOG_VERBOSE 299 #undef AST_LOG_VERBOSE 301 #define AST_LOG_VERBOSE __LOG_VERBOSE, _A_ 307 #define LOG_DTMF __LOG_DTMF, _A_ 312 #define AST_LOG_DTMF __LOG_DTMF, _A_ 314 #define NUMLOGLEVELS 32 439 #define ast_log_dynamic_level(level, ...) ast_log(level, __FILE__, __LINE__, __PRETTY_FUNCTION__, __VA_ARGS__) 441 #define DEBUG_ATLEAST(level) \ 442 (option_debug >= (level) \ 443 || (ast_opt_dbg_module \ 444 && ((int)ast_debug_get_by_module(AST_MODULE) >= (level) \ 445 || (int)ast_debug_get_by_module(__FILE__) >= (level)))) 452 #define ast_debug(level, ...) \ 454 if (DEBUG_ATLEAST(level)) { \ 455 ast_log(AST_LOG_DEBUG, __VA_ARGS__); \ 461 #define VERBOSITY_ATLEAST(level) ((level) <= ast_verb_sys_level) 463 #define ast_verb(level, ...) \ 465 if (VERBOSITY_ATLEAST(level) ) { \ 466 __ast_verbose(__FILE__, __LINE__, __PRETTY_FUNCTION__, level, __VA_ARGS__); \ 470 #define ast_verb_callid(level, callid, ...) \ 472 if (VERBOSITY_ATLEAST(level) ) { \ 473 __ast_verbose_callid(__FILE__, __LINE__, __PRETTY_FUNCTION__, level, callid, __VA_ARGS__); \ 637 #define TRACE_ATLEAST(level) \ 638 (option_trace >= (level) \ 639 || (ast_opt_trace_module \ 640 && ((int)ast_trace_get_by_module(AST_MODULE) >= (level) \ 641 || (int)ast_trace_get_by_module(__FILE__) >= (level)))) 665 void __attribute__((
format (printf, 6, 7)))
__ast_trace(const
char *file,
int line, const
char *func,
677 #define ast_trace_raw(level, indent_type, ...) \ 678 ast_debug(level < 0 ? __scope_level : level, " " __VA_ARGS__); \ 679 if (TRACE_ATLEAST(level < 0 ? __scope_level : level)) { \ 680 __ast_trace(__FILE__, __LINE__, __PRETTY_FUNCTION__, indent_type, 0, " " __VA_ARGS__); \ 692 #define ast_trace(level, ...) \ 693 ast_debug(level < 0 ? __scope_level : level, " " __VA_ARGS__); \ 694 if (TRACE_ATLEAST(level < 0 ? __scope_level : level)) { \ 695 __ast_trace(__FILE__, __LINE__, __PRETTY_FUNCTION__, AST_TRACE_INDENT_SAME, 0, " " __VA_ARGS__); \ 704 #define ast_trace_get_indent() _ast_trace_get_indent() 712 #define ast_trace_set_indent(indent) _ast_trace_set_indent(indent) 720 #define ast_trace_inc_indent() _ast_trace_inc_indent() 728 #define ast_trace_dec_indent() _ast_trace_dec_indent() 749 #define SCOPE_TRACE(level, ...) \ 750 const char *__trace_funcname = __PRETTY_FUNCTION__; \ 751 auto void __scopevar ## __LINE__ ## __EXIT(void * v); \ 752 void __scopevar ## __LINE__ ## __EXIT(void * v __attribute__((unused))) { \ 753 if (TRACE_ATLEAST(level)) { \ 754 __ast_trace(__FILE__, __LINE__, __trace_funcname, AST_TRACE_INDENT_DEC_BEFORE, 0, " " __VA_ARGS__); \ 757 void *__scopevar ## __LINE__ ## __TRACER __attribute__((cleanup(__scopevar ## __LINE__ ## __EXIT))) = (void *) __PRETTY_FUNCTION__ ; \ 758 auto int __scopevar ## __LINE__ ## __ENTER(void); \ 759 int __scopevar ## __LINE__ ## __ENTER(void) { \ 760 if (TRACE_ATLEAST(level)) { \ 761 __ast_trace(__FILE__, __LINE__, __trace_funcname, AST_TRACE_INDENT_INC_AFTER, 0, " " __VA_ARGS__); \ 765 int __scopevar ## __LINE__ ## __RETURN __attribute__((unused)) = __scopevar ## __LINE__ ## __ENTER() 780 #define SCOPE_ENTER(level, ...) \ 781 int __scope_level = level; \ 782 int __scope_task = 0; \ 783 ast_debug(__scope_level, " " __VA_ARGS__); \ 784 if (TRACE_ATLEAST(level)) { \ 785 __ast_trace(__FILE__, __LINE__, __PRETTY_FUNCTION__, AST_TRACE_INDENT_INC_AFTER, 0, " " __VA_ARGS__); \ 788 #define SCOPE_ENTER_TASK(level, indent, ...) \ 789 int __scope_level = level; \ 790 int __scope_task = 1; \ 791 ast_debug(__scope_level, " " __VA_ARGS__); \ 792 if (TRACE_ATLEAST(level)) { \ 793 __ast_trace(__FILE__, __LINE__, __PRETTY_FUNCTION__, AST_TRACE_INDENT_PROVIDED, indent, " " __VA_ARGS__); \ 805 #define SCOPE_EXIT(...) \ 806 ast_debug(__scope_level, " " __VA_ARGS__); \ 807 if (TRACE_ATLEAST(__scope_level)) { \ 808 __ast_trace(__FILE__, __LINE__, __PRETTY_FUNCTION__, AST_TRACE_INDENT_DEC_BEFORE, 0, " " __VA_ARGS__); \ 809 if (__scope_task) { \ 810 _ast_trace_set_indent(0); \ 834 #define SCOPE_EXIT_EXPR(__expr, ...) \ 835 ast_debug(__scope_level, " " __VA_ARGS__); \ 836 if (TRACE_ATLEAST(__scope_level)) { \ 837 __ast_trace(__FILE__, __LINE__, __PRETTY_FUNCTION__, AST_TRACE_INDENT_DEC_BEFORE, 0, " " __VA_ARGS__); \ 838 if (__scope_task) { \ 839 _ast_trace_set_indent(0); \ 854 #define SCOPE_EXIT_RTN(...) \ 855 ast_debug(__scope_level, " " __VA_ARGS__); \ 856 if (TRACE_ATLEAST(__scope_level)) { \ 857 __ast_trace(__FILE__, __LINE__, __PRETTY_FUNCTION__, AST_TRACE_INDENT_DEC_BEFORE, 0, " " __VA_ARGS__); \ 858 if (__scope_task) { \ 859 _ast_trace_set_indent(0); \ 875 #define SCOPE_EXIT_RTN_VALUE(__return_value, ...) \ 876 ast_debug(__scope_level, " " __VA_ARGS__); \ 877 if (TRACE_ATLEAST(__scope_level)) { \ 878 __ast_trace(__FILE__, __LINE__, __PRETTY_FUNCTION__, AST_TRACE_INDENT_DEC_BEFORE, 0, " " __VA_ARGS__); \ 879 if (__scope_task) { \ 880 _ast_trace_set_indent(0); \ 883 return(__return_value) 886 #define ast_trace_raw(level, indent_type, ...) \ 887 ast_debug(level < 0 ? __scope_level : level, " " __VA_ARGS__) 889 #define ast_trace(level, ...) \ 890 ast_debug(level < 0 ? __scope_level : level, " " __VA_ARGS__) 892 #define ast_trace_get_indent() (0) 893 #define ast_trace_set_indent(indent) 894 #define ast_trace_inc_indent() 895 #define ast_trace_dec_indent() 896 #define SCOPE_TRACE(__level, ...) 898 #define SCOPE_ENTER(level, ...) \ 899 int __scope_level = level; \ 900 ast_debug(level, " " __VA_ARGS__) 902 #define SCOPE_ENTER_TASK(level, indent, ...) \ 903 int __scope_level = level; \ 904 ast_debug(level, " " __VA_ARGS__) 906 #define SCOPE_EXIT(...) \ 907 ast_debug(__scope_level, " " __VA_ARGS__) 909 #define SCOPE_EXIT_EXPR(__expr, ...) \ 910 ast_debug(__scope_level, " " __VA_ARGS__); \ 913 #define SCOPE_EXIT_RTN(...) \ 914 ast_debug(__scope_level, " " __VA_ARGS__); \ 917 #define SCOPE_EXIT_RTN_VALUE(__return_value, ...) \ 918 ast_debug(__scope_level, " " __VA_ARGS__); \ 919 return __return_value 928 #define SCOPE_EXIT_LOG(__log_level, ...) \ 930 ast_log(__log_level, " " __VA_ARGS__); \ 931 SCOPE_EXIT(" " __VA_ARGS__); \ 934 #define SCOPE_EXIT_LOG_RTN(__log_level, ...) \ 936 ast_log(__log_level, " " __VA_ARGS__); \ 937 SCOPE_EXIT_RTN(" " __VA_ARGS__); \ 940 #define SCOPE_EXIT_LOG_RTN_VALUE(__value, __log_level, ...) \ 942 ast_log(__log_level, " " __VA_ARGS__); \ 943 SCOPE_EXIT_RTN_VALUE(__value, " " __VA_ARGS__); \ 946 #define SCOPE_EXIT_LOG_EXPR(__expr, __log_level, ...) \ 948 ast_log(__log_level, " " __VA_ARGS__); \ 949 SCOPE_EXIT_EXPR(__expr, " " __VA_ARGS__); \ 952 #define ast_trace_log(__level, __log_level, ...) \ 954 ast_log(__log_level, " " __VA_ARGS__); \ 955 ast_trace(__level < 0 ? __scope_level : __level, " " __VA_ARGS__); \ 959 #if defined(__cplusplus) || defined(c_plusplus) void ast_console_puts(const char *string)
write the string to the root console, and all attached network console clients
void ast_log(int level, const char *file, int line, const char *function, const char *fmt,...)
Used for sending a log message This is the standard logger function. Probably the only way you will i...
void ast_console_puts_mutable_full(const char *message, int level, int sublevel)
log the string to the console, and all attached console clients
void ast_log_callid(int level, const char *file, int line, const char *function, ast_callid callid, const char *fmt,...)
Used for sending a log message with a known call_id This is a modified logger function which is funct...
int ast_logger_get_channels(int(*logentry)(const char *channel, const char *type, const char *status, const char *configuration, void *data), void *data)
Retrieve the existing log channels.
unsigned long _ast_trace_dec_indent(void)
Decrement the indent level.
int ast_verb_console_get(void)
Get this thread's console verbosity level.
void ast_callid_threadstorage_auto_clean(ast_callid callid, int callid_created)
Use in conjunction with ast_callid_threadstorage_auto. Cleans up the references and if the callid was...
int ast_callid_threadassoc_change(ast_callid callid)
Sets what is stored in the thread storage to the given callid if it does not match what is already th...
const char * ast_logger_get_dateformat(void)
Get the logger configured date format.
int ast_logger_rotate_channel(const char *log_channel)
Rotate the specified log channel.
void __ast_verbose(const char *file, int line, const char *func, int level, const char *fmt,...)
Send a verbose message (based on verbose level)
void ast_queue_log(const char *queuename, const char *callid, const char *agent, const char *event, const char *fmt,...)
int ast_logger_rotate(void)
Reload logger while rotating log files.
unsigned long _ast_trace_inc_indent(void)
Increment the indent level.
void ast_init_logger_for_socket_console(void)
load logger.conf configuration for console socket connections
void ast_console_toggle_loglevel(int fd, int level, int state)
enables or disables logging of a specified level to the console fd specifies the index of the console...
void ast_console_toggle_mute(int fd, int silent)
mute or unmute a console from logging
int ast_callid_threadassoc_remove(void)
Removes callid from thread storage of the calling thread.
ast_callid ast_read_threadstorage_callid(void)
extracts the callerid from the thread
void ast_log_backtrace(void)
Log a backtrace of the current thread's execution stack to the Asterisk log.
void ast_verb_console_register(int *level)
Register this thread's console verbosity level pointer.
void ast_child_verbose(int level, const char *fmt,...)
int ast_callid_threadassoc_add(ast_callid callid)
Adds a known callid to thread storage of the calling thread.
void __ast_verbose_callid(const char *file, int line, const char *func, int level, ast_callid callid, const char *fmt,...)
Send a verbose message (based on verbose level) with deliberately specified callid.
void ast_logger_unregister_level(const char *name)
Unregister a previously registered logger level.
ast_trace_indent_type
Controls if and when indenting is applied.
int ast_register_verbose(void(*verboser)(const char *string)) attribute_warn_unused_result
unsigned int ast_trace_get_by_module(const char *module)
Get the trace level for a module.
void ast_logger_set_queue_limit(int queue_limit)
Set the maximum number of messages allowed in the processing queue.
int ast_logger_register_level(const char *name)
Register a new logger level.
int ast_logger_create_channel(const char *log_channel, const char *components)
Create a log channel.
void ast_log_safe(int level, const char *file, int line, const char *function, const char *fmt,...)
Used for sending a log message with protection against recursion.
ast_callid ast_create_callid(void)
factory function to create a new uniquely identifying callid.
int ast_logger_get_queue_limit(void)
Get the maximum number of messages allowed in the processing queue.
void ast_callid_strnprint(char *buffer, size_t buffer_size, ast_callid callid)
copy a string representation of the callid into a target string
void ast_verb_console_unregister(void)
Unregister this thread's console verbosity level.
int ast_is_logger_initialized(void)
Test if logger is initialized.
unsigned long _ast_trace_get_indent(void)
Get the current indent level.
int ast_logger_remove_channel(const char *log_channel)
Delete the specified log channel.
int ast_dynamic_logger_level(const char *name)
Checks if a dynamic logger level exists.
#define attribute_warn_unused_result
void __ast_verbose_ap(const char *file, int line, const char *func, int level, ast_callid callid, const char *fmt, va_list ap)
void ast_console_puts_mutable(const char *string, int level)
log the string to the console, and all attached console clients
void ast_verb_update(void)
Re-evaluate the system max verbosity level (ast_verb_sys_level).
void _ast_trace_set_indent(unsigned long indent)
Set the current indent level.
void ast_verb_console_set(int verb_level)
Set this thread's console verbosity level.
int ast_callid_threadstorage_auto(ast_callid *callid)
Checks thread storage for a callid and stores a reference if it exists. If not, then a new one will b...
Options provided by main asterisk program.
unsigned int ast_debug_get_by_module(const char *module)
Get the debug level for a module.
int ast_unregister_verbose(void(*verboser)(const char *string)) attribute_warn_unused_result
static snd_pcm_format_t format
void ast_log_ap(int level, const char *file, int line, const char *function, const char *fmt, va_list ap)
void __ast_trace(const char *file, int line, const char *func, enum ast_trace_indent_type indent_type, unsigned long indent, const char *format,...)