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, ...);
198#define VERBOSE_MAGIC2LEVEL(x) (((char) -*(signed char *) (x)) - 1)
199#define VERBOSE_HASMAGIC(x) (*(signed char *) (x) < 0)
245#define LOG_DEBUG __LOG_DEBUG, _A_
250#define AST_LOG_DEBUG __LOG_DEBUG, _A_
256#define LOG_TRACE __LOG_TRACE, _A_
261#define AST_LOG_TRACE __LOG_TRACE, _A_
266#define __LOG_NOTICE 2
267#define LOG_NOTICE __LOG_NOTICE, _A_
272#define AST_LOG_NOTICE __LOG_NOTICE, _A_
277#define __LOG_WARNING 3
278#define LOG_WARNING __LOG_WARNING, _A_
280#ifdef AST_LOG_WARNING
281#undef AST_LOG_WARNING
283#define AST_LOG_WARNING __LOG_WARNING, _A_
289#define LOG_ERROR __LOG_ERROR, _A_
294#define AST_LOG_ERROR __LOG_ERROR, _A_
299#define __LOG_VERBOSE 5
300#define LOG_VERBOSE __LOG_VERBOSE, _A_
302#ifdef AST_LOG_VERBOSE
303#undef AST_LOG_VERBOSE
305#define AST_LOG_VERBOSE __LOG_VERBOSE, _A_
311#define LOG_DTMF __LOG_DTMF, _A_
316#define AST_LOG_DTMF __LOG_DTMF, _A_
318#define NUMLOGLEVELS 32
441#define ast_log_dynamic_level(level, ...) ast_log(level, _A_, __VA_ARGS__)
443#define DEBUG_ATLEAST(level) \
444 (option_debug >= (level) \
445 || (ast_opt_dbg_module \
446 && ((int)ast_debug_get_by_module(AST_MODULE) >= (level) \
447 || (int)ast_debug_get_by_module(__FILE__) >= (level))))
454#define ast_debug(level, ...) \
456 if (DEBUG_ATLEAST(level)) { \
457 ast_log(AST_LOG_DEBUG, __VA_ARGS__); \
463#define VERBOSITY_ATLEAST(level) ((level) <= ast_verb_sys_level)
465#define ast_verb(level, ...) \
467 if (VERBOSITY_ATLEAST(level) ) { \
468 __ast_verbose(_A_, level, __VA_ARGS__); \
472#define ast_verb_callid(level, callid, ...) \
474 if (VERBOSITY_ATLEAST(level) ) { \
475 __ast_verbose_callid(_A_, level, callid, __VA_ARGS__); \
665#define _TRACE_PREFIX_DEFAULT_ _A_
666#ifndef _TRACE_PREFIX_
667#define _TRACE_PREFIX_ _TRACE_PREFIX_DEFAULT_
682#define TRACE_ATLEAST(level) \
683 (option_trace >= (level) \
684 || (ast_opt_trace_module \
685 && ((int)ast_trace_get_by_module(AST_MODULE) >= (level) \
686 || (int)ast_trace_get_by_module(__FILE__) >= (level))))
710void __attribute__((format (printf, 6, 7))) __ast_trace(const
char *
file,
int line, const
char *func,
721#define ast_trace_raw(level, indent_type, ...) \
722 ast_debug(level < 0 ? __scope_level : level, " " __VA_ARGS__); \
723 if (TRACE_ATLEAST(level < 0 ? __scope_level : level)) { \
724 __ast_trace(_TRACE_PREFIX_, indent_type, 0, " " __VA_ARGS__); \
735#define ast_trace(level, ...) \
736 ast_debug(level < 0 ? __scope_level : level, " " __VA_ARGS__); \
737 if (TRACE_ATLEAST(level < 0 ? __scope_level : level)) { \
738 __ast_trace(_TRACE_PREFIX_, AST_TRACE_INDENT_SAME, 0, " " __VA_ARGS__); \
746unsigned long _ast_trace_get_indent(
void);
747#define ast_trace_get_indent() _ast_trace_get_indent()
754void _ast_trace_set_indent(
unsigned long indent);
755#define ast_trace_set_indent(indent) _ast_trace_set_indent(indent)
762unsigned long _ast_trace_inc_indent(
void);
763#define ast_trace_inc_indent() _ast_trace_inc_indent()
770unsigned long _ast_trace_dec_indent(
void);
771#define ast_trace_dec_indent() _ast_trace_dec_indent()
791#define SCOPE_TRACE(level, ...) \
792 const char *__trace_funcname = __PRETTY_FUNCTION__; \
793 auto void __scopevar ## __LINE__ ## __EXIT(void * v); \
794 void __scopevar ## __LINE__ ## __EXIT(void * v __attribute__((unused))) { \
795 if (TRACE_ATLEAST(level)) { \
796 __ast_trace(__FILE__, __LINE__, __trace_funcname, AST_TRACE_INDENT_DEC_BEFORE, 0, " " __VA_ARGS__); \
799 void *__scopevar ## __LINE__ ## __TRACER __attribute__((cleanup(__scopevar ## __LINE__ ## __EXIT))) = (void *) __PRETTY_FUNCTION__ ; \
800 auto int __scopevar ## __LINE__ ## __ENTER(void); \
801 int __scopevar ## __LINE__ ## __ENTER(void) { \
802 if (TRACE_ATLEAST(level)) { \
803 __ast_trace(__FILE__, __LINE__, __trace_funcname, AST_TRACE_INDENT_INC_AFTER, 0, " " __VA_ARGS__); \
807 int __scopevar ## __LINE__ ## __RETURN __attribute__((unused)) = __scopevar ## __LINE__ ## __ENTER()
821#define SCOPE_ENTER(level, ...) \
822 int __scope_level = level; \
823 int __scope_task = 0; \
824 ast_debug(__scope_level, " " __VA_ARGS__); \
825 if (TRACE_ATLEAST(level)) { \
826 __ast_trace(_TRACE_PREFIX_, AST_TRACE_INDENT_INC_AFTER, 0, " " __VA_ARGS__); \
829#define SCOPE_ENTER_TASK(level, indent, ...) \
830 int __scope_level = level; \
831 int __scope_task = 1; \
832 ast_debug(__scope_level, " " __VA_ARGS__); \
833 if (TRACE_ATLEAST(level)) { \
834 __ast_trace(_TRACE_PREFIX_, AST_TRACE_INDENT_PROVIDED, indent, " " __VA_ARGS__); \
861#define SCOPE_CALL(level, __funcname, ...) \
863 ast_trace(level, "--> Calling %s\n", #__funcname); \
864 __funcname(__VA_ARGS__); \
865 ast_trace(level, "<-- Return from %s\n", #__funcname); \
895#define SCOPE_CALL_WITH_RESULT(level, __type, __funcname, ...) \
898 ast_trace(level, "--> Calling %s\n", #__funcname); \
899 __var = __funcname(__VA_ARGS__); \
900 ast_trace(level, "<-- Return from %s\n", #__funcname); \
904#define SCOPE_CALL_WITH_INT_RESULT(level, __funcname, ...) \
905 SCOPE_CALL_WITH_RESULT(level, int, __funcname, __VA_ARGS__)
915#define SCOPE_EXIT(...) \
916 ast_debug(__scope_level, " " __VA_ARGS__); \
917 if (TRACE_ATLEAST(__scope_level)) { \
918 __ast_trace(_TRACE_PREFIX_, AST_TRACE_INDENT_DEC_BEFORE, 0, " " __VA_ARGS__); \
919 if (__scope_task) { \
920 _ast_trace_set_indent(0); \
944#define SCOPE_EXIT_EXPR(__expr, ...) \
945 ast_debug(__scope_level, " " __VA_ARGS__); \
946 if (TRACE_ATLEAST(__scope_level)) { \
947 __ast_trace(_TRACE_PREFIX_, AST_TRACE_INDENT_DEC_BEFORE, 0, " " __VA_ARGS__); \
948 if (__scope_task) { \
949 _ast_trace_set_indent(0); \
963#define SCOPE_EXIT_RTN(...) \
964 ast_debug(__scope_level, " " __VA_ARGS__); \
965 if (TRACE_ATLEAST(__scope_level)) { \
966 __ast_trace(_TRACE_PREFIX_, AST_TRACE_INDENT_DEC_BEFORE, 0, " " __VA_ARGS__); \
967 if (__scope_task) { \
968 _ast_trace_set_indent(0); \
983#define SCOPE_EXIT_RTN_VALUE(__return_value, ...) \
984 ast_debug(__scope_level, " " __VA_ARGS__); \
985 if (TRACE_ATLEAST(__scope_level)) { \
986 __ast_trace(_TRACE_PREFIX_, AST_TRACE_INDENT_DEC_BEFORE, 0, " " __VA_ARGS__); \
987 if (__scope_task) { \
988 _ast_trace_set_indent(0); \
991 return(__return_value)
994#define ast_trace_raw(level, indent_type, ...) \
995 ast_debug(level < 0 ? __scope_level : level, " " __VA_ARGS__)
997#define ast_trace(level, ...) \
998 ast_debug(level < 0 ? __scope_level : level, " " __VA_ARGS__)
1000#define ast_trace_get_indent() (0)
1001#define ast_trace_set_indent(indent)
1002#define ast_trace_inc_indent()
1003#define ast_trace_dec_indent()
1004#define SCOPE_TRACE(__level, ...)
1006#define SCOPE_ENTER(level, ...) \
1007 int __scope_level = level; \
1008 ast_debug(level, " " __VA_ARGS__)
1010#define SCOPE_ENTER_TASK(level, indent, ...) \
1011 int __scope_level = level; \
1012 ast_debug(level, " " __VA_ARGS__)
1014#define SCOPE_CALL(level, __funcname, ...) \
1015 __funcname(__VA_ARGS__)
1017#define SCOPE_CALL_WITH_RESULT(level, __var, __funcname, ...) \
1018 __funcname(__VA_ARGS__)
1020#define SCOPE_CALL_WITH_INT_RESULT(level, __funcname, ...) \
1021 __funcname(__VA_ARGS__)
1023#define SCOPE_EXIT(...) \
1024 ast_debug(__scope_level, " " __VA_ARGS__)
1026#define SCOPE_EXIT_EXPR(__expr, ...) \
1027 ast_debug(__scope_level, " " __VA_ARGS__); \
1030#define SCOPE_EXIT_RTN(...) \
1031 ast_debug(__scope_level, " " __VA_ARGS__); \
1034#define SCOPE_EXIT_RTN_VALUE(__return_value, ...) \
1035 ast_debug(__scope_level, " " __VA_ARGS__); \
1036 return __return_value
1045#define SCOPE_EXIT_LOG(__log_level, ...) \
1047 ast_log(__log_level, " " __VA_ARGS__); \
1048 SCOPE_EXIT(" " __VA_ARGS__); \
1051#define SCOPE_EXIT_LOG_RTN(__log_level, ...) \
1053 ast_log(__log_level, " " __VA_ARGS__); \
1054 SCOPE_EXIT_RTN(" " __VA_ARGS__); \
1057#define SCOPE_EXIT_LOG_RTN_VALUE(__value, __log_level, ...) \
1059 ast_log(__log_level, " " __VA_ARGS__); \
1060 SCOPE_EXIT_RTN_VALUE(__value, " " __VA_ARGS__); \
1063#define SCOPE_EXIT_LOG_EXPR(__expr, __log_level, ...) \
1065 ast_log(__log_level, " " __VA_ARGS__); \
1066 SCOPE_EXIT_EXPR(__expr, " " __VA_ARGS__); \
1069#define ast_trace_log(__level, __log_level, ...) \
1071 ast_log(__log_level, " " __VA_ARGS__); \
1072 ast_trace(__level < 0 ? __scope_level : __level, " " __VA_ARGS__); \
1076#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 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_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.