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, ...);
176void __attribute__((format(printf, 5, 6)))
__ast_verbose(const
char *
file,
int line, const
char *func,
int level, const
char *fmt, ...);
188#define ast_verbose(...) __ast_verbose(_A_, -1, __VA_ARGS__)
189#define ast_verbose_callid(callid, ...) __ast_verbose_callid(_A_, -1, callid, __VA_ARGS__)
191void __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);
193void __attribute__((format(printf, 2, 3)))
ast_child_verbose(
int level, const
char *fmt, ...);
200#define VERBOSE_MAGIC2LEVEL(x) (((char) -*(signed char *) (x)) - 1)
201#define VERBOSE_HASMAGIC(x) (*(signed char *) (x) < 0)
247#define LOG_DEBUG __LOG_DEBUG, _A_
252#define AST_LOG_DEBUG __LOG_DEBUG, _A_
258#define LOG_TRACE __LOG_TRACE, _A_
263#define AST_LOG_TRACE __LOG_TRACE, _A_
268#define __LOG_NOTICE 2
269#define LOG_NOTICE __LOG_NOTICE, _A_
274#define AST_LOG_NOTICE __LOG_NOTICE, _A_
279#define __LOG_WARNING 3
280#define LOG_WARNING __LOG_WARNING, _A_
282#ifdef AST_LOG_WARNING
283#undef AST_LOG_WARNING
285#define AST_LOG_WARNING __LOG_WARNING, _A_
291#define LOG_ERROR __LOG_ERROR, _A_
296#define AST_LOG_ERROR __LOG_ERROR, _A_
301#define __LOG_VERBOSE 5
302#define LOG_VERBOSE __LOG_VERBOSE, _A_
304#ifdef AST_LOG_VERBOSE
305#undef AST_LOG_VERBOSE
307#define AST_LOG_VERBOSE __LOG_VERBOSE, _A_
313#define LOG_DTMF __LOG_DTMF, _A_
318#define AST_LOG_DTMF __LOG_DTMF, _A_
320#define NUMLOGLEVELS 32
443#define ast_log_dynamic_level(level, ...) ast_log(level, _A_, __VA_ARGS__)
445#define DEBUG_ATLEAST(level) \
446 (option_debug >= (level) \
447 || (ast_opt_dbg_module \
448 && ((int)ast_debug_get_by_module(AST_MODULE) >= (level) \
449 || (int)ast_debug_get_by_module(__FILE__) >= (level))))
456#define ast_debug(level, ...) \
458 if (DEBUG_ATLEAST(level)) { \
459 ast_log(AST_LOG_DEBUG, __VA_ARGS__); \
465#define VERBOSITY_ATLEAST(level) ((level) <= ast_verb_sys_level)
467#define ast_verb(level, ...) \
469 if (VERBOSITY_ATLEAST(level) ) { \
470 __ast_verbose(_A_, level, __VA_ARGS__); \
474#define ast_verb_callid(level, callid, ...) \
476 if (VERBOSITY_ATLEAST(level) ) { \
477 __ast_verbose_callid(_A_, level, callid, __VA_ARGS__); \
667#define _TRACE_PREFIX_DEFAULT_ _A_
668#ifndef _TRACE_PREFIX_
669#define _TRACE_PREFIX_ _TRACE_PREFIX_DEFAULT_
684#define TRACE_ATLEAST(level) \
685 (option_trace >= (level) \
686 || (ast_opt_trace_module \
687 && ((int)ast_trace_get_by_module(AST_MODULE) >= (level) \
688 || (int)ast_trace_get_by_module(__FILE__) >= (level))))
712void __attribute__((format (printf, 6, 7))) __ast_trace(const
char *
file,
int line, const
char *func,
723#define ast_trace_raw(level, indent_type, ...) \
724 ast_debug(level < 0 ? __scope_level : level, " " __VA_ARGS__); \
725 if (TRACE_ATLEAST(level < 0 ? __scope_level : level)) { \
726 __ast_trace(_TRACE_PREFIX_, indent_type, 0, " " __VA_ARGS__); \
737#define ast_trace(level, ...) \
738 ast_debug(level < 0 ? __scope_level : level, " " __VA_ARGS__); \
739 if (TRACE_ATLEAST(level < 0 ? __scope_level : level)) { \
740 __ast_trace(_TRACE_PREFIX_, AST_TRACE_INDENT_SAME, 0, " " __VA_ARGS__); \
748unsigned long _ast_trace_get_indent(
void);
749#define ast_trace_get_indent() _ast_trace_get_indent()
756void _ast_trace_set_indent(
unsigned long indent);
757#define ast_trace_set_indent(indent) _ast_trace_set_indent(indent)
764unsigned long _ast_trace_inc_indent(
void);
765#define ast_trace_inc_indent() _ast_trace_inc_indent()
772unsigned long _ast_trace_dec_indent(
void);
773#define ast_trace_dec_indent() _ast_trace_dec_indent()
793#define SCOPE_TRACE(level, ...) \
794 const char *__trace_funcname = __PRETTY_FUNCTION__; \
795 auto void __scopevar ## __LINE__ ## __EXIT(void * v); \
796 void __scopevar ## __LINE__ ## __EXIT(void * v __attribute__((unused))) { \
797 if (TRACE_ATLEAST(level)) { \
798 __ast_trace(__FILE__, __LINE__, __trace_funcname, AST_TRACE_INDENT_DEC_BEFORE, 0, " " __VA_ARGS__); \
801 void *__scopevar ## __LINE__ ## __TRACER __attribute__((cleanup(__scopevar ## __LINE__ ## __EXIT))) = (void *) __PRETTY_FUNCTION__ ; \
802 auto int __scopevar ## __LINE__ ## __ENTER(void); \
803 int __scopevar ## __LINE__ ## __ENTER(void) { \
804 if (TRACE_ATLEAST(level)) { \
805 __ast_trace(__FILE__, __LINE__, __trace_funcname, AST_TRACE_INDENT_INC_AFTER, 0, " " __VA_ARGS__); \
809 int __scopevar ## __LINE__ ## __RETURN __attribute__((unused)) = __scopevar ## __LINE__ ## __ENTER()
823#define SCOPE_ENTER(level, ...) \
824 int __scope_level = level; \
825 int __scope_task = 0; \
826 ast_debug(__scope_level, " " __VA_ARGS__); \
827 if (TRACE_ATLEAST(level)) { \
828 __ast_trace(_TRACE_PREFIX_, AST_TRACE_INDENT_INC_AFTER, 0, " " __VA_ARGS__); \
831#define SCOPE_ENTER_TASK(level, indent, ...) \
832 int __scope_level = level; \
833 int __scope_task = 1; \
834 ast_debug(__scope_level, " " __VA_ARGS__); \
835 if (TRACE_ATLEAST(level)) { \
836 __ast_trace(_TRACE_PREFIX_, AST_TRACE_INDENT_PROVIDED, indent, " " __VA_ARGS__); \
863#define SCOPE_CALL(level, __funcname, ...) \
865 ast_trace(level, "--> Calling %s\n", #__funcname); \
866 __funcname(__VA_ARGS__); \
867 ast_trace(level, "<-- Return from %s\n", #__funcname); \
897#define SCOPE_CALL_WITH_RESULT(level, __type, __funcname, ...) \
900 ast_trace(level, "--> Calling %s\n", #__funcname); \
901 __var = __funcname(__VA_ARGS__); \
902 ast_trace(level, "<-- Return from %s\n", #__funcname); \
906#define SCOPE_CALL_WITH_INT_RESULT(level, __funcname, ...) \
907 SCOPE_CALL_WITH_RESULT(level, int, __funcname, __VA_ARGS__)
917#define SCOPE_EXIT(...) \
918 ast_debug(__scope_level, " " __VA_ARGS__); \
919 if (TRACE_ATLEAST(__scope_level)) { \
920 __ast_trace(_TRACE_PREFIX_, AST_TRACE_INDENT_DEC_BEFORE, 0, " " __VA_ARGS__); \
921 if (__scope_task) { \
922 _ast_trace_set_indent(0); \
946#define SCOPE_EXIT_EXPR(__expr, ...) \
947 ast_debug(__scope_level, " " __VA_ARGS__); \
948 if (TRACE_ATLEAST(__scope_level)) { \
949 __ast_trace(_TRACE_PREFIX_, AST_TRACE_INDENT_DEC_BEFORE, 0, " " __VA_ARGS__); \
950 if (__scope_task) { \
951 _ast_trace_set_indent(0); \
965#define SCOPE_EXIT_RTN(...) \
966 ast_debug(__scope_level, " " __VA_ARGS__); \
967 if (TRACE_ATLEAST(__scope_level)) { \
968 __ast_trace(_TRACE_PREFIX_, AST_TRACE_INDENT_DEC_BEFORE, 0, " " __VA_ARGS__); \
969 if (__scope_task) { \
970 _ast_trace_set_indent(0); \
985#define SCOPE_EXIT_RTN_VALUE(__return_value, ...) \
986 ast_debug(__scope_level, " " __VA_ARGS__); \
987 if (TRACE_ATLEAST(__scope_level)) { \
988 __ast_trace(_TRACE_PREFIX_, AST_TRACE_INDENT_DEC_BEFORE, 0, " " __VA_ARGS__); \
989 if (__scope_task) { \
990 _ast_trace_set_indent(0); \
993 return(__return_value)
996#define ast_trace_raw(level, indent_type, ...) \
997 ast_debug(level < 0 ? __scope_level : level, " " __VA_ARGS__)
999#define ast_trace(level, ...) \
1000 ast_debug(level < 0 ? __scope_level : level, " " __VA_ARGS__)
1002#define ast_trace_get_indent() (0)
1003#define ast_trace_set_indent(indent)
1004#define ast_trace_inc_indent()
1005#define ast_trace_dec_indent()
1006#define SCOPE_TRACE(__level, ...)
1008#define SCOPE_ENTER(level, ...) \
1009 int __scope_level = level; \
1010 ast_debug(level, " " __VA_ARGS__)
1012#define SCOPE_ENTER_TASK(level, indent, ...) \
1013 int __scope_level = level; \
1014 ast_debug(level, " " __VA_ARGS__)
1016#define SCOPE_CALL(level, __funcname, ...) \
1017 __funcname(__VA_ARGS__)
1019#define SCOPE_CALL_WITH_RESULT(level, __var, __funcname, ...) \
1020 __funcname(__VA_ARGS__)
1022#define SCOPE_CALL_WITH_INT_RESULT(level, __funcname, ...) \
1023 __funcname(__VA_ARGS__)
1025#define SCOPE_EXIT(...) \
1026 ast_debug(__scope_level, " " __VA_ARGS__)
1028#define SCOPE_EXIT_EXPR(__expr, ...) \
1029 ast_debug(__scope_level, " " __VA_ARGS__); \
1032#define SCOPE_EXIT_RTN(...) \
1033 ast_debug(__scope_level, " " __VA_ARGS__); \
1036#define SCOPE_EXIT_RTN_VALUE(__return_value, ...) \
1037 ast_debug(__scope_level, " " __VA_ARGS__); \
1038 return __return_value
1047#define SCOPE_EXIT_LOG(__log_level, ...) \
1049 ast_log(__log_level, " " __VA_ARGS__); \
1050 SCOPE_EXIT(" " __VA_ARGS__); \
1053#define SCOPE_EXIT_LOG_RTN(__log_level, ...) \
1055 ast_log(__log_level, " " __VA_ARGS__); \
1056 SCOPE_EXIT_RTN(" " __VA_ARGS__); \
1059#define SCOPE_EXIT_LOG_RTN_VALUE(__value, __log_level, ...) \
1061 ast_log(__log_level, " " __VA_ARGS__); \
1062 SCOPE_EXIT_RTN_VALUE(__value, " " __VA_ARGS__); \
1065#define SCOPE_EXIT_LOG_EXPR(__expr, __log_level, ...) \
1067 ast_log(__log_level, " " __VA_ARGS__); \
1068 SCOPE_EXIT_EXPR(__expr, " " __VA_ARGS__); \
1071#define ast_trace_log(__level, __log_level, ...) \
1073 ast_log(__log_level, " " __VA_ARGS__); \
1074 ast_trace(__level < 0 ? __scope_level : __level, " " __VA_ARGS__); \
1078#if defined(__cplusplus) || defined(c_plusplus)
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
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 callid 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_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,...)
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.