26#ifndef _ASTERISK_LOGGER_H
27#define _ASTERISK_LOGGER_H
31#if defined(__cplusplus) || defined(c_plusplus)
35#define EVENTLOG "event_log"
36#define QUEUELOG "queue_log"
42#define _A_ __FILE__, __LINE__, __FUNCTION__
44#define VERBOSE_PREFIX_1 " "
45#define VERBOSE_PREFIX_2 " == "
46#define VERBOSE_PREFIX_3 " -- "
47#define VERBOSE_PREFIX_4 " > "
48#define VERBOSE_PREFIX_5 " > "
49#define VERBOSE_PREFIX_6 " > "
50#define VERBOSE_PREFIX_7 " > "
51#define VERBOSE_PREFIX_8 " > "
52#define VERBOSE_PREFIX_9 " > "
53#define VERBOSE_PREFIX_10 " > "
55#define AST_CALLID_BUFFER_LENGTH 13
78void ast_log(
int level,
const char *
file,
int line,
const char *function,
const char *fmt, ...)
79 __attribute__((format(printf, 5, 6)));
81void ast_log_ap(
int level, const
char *
file,
int line, const
char *function, const
char *fmt, va_list ap)
82 __attribute__((format(printf, 5, 0)));
92void ast_log_safe(
int level, const
char *
file,
int line, const
char *function, const
char *fmt, ...)
93 __attribute__((format(printf, 5, 6)));
111 __attribute__((format(printf, 6, 7)));
126 const
char *
status, const
char *configuration,
void *data),
void *data);
158void __attribute__((format(printf, 5, 6)))
ast_queue_log(const
char *queuename, const
char *callid, const
char *agent, const
char *
event, const
char *fmt, ...);
174void __attribute__((format(printf, 5, 6)))
__ast_verbose(const
char *
file,
int line, const
char *func,
int level, const
char *fmt, ...);
186#define ast_verbose(...) __ast_verbose(_A_, -1, __VA_ARGS__)
187#define ast_verbose_callid(callid, ...) __ast_verbose_callid(_A_, -1, callid, __VA_ARGS__)
189void __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);
191void __attribute__((format(printf, 2, 3)))
ast_child_verbose(
int level, const
char *fmt, ...);
201#define VERBOSE_MAGIC2LEVEL(x) (((char) -*(signed char *) (x)) - 1)
202#define VERBOSE_HASMAGIC(x) (*(signed char *) (x) < 0)
248#define LOG_DEBUG __LOG_DEBUG, _A_
253#define AST_LOG_DEBUG __LOG_DEBUG, _A_
259#define LOG_TRACE __LOG_TRACE, _A_
264#define AST_LOG_TRACE __LOG_TRACE, _A_
269#define __LOG_NOTICE 2
270#define LOG_NOTICE __LOG_NOTICE, _A_
275#define AST_LOG_NOTICE __LOG_NOTICE, _A_
280#define __LOG_WARNING 3
281#define LOG_WARNING __LOG_WARNING, _A_
283#ifdef AST_LOG_WARNING
284#undef AST_LOG_WARNING
286#define AST_LOG_WARNING __LOG_WARNING, _A_
292#define LOG_ERROR __LOG_ERROR, _A_
297#define AST_LOG_ERROR __LOG_ERROR, _A_
302#define __LOG_VERBOSE 5
303#define LOG_VERBOSE __LOG_VERBOSE, _A_
305#ifdef AST_LOG_VERBOSE
306#undef AST_LOG_VERBOSE
308#define AST_LOG_VERBOSE __LOG_VERBOSE, _A_
314#define LOG_DTMF __LOG_DTMF, _A_
319#define AST_LOG_DTMF __LOG_DTMF, _A_
321#define NUMLOGLEVELS 32
444#define ast_log_dynamic_level(level, ...) ast_log(level, _A_, __VA_ARGS__)
446#define DEBUG_ATLEAST(level) \
447 (option_debug >= (level) \
448 || (ast_opt_dbg_module \
449 && ((int)ast_debug_get_by_module(AST_MODULE) >= (level) \
450 || (int)ast_debug_get_by_module(__FILE__) >= (level))))
457#define ast_debug(level, ...) \
459 if (DEBUG_ATLEAST(level)) { \
460 ast_log(AST_LOG_DEBUG, __VA_ARGS__); \
466#define VERBOSITY_ATLEAST(level) ((level) <= ast_verb_sys_level)
468#define ast_verb(level, ...) \
470 if (VERBOSITY_ATLEAST(level) ) { \
471 __ast_verbose(_A_, level, __VA_ARGS__); \
475#define ast_verb_callid(level, callid, ...) \
477 if (VERBOSITY_ATLEAST(level) ) { \
478 __ast_verbose_callid(_A_, level, callid, __VA_ARGS__); \
668#define _TRACE_PREFIX_DEFAULT_ _A_
669#ifndef _TRACE_PREFIX_
670#define _TRACE_PREFIX_ _TRACE_PREFIX_DEFAULT_
685#define TRACE_ATLEAST(level) \
686 (option_trace >= (level) \
687 || (ast_opt_trace_module \
688 && ((int)ast_trace_get_by_module(AST_MODULE) >= (level) \
689 || (int)ast_trace_get_by_module(__FILE__) >= (level))))
713void __attribute__((format (printf, 6, 7))) __ast_trace(const
char *
file,
int line, const
char *func,
724#define ast_trace_raw(level, indent_type, ...) \
725 ast_debug(level < 0 ? __scope_level : level, " " __VA_ARGS__); \
726 if (TRACE_ATLEAST(level < 0 ? __scope_level : level)) { \
727 __ast_trace(_TRACE_PREFIX_, indent_type, 0, " " __VA_ARGS__); \
738#define ast_trace(level, ...) \
739 ast_debug(level < 0 ? __scope_level : level, " " __VA_ARGS__); \
740 if (TRACE_ATLEAST(level < 0 ? __scope_level : level)) { \
741 __ast_trace(_TRACE_PREFIX_, AST_TRACE_INDENT_SAME, 0, " " __VA_ARGS__); \
749unsigned long _ast_trace_get_indent(
void);
750#define ast_trace_get_indent() _ast_trace_get_indent()
757void _ast_trace_set_indent(
unsigned long indent);
758#define ast_trace_set_indent(indent) _ast_trace_set_indent(indent)
765unsigned long _ast_trace_inc_indent(
void);
766#define ast_trace_inc_indent() _ast_trace_inc_indent()
773unsigned long _ast_trace_dec_indent(
void);
774#define ast_trace_dec_indent() _ast_trace_dec_indent()
794#define SCOPE_TRACE(level, ...) \
795 const char *__trace_funcname = __PRETTY_FUNCTION__; \
796 auto void __scopevar ## __LINE__ ## __EXIT(void * v); \
797 void __scopevar ## __LINE__ ## __EXIT(void * v __attribute__((unused))) { \
798 if (TRACE_ATLEAST(level)) { \
799 __ast_trace(__FILE__, __LINE__, __trace_funcname, AST_TRACE_INDENT_DEC_BEFORE, 0, " " __VA_ARGS__); \
802 void *__scopevar ## __LINE__ ## __TRACER __attribute__((cleanup(__scopevar ## __LINE__ ## __EXIT))) = (void *) __PRETTY_FUNCTION__ ; \
803 auto int __scopevar ## __LINE__ ## __ENTER(void); \
804 int __scopevar ## __LINE__ ## __ENTER(void) { \
805 if (TRACE_ATLEAST(level)) { \
806 __ast_trace(__FILE__, __LINE__, __trace_funcname, AST_TRACE_INDENT_INC_AFTER, 0, " " __VA_ARGS__); \
810 int __scopevar ## __LINE__ ## __RETURN __attribute__((unused)) = __scopevar ## __LINE__ ## __ENTER()
824#define SCOPE_ENTER(level, ...) \
825 int __scope_level = level; \
826 int __scope_task = 0; \
827 ast_debug(__scope_level, " " __VA_ARGS__); \
828 if (TRACE_ATLEAST(level)) { \
829 __ast_trace(_TRACE_PREFIX_, AST_TRACE_INDENT_INC_AFTER, 0, " " __VA_ARGS__); \
832#define SCOPE_ENTER_TASK(level, indent, ...) \
833 int __scope_level = level; \
834 int __scope_task = 1; \
835 ast_debug(__scope_level, " " __VA_ARGS__); \
836 if (TRACE_ATLEAST(level)) { \
837 __ast_trace(_TRACE_PREFIX_, AST_TRACE_INDENT_PROVIDED, indent, " " __VA_ARGS__); \
864#define SCOPE_CALL(level, __funcname, ...) \
866 ast_trace(level, "--> Calling %s\n", #__funcname); \
867 __funcname(__VA_ARGS__); \
868 ast_trace(level, "<-- Return from %s\n", #__funcname); \
898#define SCOPE_CALL_WITH_RESULT(level, __type, __funcname, ...) \
901 ast_trace(level, "--> Calling %s\n", #__funcname); \
902 __var = __funcname(__VA_ARGS__); \
903 ast_trace(level, "<-- Return from %s\n", #__funcname) \
907#define SCOPE_CALL_WITH_INT_RESULT(level, __funcname, ...) \
908 SCOPE_CALL_WITH_RESULT(level, int, __funcname, __VA_ARGS__)
918#define SCOPE_EXIT(...) \
919 ast_debug(__scope_level, " " __VA_ARGS__); \
920 if (TRACE_ATLEAST(__scope_level)) { \
921 __ast_trace(_TRACE_PREFIX_, AST_TRACE_INDENT_DEC_BEFORE, 0, " " __VA_ARGS__); \
922 if (__scope_task) { \
923 _ast_trace_set_indent(0); \
947#define SCOPE_EXIT_EXPR(__expr, ...) \
948 ast_debug(__scope_level, " " __VA_ARGS__); \
949 if (TRACE_ATLEAST(__scope_level)) { \
950 __ast_trace(_TRACE_PREFIX_, AST_TRACE_INDENT_DEC_BEFORE, 0, " " __VA_ARGS__); \
951 if (__scope_task) { \
952 _ast_trace_set_indent(0); \
966#define SCOPE_EXIT_RTN(...) \
967 ast_debug(__scope_level, " " __VA_ARGS__); \
968 if (TRACE_ATLEAST(__scope_level)) { \
969 __ast_trace(_TRACE_PREFIX_, AST_TRACE_INDENT_DEC_BEFORE, 0, " " __VA_ARGS__); \
970 if (__scope_task) { \
971 _ast_trace_set_indent(0); \
986#define SCOPE_EXIT_RTN_VALUE(__return_value, ...) \
987 ast_debug(__scope_level, " " __VA_ARGS__); \
988 if (TRACE_ATLEAST(__scope_level)) { \
989 __ast_trace(_TRACE_PREFIX_, AST_TRACE_INDENT_DEC_BEFORE, 0, " " __VA_ARGS__); \
990 if (__scope_task) { \
991 _ast_trace_set_indent(0); \
994 return(__return_value)
997#define ast_trace_raw(level, indent_type, ...) \
998 ast_debug(level < 0 ? __scope_level : level, " " __VA_ARGS__)
1000#define ast_trace(level, ...) \
1001 ast_debug(level < 0 ? __scope_level : level, " " __VA_ARGS__)
1003#define ast_trace_get_indent() (0)
1004#define ast_trace_set_indent(indent)
1005#define ast_trace_inc_indent()
1006#define ast_trace_dec_indent()
1007#define SCOPE_TRACE(__level, ...)
1009#define SCOPE_ENTER(level, ...) \
1010 int __scope_level = level; \
1011 ast_debug(level, " " __VA_ARGS__)
1013#define SCOPE_ENTER_TASK(level, indent, ...) \
1014 int __scope_level = level; \
1015 ast_debug(level, " " __VA_ARGS__)
1017#define SCOPE_CALL(level, __funcname, ...) \
1018 __funcname(__VA_ARGS__)
1020#define SCOPE_CALL_WITH_RESULT(level, __var, __funcname, ...) \
1021 __var = __funcname(__VA_ARGS__)
1023#define SCOPE_CALL_WITH_INT_RESULT(level, __funcname, ...) \
1024 __funcname(__VA_ARGS__)
1026#define SCOPE_EXIT(...) \
1027 ast_debug(__scope_level, " " __VA_ARGS__)
1029#define SCOPE_EXIT_EXPR(__expr, ...) \
1030 ast_debug(__scope_level, " " __VA_ARGS__); \
1033#define SCOPE_EXIT_RTN(...) \
1034 ast_debug(__scope_level, " " __VA_ARGS__); \
1037#define SCOPE_EXIT_RTN_VALUE(__return_value, ...) \
1038 ast_debug(__scope_level, " " __VA_ARGS__); \
1039 return __return_value
1048#define SCOPE_EXIT_LOG(__log_level, ...) \
1050 ast_log(__log_level, " " __VA_ARGS__); \
1051 SCOPE_EXIT(" " __VA_ARGS__); \
1054#define SCOPE_EXIT_LOG_RTN(__log_level, ...) \
1056 ast_log(__log_level, " " __VA_ARGS__); \
1057 SCOPE_EXIT_RTN(" " __VA_ARGS__); \
1060#define SCOPE_EXIT_LOG_RTN_VALUE(__value, __log_level, ...) \
1062 ast_log(__log_level, " " __VA_ARGS__); \
1063 SCOPE_EXIT_RTN_VALUE(__value, " " __VA_ARGS__); \
1066#define SCOPE_EXIT_LOG_EXPR(__expr, __log_level, ...) \
1068 ast_log(__log_level, " " __VA_ARGS__); \
1069 SCOPE_EXIT_EXPR(__expr, " " __VA_ARGS__); \
1072#define ast_trace_log(__level, __log_level, ...) \
1074 ast_log(__log_level, " " __VA_ARGS__); \
1075 ast_trace(__level < 0 ? __scope_level : __level, " " __VA_ARGS__); \
1079#if defined(__cplusplus) || defined(c_plusplus)
#define attribute_warn_unused_result
void ast_init_logger_for_socket_console(void)
load logger.conf configuration for console socket connections
unsigned int ast_trace_get_by_module(const char *module)
Get the trace level for a module.
ast_trace_indent_type
Controls if and when indenting is applied.
@ AST_TRACE_INDENT_INC_BEFORE
@ AST_TRACE_INDENT_PROVIDED
@ AST_TRACE_INDENT_INC_AFTER
@ AST_TRACE_INDENT_DEC_BEFORE
@ AST_TRACE_INDENT_DEC_AFTER
int ast_logger_get_dynamic_level(const char *name)
Retrieve dynamic logging level id.
int ast_logger_get_queue_limit(void)
Get the maximum number of messages allowed in the processing queue.
void __ast_verbose_ap(const char *file, int line, const char *func, int level, ast_callid callid, const char *fmt, va_list ap)
int ast_logger_rotate_channel(const char *log_channel)
Rotate the specified log channel.
void ast_callid_strnprint(char *buffer, size_t buffer_size, ast_callid callid)
copy a string representation of the callid into a target string
int ast_logger_rotate(void)
Reload logger while rotating log files.
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...
void ast_verb_console_unregister(void)
Unregister this thread's console verbosity level.
int ast_logger_create_channel(const char *log_channel, const char *components)
Create a log channel.
void ast_verb_console_register(int *level)
Register this thread's console verbosity level pointer.
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...
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.
int ast_logger_remove_channel(const char *log_channel)
Delete the specified log channel.
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.
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...
int ast_is_logger_initialized(void)
Test if logger is initialized.
void ast_console_toggle_mute(int fd, int silent)
mute or unmute a console from logging
ast_callid ast_read_threadstorage_callid(void)
extracts the callerid from the thread
int ast_callid_threadassoc_add(ast_callid callid)
Adds a known callid to thread storage of the calling thread.
void ast_console_puts_mutable(const char *string, int level)
log the string to the console, and all attached console clients
ast_callid ast_create_callid(void)
factory function to create a new uniquely identifying callid.
void ast_console_puts(const char *string)
write the string to the root console, and all attached network console clients
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_verbose(const char *file, int line, const char *func, int level, const char *fmt,...)
Send a verbose message (based on verbose level)
void ast_log_ap(int level, const char *file, int line, const char *function, const char *fmt, va_list ap)
int ast_register_verbose(void(*verboser)(const char *string)) attribute_warn_unused_result
int ast_callid_threadassoc_remove(void)
Removes callid from thread storage of the calling thread.
void ast_queue_log(const char *queuename, const char *callid, const char *agent, const char *event, const char *fmt,...)
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...
int ast_logger_register_level(const char *name)
Register a new logger level.
void ast_logger_set_queue_limit(int queue_limit)
Set the maximum number of messages allowed in the processing queue.
void ast_verb_update(void)
Re-evaluate the system max verbosity level (ast_verb_sys_level).
void ast_child_verbose(int level, const char *fmt,...)
int ast_unregister_verbose(void(*verboser)(const char *string)) attribute_warn_unused_result
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_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_verb_console_get(void)
Get this thread's console verbosity level.
const char * ast_logger_get_dateformat(void)
Get the logger configured date format.
void ast_logger_unregister_level(const char *name)
Unregister a previously registered logger level.
void ast_console_puts_mutable_full(const char *message, int level, int sublevel)
log the string to the console, and all attached console clients
unsigned int ast_debug_get_by_module(const char *module)
Get the debug level for a module.
void ast_log_backtrace(void)
Log a backtrace of the current thread's execution stack to the Asterisk log.
void ast_verb_console_set(int verb_level)
Set this thread's console verbosity level.
Options provided by main asterisk program.