Asterisk - The Open Source Telephony Project GIT-master-70eff7f
Loading...
Searching...
No Matches
Macros | Typedefs | Enumerations | Functions | Variables
logger.h File Reference

Support for logging to various files, console and syslog Configuration in file logger.conf. More...

#include "asterisk/options.h"
Include dependency graph for include/asterisk/logger.h:

Go to the source code of this file.

Macros

#define __LOG_DEBUG   0
 
#define __LOG_DTMF   6
 
#define __LOG_ERROR   4
 
#define __LOG_NOTICE   2
 
#define __LOG_TRACE   1
 
#define __LOG_VERBOSE   5
 
#define __LOG_WARNING   3
 
#define _A_   __FILE__, __LINE__, __FUNCTION__
 
#define _TRACE_PREFIX_   _TRACE_PREFIX_DEFAULT_
 
#define _TRACE_PREFIX_DEFAULT_   _A_
 
#define AST_CALLID_BUFFER_LENGTH   13
 
#define ast_debug(level, ...)
 Log a DEBUG message.
 
#define AST_LOG_DEBUG   __LOG_DEBUG, _A_
 
#define AST_LOG_DTMF   __LOG_DTMF, _A_
 
#define ast_log_dynamic_level(level, ...)   ast_log(level, _A_, __VA_ARGS__)
 Send a log message to a dynamically registered log level.
 
#define AST_LOG_ERROR   __LOG_ERROR, _A_
 
#define AST_LOG_NOTICE   __LOG_NOTICE, _A_
 
#define AST_LOG_TRACE   __LOG_TRACE, _A_
 
#define AST_LOG_VERBOSE   __LOG_VERBOSE, _A_
 
#define AST_LOG_WARNING   __LOG_WARNING, _A_
 
#define ast_trace(level, ...)    ast_debug(level < 0 ? __scope_level : level, " " __VA_ARGS__)
 
#define ast_trace_dec_indent()
 
#define ast_trace_get_indent()   (0)
 
#define ast_trace_inc_indent()
 
#define ast_trace_log(__level, __log_level, ...)
 
#define ast_trace_raw(level, indent_type, ...)    ast_debug(level < 0 ? __scope_level : level, " " __VA_ARGS__)
 
#define ast_trace_set_indent(indent)
 
#define ast_verb(level, ...)
 
#define ast_verb_callid(level, callid, ...)
 
#define ast_verbose(...)   __ast_verbose(_A_, -1, __VA_ARGS__)
 
#define ast_verbose_callid(callid, ...)   __ast_verbose_callid(_A_, -1, callid, __VA_ARGS__)
 
#define DEBUG_ATLEAST(level)
 
#define DEBUG_M(a)
 
#define EVENTLOG   "event_log"
 
#define LOG_DEBUG   __LOG_DEBUG, _A_
 
#define LOG_DTMF   __LOG_DTMF, _A_
 
#define LOG_ERROR   __LOG_ERROR, _A_
 
#define LOG_NOTICE   __LOG_NOTICE, _A_
 
#define LOG_TRACE   __LOG_TRACE, _A_
 
#define LOG_VERBOSE   __LOG_VERBOSE, _A_
 
#define LOG_WARNING   __LOG_WARNING, _A_
 
#define NUMLOGLEVELS   32
 
#define QUEUELOG   "queue_log"
 
#define SCOPE_CALL(level, __funcname, ...)    __funcname(__VA_ARGS__)
 
#define SCOPE_CALL_WITH_INT_RESULT(level, __funcname, ...)    __funcname(__VA_ARGS__)
 
#define SCOPE_CALL_WITH_RESULT(level, __var, __funcname, ...)    __funcname(__VA_ARGS__)
 
#define SCOPE_ENTER(level, ...)
 
#define SCOPE_ENTER_TASK(level, indent, ...)
 
#define SCOPE_EXIT(...)    ast_debug(__scope_level, " " __VA_ARGS__)
 
#define SCOPE_EXIT_EXPR(__expr, ...)
 
#define SCOPE_EXIT_LOG(__log_level, ...)
 
#define SCOPE_EXIT_LOG_EXPR(__expr, __log_level, ...)
 
#define SCOPE_EXIT_LOG_RTN(__log_level, ...)
 
#define SCOPE_EXIT_LOG_RTN_VALUE(__value, __log_level, ...)
 
#define SCOPE_EXIT_RTN(...)
 
#define SCOPE_EXIT_RTN_VALUE(__return_value, ...)
 
#define SCOPE_TRACE(__level, ...)
 
#define TRACE_ATLEAST(level)
 
#define VERBOSE_HASMAGIC(x)   (*(signed char *) (x) < 0)
 
#define VERBOSE_MAGIC2LEVEL(x)   (((char) -*(signed char *) (x)) - 1)
 
#define VERBOSE_PREFIX_1   " "
 
#define VERBOSE_PREFIX_10   " > "
 
#define VERBOSE_PREFIX_2   " == "
 
#define VERBOSE_PREFIX_3   " -- "
 
#define VERBOSE_PREFIX_4   " > "
 
#define VERBOSE_PREFIX_5   " > "
 
#define VERBOSE_PREFIX_6   " > "
 
#define VERBOSE_PREFIX_7   " > "
 
#define VERBOSE_PREFIX_8   " > "
 
#define VERBOSE_PREFIX_9   " > "
 
#define VERBOSITY_ATLEAST(level)   ((level) <= ast_verb_sys_level)
 

Typedefs

typedef unsigned int ast_callid
 

Enumerations

enum  ast_logger_results { AST_LOGGER_SUCCESS = 0 , AST_LOGGER_FAILURE = 1 , AST_LOGGER_DECLINE = -1 , AST_LOGGER_ALLOC_ERROR = -2 }
 
enum  ast_trace_indent_type {
  AST_TRACE_INDENT_SAME = 0 , AST_TRACE_INDENT_INC_BEFORE , AST_TRACE_INDENT_INC_AFTER , AST_TRACE_INDENT_DEC_BEFORE ,
  AST_TRACE_INDENT_DEC_AFTER , AST_TRACE_INDENT_PROVIDED , AST_TRACE_INDENT_NONE
}
 Controls if and when indenting is applied. More...
 

Functions

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_verbose_ap (const char *file, int line, const char *func, int level, ast_callid callid, const char *fmt, va_list ap)
 
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_callid_strnprint (char *buffer, size_t buffer_size, ast_callid callid)
 copy a string representation of the callid into a target string
 
int ast_callid_threadassoc_add (ast_callid callid)
 Adds a known callid to thread storage of the calling thread.
 
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 there.
 
int ast_callid_threadassoc_remove (void)
 Removes callid from thread storage of the calling thread.
 
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 be created, bound to the thread, and a reference to it will be stored.
 
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 created by threadstorage_auto, unbinds the callid from the threadstorage.
 
void ast_child_verbose (int level, const char *fmt,...)
 
void ast_console_puts (const char *string)
 write the string to the root console, and all attached network console clients
 
void ast_console_puts_mutable (const char *string, int level)
 log the string to the console, and all attached console clients
 
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_console_toggle_loglevel (int fd, int level, int state)
 enables or disables logging of a specified level to the console
 
void ast_console_toggle_mute (int fd, int silent)
 mute or unmute a console from logging
 
ast_callid ast_create_callid (void)
 factory function to create a new uniquely identifying callid.
 
unsigned int ast_debug_get_by_module (const char *module)
 Get the debug level for a module.
 
void ast_init_logger_for_socket_console (void)
 load logger.conf configuration for console socket connections
 
int ast_is_logger_initialized (void)
 Test if logger is initialized.
 
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 invoke it would be something like this: ast_log(AST_LOG_WHATEVER, "Problem with the %s Captain. We should get some more. Will %d be enough?\n", "flux capacitor", 10); where WHATEVER is one of ERROR, DEBUG, EVENT, NOTICE, or WARNING depending on which log you wish to output to. These are implemented as macros, that will provide the function with the needed arguments.
 
void ast_log_ap (int level, const char *file, int line, const char *function, const char *fmt, va_list ap)
 
void ast_log_backtrace (void)
 Log a backtrace of the current thread's execution stack to the Asterisk log.
 
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 functionally identical to the above logger function, it just include a call_id argument as well. If NULL is specified here, no attempt will be made to join the log message with a call_id.
 
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_create_channel (const char *log_channel, const char *components)
 Create a 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.
 
const char * ast_logger_get_dateformat (void)
 Get the logger configured date format.
 
int ast_logger_get_dynamic_level (const char *name)
 Retrieve dynamic logging level id.
 
int ast_logger_get_over_threshold_queue_limit (void)
 Get the over threshold maximum number of messages allowed in the processing queue.
 
int ast_logger_get_queue_limit (void)
 Get 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_remove_channel (const char *log_channel)
 Delete the specified log channel.
 
int ast_logger_rotate (void)
 Reload logger while rotating log files.
 
int ast_logger_rotate_channel (const char *log_channel)
 Rotate the specified log channel.
 
void ast_logger_set_over_threshold_queue_limit (int limit)
 Set the threshold for the maximum number of WARNING/ERROR messages allowed in the processing queue that can exceed the logger queue's threshold. This acts as a buffer for WARNING/ERROR messages so that we can continue to queue them while discarding other message types. This threshold sits on top of the logger queue's message threshold, so the actual queue size will be the logger queue threshold PLUS this threshold.
 
void ast_logger_set_queue_limit (int queue_limit)
 Set the maximum number of messages allowed in the processing queue.
 
void ast_logger_unregister_level (const char *name)
 Unregister a previously registered logger level.
 
void ast_queue_log (const char *queuename, const char *callid, const char *agent, const char *event, const char *fmt,...)
 
ast_callid ast_read_threadstorage_callid (void)
 extracts the callid from the thread
 
unsigned int ast_trace_get_by_module (const char *module)
 Get the trace level for a module.
 
int ast_verb_console_get (void)
 Get this thread's console verbosity level.
 
void ast_verb_console_register (int *level)
 Register this thread's console verbosity level pointer.
 
void ast_verb_console_set (int verb_level)
 Set this thread's console verbosity level.
 
void ast_verb_console_unregister (void)
 Unregister this thread's console verbosity level.
 
void ast_verb_update (void)
 Re-evaluate the system max verbosity level (ast_verb_sys_level).
 

Variables

int ast_verb_sys_level
 

Detailed Description

Support for logging to various files, console and syslog Configuration in file logger.conf.

Definition in file include/asterisk/logger.h.

Macro Definition Documentation

◆ __LOG_DEBUG

#define __LOG_DEBUG   0

Definition at line 246 of file include/asterisk/logger.h.

◆ __LOG_DTMF

#define __LOG_DTMF   6

Definition at line 312 of file include/asterisk/logger.h.

◆ __LOG_ERROR

#define __LOG_ERROR   4

Definition at line 290 of file include/asterisk/logger.h.

◆ __LOG_NOTICE

#define __LOG_NOTICE   2

Definition at line 268 of file include/asterisk/logger.h.

◆ __LOG_TRACE

#define __LOG_TRACE   1

Definition at line 257 of file include/asterisk/logger.h.

◆ __LOG_VERBOSE

#define __LOG_VERBOSE   5

Definition at line 301 of file include/asterisk/logger.h.

◆ __LOG_WARNING

#define __LOG_WARNING   3

Definition at line 279 of file include/asterisk/logger.h.

◆ _A_

#define _A_   __FILE__, __LINE__, __FUNCTION__

Definition at line 42 of file include/asterisk/logger.h.

◆ AST_CALLID_BUFFER_LENGTH

#define AST_CALLID_BUFFER_LENGTH   13

Definition at line 55 of file include/asterisk/logger.h.

◆ ast_debug

#define ast_debug (   level,
  ... 
)
Value:
do { \
if (DEBUG_ATLEAST(level)) { \
ast_log(AST_LOG_DEBUG, __VA_ARGS__); \
} \
} while (0)
#define DEBUG_ATLEAST(level)
#define AST_LOG_DEBUG

Log a DEBUG message.

Parameters
levelThe minimum value of option_debug for this message to get logged
Examples
app_skel.c.

Definition at line 456 of file include/asterisk/logger.h.

457 { \
458 if (DEBUG_ATLEAST(level)) { \
459 ast_log(AST_LOG_DEBUG, __VA_ARGS__); \
460 } \
461 } while (0)

◆ AST_LOG_DEBUG

#define AST_LOG_DEBUG   __LOG_DEBUG, _A_

Definition at line 252 of file include/asterisk/logger.h.

◆ AST_LOG_DTMF

#define AST_LOG_DTMF   __LOG_DTMF, _A_

Definition at line 318 of file include/asterisk/logger.h.

◆ ast_log_dynamic_level

#define ast_log_dynamic_level (   level,
  ... 
)    ast_log(level, _A_, __VA_ARGS__)

Send a log message to a dynamically registered log level.

Parameters
levelThe log level to send the message to

Like ast_log, the log message may include printf-style formats, and the data for these must be provided as additional parameters after the log message.

Since
1.8

Definition at line 443 of file include/asterisk/logger.h.

◆ AST_LOG_ERROR

#define AST_LOG_ERROR   __LOG_ERROR, _A_

Definition at line 296 of file include/asterisk/logger.h.

◆ AST_LOG_NOTICE

#define AST_LOG_NOTICE   __LOG_NOTICE, _A_

Definition at line 274 of file include/asterisk/logger.h.

◆ AST_LOG_TRACE

#define AST_LOG_TRACE   __LOG_TRACE, _A_

Definition at line 263 of file include/asterisk/logger.h.

◆ AST_LOG_VERBOSE

#define AST_LOG_VERBOSE   __LOG_VERBOSE, _A_

Definition at line 307 of file include/asterisk/logger.h.

◆ AST_LOG_WARNING

#define AST_LOG_WARNING   __LOG_WARNING, _A_

Definition at line 285 of file include/asterisk/logger.h.

◆ ast_verb

#define ast_verb (   level,
  ... 
)
Value:
do { \
if (VERBOSITY_ATLEAST(level) ) { \
__ast_verbose(_A_, level, __VA_ARGS__); \
} \
} while (0)
#define _A_
#define VERBOSITY_ATLEAST(level)

Definition at line 467 of file include/asterisk/logger.h.

468 { \
469 if (VERBOSITY_ATLEAST(level) ) { \
470 __ast_verbose(_A_, level, __VA_ARGS__); \
471 } \
472 } while (0)

◆ ast_verb_callid

#define ast_verb_callid (   level,
  callid,
  ... 
)
Value:
do { \
if (VERBOSITY_ATLEAST(level) ) { \
__ast_verbose_callid(_A_, level, callid, __VA_ARGS__); \
} \
} while (0)

Definition at line 474 of file include/asterisk/logger.h.

475 { \
476 if (VERBOSITY_ATLEAST(level) ) { \
477 __ast_verbose_callid(_A_, level, callid, __VA_ARGS__); \
478 } \
479 } while (0)

◆ ast_verbose

#define ast_verbose (   ...)    __ast_verbose(_A_, -1, __VA_ARGS__)

Definition at line 188 of file include/asterisk/logger.h.

◆ ast_verbose_callid

#define ast_verbose_callid (   callid,
  ... 
)    __ast_verbose_callid(_A_, -1, callid, __VA_ARGS__)

Definition at line 189 of file include/asterisk/logger.h.

◆ DEBUG_ATLEAST

#define DEBUG_ATLEAST (   level)
Value:
(option_debug >= (level) \
&& ((int)ast_debug_get_by_module(AST_MODULE) >= (level) \
|| (int)ast_debug_get_by_module(__FILE__) >= (level))))
#define AST_MODULE
int option_debug
Definition options.c:70
unsigned int ast_debug_get_by_module(const char *module)
Get the debug level for a module.
Definition main/cli.c:139
#define ast_opt_dbg_module
Definition options.h:138

Definition at line 445 of file include/asterisk/logger.h.

◆ DEBUG_M

#define DEBUG_M (   a)
Value:
{ \
a; \
}
static struct test_val a

Definition at line 38 of file include/asterisk/logger.h.

38 { \
39 a; \
40}

◆ EVENTLOG

#define EVENTLOG   "event_log"

Definition at line 35 of file include/asterisk/logger.h.

◆ LOG_DEBUG

#define LOG_DEBUG   __LOG_DEBUG, _A_

Definition at line 247 of file include/asterisk/logger.h.

◆ LOG_DTMF

#define LOG_DTMF   __LOG_DTMF, _A_

Definition at line 313 of file include/asterisk/logger.h.

◆ LOG_ERROR

#define LOG_ERROR   __LOG_ERROR, _A_
Examples
app_skel.c.

Definition at line 291 of file include/asterisk/logger.h.

◆ LOG_NOTICE

#define LOG_NOTICE   __LOG_NOTICE, _A_

Definition at line 269 of file include/asterisk/logger.h.

◆ LOG_TRACE

#define LOG_TRACE   __LOG_TRACE, _A_

Definition at line 258 of file include/asterisk/logger.h.

◆ LOG_VERBOSE

#define LOG_VERBOSE   __LOG_VERBOSE, _A_

Definition at line 302 of file include/asterisk/logger.h.

◆ LOG_WARNING

#define LOG_WARNING   __LOG_WARNING, _A_
Examples
app_skel.c.

Definition at line 280 of file include/asterisk/logger.h.

◆ NUMLOGLEVELS

#define NUMLOGLEVELS   32

Definition at line 320 of file include/asterisk/logger.h.

◆ QUEUELOG

#define QUEUELOG   "queue_log"

Definition at line 36 of file include/asterisk/logger.h.

◆ VERBOSE_HASMAGIC

#define VERBOSE_HASMAGIC (   x)    (*(signed char *) (x) < 0)

Definition at line 201 of file include/asterisk/logger.h.

◆ VERBOSE_MAGIC2LEVEL

#define VERBOSE_MAGIC2LEVEL (   x)    (((char) -*(signed char *) (x)) - 1)

Definition at line 200 of file include/asterisk/logger.h.

◆ VERBOSE_PREFIX_1

#define VERBOSE_PREFIX_1   " "

Definition at line 44 of file include/asterisk/logger.h.

◆ VERBOSE_PREFIX_10

#define VERBOSE_PREFIX_10   " > "

Definition at line 53 of file include/asterisk/logger.h.

◆ VERBOSE_PREFIX_2

#define VERBOSE_PREFIX_2   " == "

Definition at line 45 of file include/asterisk/logger.h.

◆ VERBOSE_PREFIX_3

#define VERBOSE_PREFIX_3   " -- "

Definition at line 46 of file include/asterisk/logger.h.

◆ VERBOSE_PREFIX_4

#define VERBOSE_PREFIX_4   " > "

Definition at line 47 of file include/asterisk/logger.h.

◆ VERBOSE_PREFIX_5

#define VERBOSE_PREFIX_5   " > "

Definition at line 48 of file include/asterisk/logger.h.

◆ VERBOSE_PREFIX_6

#define VERBOSE_PREFIX_6   " > "

Definition at line 49 of file include/asterisk/logger.h.

◆ VERBOSE_PREFIX_7

#define VERBOSE_PREFIX_7   " > "

Definition at line 50 of file include/asterisk/logger.h.

◆ VERBOSE_PREFIX_8

#define VERBOSE_PREFIX_8   " > "

Definition at line 51 of file include/asterisk/logger.h.

◆ VERBOSE_PREFIX_9

#define VERBOSE_PREFIX_9   " > "

Definition at line 52 of file include/asterisk/logger.h.

◆ VERBOSITY_ATLEAST

#define VERBOSITY_ATLEAST (   level)    ((level) <= ast_verb_sys_level)

Definition at line 465 of file include/asterisk/logger.h.

Typedef Documentation

◆ ast_callid

typedef unsigned int ast_callid

Definition at line 96 of file include/asterisk/logger.h.

Enumeration Type Documentation

◆ ast_logger_results

Enumerator
AST_LOGGER_SUCCESS 

Log channel was created or deleted successfully

AST_LOGGER_FAILURE 

Log channel already exists for create or doesn't exist for deletion of log channel

AST_LOGGER_DECLINE 

Log channel request was not accepted

AST_LOGGER_ALLOC_ERROR 

filename allocation error

Definition at line 57 of file include/asterisk/logger.h.

57 {
58 AST_LOGGER_SUCCESS = 0, /*!< Log channel was created or deleted successfully */
59 AST_LOGGER_FAILURE = 1, /*!< Log channel already exists for create or doesn't exist for deletion of log channel */
60 AST_LOGGER_DECLINE = -1, /*!< Log channel request was not accepted */
61 AST_LOGGER_ALLOC_ERROR = -2 /*!< filename allocation error */
62};
@ AST_LOGGER_DECLINE
@ AST_LOGGER_FAILURE
@ AST_LOGGER_SUCCESS
@ AST_LOGGER_ALLOC_ERROR

Function Documentation

◆ __ast_verbose()

void __ast_verbose ( const char *  file,
int  line,
const char *  func,
int  level,
const char *  fmt,
  ... 
)

Send a verbose message (based on verbose level)

This works like ast_log, but prints verbose messages to the console depending on verbosity level set.

ast_verbose(VERBOSE_PREFIX_3 "Whatever %s is happening\n", "nothing");
#define VERBOSE_PREFIX_3
#define ast_verbose(...)

This will print the message to the console if the verbose level is set to a level >= 3

Note the absence of a comma after the VERBOSE_PREFIX_3. This is important. VERBOSE_PREFIX_1 through VERBOSE_PREFIX_10 are defined.

Version
11 added level parameter

Definition at line 2617 of file logger.c.

2618{
2619 ast_callid callid;
2620 va_list ap;
2621
2623
2624 va_start(ap, fmt);
2625 __ast_verbose_ap(file, line, func, level, callid, fmt, ap);
2626 va_end(ap);
2627}
unsigned int ast_callid
void __ast_verbose_ap(const char *file, int line, const char *func, int level, ast_callid callid, const char *fmt, va_list ap)
Definition logger.c:2612
ast_callid ast_read_threadstorage_callid(void)
extracts the callid from the thread
Definition logger.c:2287

References __ast_verbose_ap(), and ast_read_threadstorage_callid().

◆ __ast_verbose_ap()

void __ast_verbose_ap ( const char *  file,
int  line,
const char *  func,
int  level,
ast_callid  callid,
const char *  fmt,
va_list  ap 
)

Definition at line 2612 of file logger.c.

2613{
2614 ast_log_full(__LOG_VERBOSE, level, file, line, func, callid, fmt, ap);
2615}
#define __LOG_VERBOSE
static void ast_log_full(int level, int sublevel, const char *file, int line, const char *function, ast_callid callid, const char *fmt, va_list ap)
send log messages to syslog and/or the console
Definition logger.c:2421

References __LOG_VERBOSE, and ast_log_full().

Referenced by __ast_verbose(), __ast_verbose_callid(), and ast_log_ap().

◆ __ast_verbose_callid()

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.

just like __ast_verbose, only __ast_verbose_callid allows you to specify which callid is being used for the log without needing to bind it to a thread. NULL is a valid argument for this function and will allow you to specify that a log will never display a call id even when there is a call id bound to the thread.

Definition at line 2629 of file logger.c.

2630{
2631 va_list ap;
2632 va_start(ap, fmt);
2633 __ast_verbose_ap(file, line, func, level, callid, fmt, ap);
2634 va_end(ap);
2635}

References __ast_verbose_ap().

◆ ast_callid_strnprint()

void ast_callid_strnprint ( char *  buffer,
size_t  buffer_size,
ast_callid  callid 
)

copy a string representation of the callid into a target string

Parameters
bufferdestination of callid string (should be able to store 13 characters or more)
buffer_sizemaximum writable length of the string (Less than 13 will result in truncation)
callidCallid for which string is being requested

Definition at line 2277 of file logger.c.

2278{
2279 snprintf(buffer, buffer_size, "[C-%08x]", callid);
2280}

Referenced by ast_channel_callid_set(), func_channel_read(), handle_showchan(), and iax_pvt_callid_new().

◆ ast_callid_threadassoc_add()

int ast_callid_threadassoc_add ( ast_callid  callid)

Adds a known callid to thread storage of the calling thread.

Return values
0- success
non-zero- failure

Definition at line 2309 of file logger.c.

2310{
2311 ast_callid *pointing;
2312
2313 pointing = ast_threadstorage_get(&unique_callid, sizeof(*pointing));
2314 if (!pointing) {
2315 return -1;
2316 }
2317
2318 if (*pointing) {
2319 ast_log(LOG_ERROR, "ast_callid_threadassoc_add(C-%08x) on thread "
2320 "already associated with callid [C-%08x].\n", callid, *pointing);
2321 return 1;
2322 }
2323
2324 *pointing = callid;
2325 return 0;
2326}
#define ast_log
Definition astobj2.c:42
#define LOG_ERROR
void * ast_threadstorage_get(struct ast_threadstorage *ts, size_t init_size)
Retrieve thread storage.

References ast_log, ast_threadstorage_get(), and LOG_ERROR.

Referenced by __analog_ss_thread(), __ast_pbx_run(), ast_callid_threadstorage_auto(), async_dial(), attended_transfer_monitor_thread(), bridge_channel_control_thread(), bridge_channel_depart_thread(), bridge_channel_ind_thread(), jingle_action_hook(), jingle_outgoing_hook(), mixmonitor_thread(), socket_process_helper(), and softmix_mixing_thread().

◆ ast_callid_threadassoc_change()

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 there.

Return values
0- success
non-zero- failure

Definition at line 2296 of file logger.c.

2297{
2298 ast_callid *id = ast_threadstorage_get(&unique_callid, sizeof(*id));
2299
2300 if (!id) {
2301 return -1;
2302 }
2303
2304 *id = callid;
2305
2306 return 0;
2307}

References ast_threadstorage_get().

Referenced by autoservice_run(), and bridge_manager_service().

◆ ast_callid_threadassoc_remove()

int ast_callid_threadassoc_remove ( void  )

Removes callid from thread storage of the calling thread.

Return values
0- success
non-zero- failure

Definition at line 2328 of file logger.c.

2329{
2330 ast_callid *pointing;
2331
2332 pointing = ast_threadstorage_get(&unique_callid, sizeof(*pointing));
2333 if (!pointing) {
2334 return -1;
2335 }
2336
2337 if (*pointing) {
2338 *pointing = 0;
2339 return 0;
2340 }
2341
2342 return -1;
2343}

References ast_threadstorage_get().

Referenced by ast_callid_threadstorage_auto_clean(), attended_transfer_monitor_thread(), jingle_action_hook(), jingle_outgoing_hook(), and socket_process().

◆ ast_callid_threadstorage_auto()

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 be created, bound to the thread, and a reference to it will be stored.

Parameters
callidpointer to store the callid
Return values
0- callid was found
1- callid was created
-1- the function failed somehow (presumably memory problems)

Definition at line 2345 of file logger.c.

2346{
2347 ast_callid tmp;
2348
2349 /* Start by trying to see if a callid is available from thread storage */
2351 if (tmp) {
2352 *callid = tmp;
2353 return 0;
2354 }
2355
2356 /* If that failed, try to create a new one and bind it. */
2357 *callid = ast_create_callid();
2358 if (*callid) {
2360 return 1;
2361 }
2362
2363 /* If neither worked, then something must have gone wrong. */
2364 return -1;
2365}
int ast_callid_threadassoc_add(ast_callid callid)
Adds a known callid to thread storage of the calling thread.
Definition logger.c:2309
ast_callid ast_create_callid(void)
factory function to create a new uniquely identifying callid.
Definition logger.c:2282

References ast_callid_threadassoc_add(), ast_create_callid(), and ast_read_threadstorage_callid().

Referenced by __analog_handle_event(), analog_handle_init_event(), dahdi_handle_event(), dahdi_request(), do_monitor(), handle_init_event(), mwi_thread(), and my_new_analog_ast_channel().

◆ ast_callid_threadstorage_auto_clean()

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 created by threadstorage_auto, unbinds the callid from the threadstorage.

Parameters
callidThe callid set by ast_callid_threadstorage_auto
callid_createdThe integer returned through ast_callid_threadstorage_auto

Definition at line 2367 of file logger.c.

2368{
2369 if (callid && callid_created) {
2370 /* If the callid was created rather than simply grabbed from the thread storage, we need to unbind here. */
2372 }
2373}
int ast_callid_threadassoc_remove(void)
Removes callid from thread storage of the calling thread.
Definition logger.c:2328

References ast_callid_threadassoc_remove().

Referenced by __analog_handle_event(), analog_handle_init_event(), dahdi_handle_event(), dahdi_new_callid_clean(), dahdi_request(), do_monitor(), handle_init_event(), and mwi_thread().

◆ ast_child_verbose()

void ast_child_verbose ( int  level,
const char *  fmt,
  ... 
)

Definition at line 929 of file logger.c.

930{
931 char *msg = NULL, *emsg = NULL, *sptr, *eptr;
932 va_list ap, aq;
933 int size;
934
935 va_start(ap, fmt);
936 va_copy(aq, ap);
937 if ((size = vsnprintf(msg, 0, fmt, ap)) < 0) {
938 va_end(ap);
939 va_end(aq);
940 return;
941 }
942 va_end(ap);
943
944 if (!(msg = ast_malloc(size + 1))) {
945 va_end(aq);
946 return;
947 }
948
949 vsnprintf(msg, size + 1, fmt, aq);
950 va_end(aq);
951
952 if (!(emsg = ast_malloc(size * 2 + 1))) {
953 ast_free(msg);
954 return;
955 }
956
957 for (sptr = msg, eptr = emsg; ; sptr++) {
958 if (*sptr == '"') {
959 *eptr++ = '\\';
960 }
961 *eptr++ = *sptr;
962 if (*sptr == '\0') {
963 break;
964 }
965 }
966 ast_free(msg);
967
968 fprintf(stdout, "verbose \"%s\" %d\n", emsg, level);
969 fflush(stdout);
970 ast_free(emsg);
971}
#define ast_free(a)
Definition astmm.h:180
#define ast_malloc(len)
A wrapper for malloc()
Definition astmm.h:191
#define NULL
Definition resample.c:96

References ast_free, ast_malloc, and NULL.

Referenced by launch_script().

◆ ast_console_puts()

void ast_console_puts ( const char *  string)

write the string to the root console, and all attached network console clients

Definition at line 1369 of file asterisk.c.

1370{
1371 /* Send to the root console */
1372 fputs(string, stdout);
1373 fflush(stdout);
1374
1375 /* Send to any network console clients */
1376 ast_network_puts(string);
1377}
static void ast_network_puts(const char *string)
write the string to all attached console clients
Definition asterisk.c:1353

References ast_network_puts().

◆ ast_console_puts_mutable()

void ast_console_puts_mutable ( const char *  string,
int  level 
)

log the string to the console, and all attached console clients

Parameters
stringThe message to write to the console
levelThe log level of the message
Version
1.6.1 added level parameter

log the string to the console, and all attached console clients

Definition at line 1329 of file asterisk.c.

1330{
1331 ast_console_puts_mutable_full(string, level, 0);
1332}
void ast_console_puts_mutable_full(const char *message, int level, int sublevel)
log the string to the console, and all attached console clients
Definition asterisk.c:1336

References ast_console_puts_mutable_full().

Referenced by init_logger_chain(), and make_logchannel().

◆ ast_console_puts_mutable_full()

void ast_console_puts_mutable_full ( const char *  message,
int  level,
int  sublevel 
)

log the string to the console, and all attached console clients

Since
14.0.0
Parameters
messageThe message to write to the console
sublevelIf the log level supports it, the sub-level of the message
levelThe log level of the message

Definition at line 1336 of file asterisk.c.

1337{
1338 /* Send to the root console */
1340
1341 /* Wake up a poll()ing console */
1343 pthread_kill(consolethread, SIGURG);
1344 }
1345
1346 /* Send to any network console clients */
1347 ast_network_puts_mutable(message, level, sublevel);
1348}
static void ast_network_puts_mutable(const char *string, int level, int sublevel)
log the string to all attached network console clients
Definition asterisk.c:1310
static pthread_t consolethread
Definition asterisk.c:392
static int console_print(const char *s)
Definition asterisk.c:2229
#define AST_PTHREADT_NULL
Definition lock.h:73
#define ast_opt_console
Definition options.h:121

References ast_network_puts_mutable(), ast_opt_console, AST_PTHREADT_NULL, console_print(), and consolethread.

Referenced by ast_console_puts_mutable(), and logger_print_normal().

◆ ast_console_toggle_loglevel()

void ast_console_toggle_loglevel ( int  fd,
int  level,
int  state 
)

enables or disables logging of a specified level to the console

Parameters
fdspecifies the index of the console receiving the level change
levelspecifies the index of the logging level being toggled
stateindicates whether logging will be on or off (0 for off, 1 for on)

enables or disables logging of a specified level to the console

Definition at line 1264 of file asterisk.c.

1265{
1266 int x;
1267
1268 if (level >= NUMLOGLEVELS) {
1269 level = NUMLOGLEVELS - 1;
1270 }
1271
1272 for (x = 0;x < AST_MAX_CONNECTS; x++) {
1273 if (fd == consoles[x].fd) {
1274 /*
1275 * Since the logging occurs when levels are false, set to
1276 * flipped iinput because this function accepts 0 as off and 1 as on
1277 */
1278 consoles[x].levels[level] = state ? 0 : 1;
1279 return;
1280 }
1281 }
1282}
#define AST_MAX_CONNECTS
Definition asterisk.c:304
struct console consoles[AST_MAX_CONNECTS]
Definition asterisk.c:351
#define NUMLOGLEVELS
int levels[NUMLOGLEVELS]
Definition asterisk.c:331

References AST_MAX_CONNECTS, consoles, console::levels, and NUMLOGLEVELS.

Referenced by handle_logger_set_level().

◆ ast_console_toggle_mute()

void ast_console_toggle_mute ( int  fd,
int  silent 
)

mute or unmute a console from logging

Definition at line 1287 of file asterisk.c.

1288{
1289 int x;
1290 for (x = 0;x < AST_MAX_CONNECTS; x++) {
1291 if (fd == consoles[x].fd) {
1292 if (consoles[x].mute) {
1293 consoles[x].mute = 0;
1294 if (!silent)
1295 ast_cli(fd, "Console is not muted anymore.\n");
1296 } else {
1297 consoles[x].mute = 1;
1298 if (!silent)
1299 ast_cli(fd, "Console is muted.\n");
1300 }
1301 return;
1302 }
1303 }
1304 ast_cli(fd, "Couldn't find remote console.\n");
1305}
void ast_cli(int fd, const char *fmt,...)
Definition clicompat.c:6
int mute
Definition asterisk.c:328

References ast_cli(), AST_MAX_CONNECTS, consoles, and console::mute.

Referenced by handle_logger_mute().

◆ ast_create_callid()

ast_callid ast_create_callid ( void  )

factory function to create a new uniquely identifying callid.

Returns
The call id

Definition at line 2282 of file logger.c.

2283{
2285}
int ast_atomic_fetchadd_int(volatile int *p, int v)
Atomically add v to *p and return the previous value of *p.
Definition lock.h:764
static volatile int next_unique_callid
Definition logger.c:88

References ast_atomic_fetchadd_int(), and next_unique_callid.

Referenced by __ast_pbx_run(), ast_callid_threadstorage_auto(), iax_pvt_callid_new(), and jingle_alloc().

◆ ast_debug_get_by_module()

unsigned int ast_debug_get_by_module ( const char *  module)

Get the debug level for a module.

Parameters
modulethe name of module
Returns
the debug level

Definition at line 139 of file main/cli.c.

140{
141 struct module_level *ml;
142 unsigned int res = 0;
143
146 if (!strcasecmp(ml->module, module)) {
147 res = ml->level;
148 break;
149 }
150 }
152
153 return res;
154}
#define AST_RWLIST_RDLOCK(head)
Read locks a list.
Definition linkedlists.h:78
#define AST_RWLIST_UNLOCK(head)
Attempts to unlock a read/write based list.
#define AST_LIST_TRAVERSE(head, var, field)
Loops over (traverses) the entries in a list.
static struct module_level_list debug_modules
Definition main/cli.c:108
map a debug or verbose level to a module name
Definition main/cli.c:99
unsigned int level
Definition main/cli.c:100
struct module_level::@356 entry
char module[0]
Definition main/cli.c:102

References AST_LIST_TRAVERSE, AST_RWLIST_RDLOCK, AST_RWLIST_UNLOCK, debug_modules, module_level::entry, module_level::level, and module_level::module.

◆ ast_is_logger_initialized()

int ast_is_logger_initialized ( void  )

Test if logger is initialized.

Return values
trueif the logger is initialized

Definition at line 2164 of file logger.c.

2165{
2166 return logger_initialized;
2167}
static int logger_initialized
Definition logger.c:87

References logger_initialized.

Referenced by check_init().

◆ ast_log()

static 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 invoke it would be something like this: ast_log(AST_LOG_WHATEVER, "Problem with the %s Captain. We should get some more. Will %d be enough?\n", "flux capacitor", 10); where WHATEVER is one of ERROR, DEBUG, EVENT, NOTICE, or WARNING depending on which log you wish to output to. These are implemented as macros, that will provide the function with the needed arguments.

Parameters
levelType of log event
fileWill be provided by the AST_LOG_* macro
lineWill be provided by the AST_LOG_* macro
functionWill be provided by the AST_LOG_* macro
fmtThis is what is important. The format is the same as your favorite breed of printf. You know how that works, right? :-)

Definition at line 130 of file ael_main.c.

131{
132 va_list vars;
133 va_start(vars,fmt);
134
135 printf("LOG: lev:%d file:%s line:%d func: %s ",
136 level, file, line, function);
137 vprintf(fmt, vars);
138 fflush(stdout);
139 va_end(vars);
140}

References ast_log_ap(), logmsg::file, logmsg::function, logmsg::level, and logmsg::line.

◆ ast_log_ap()

void ast_log_ap ( int  level,
const char *  file,
int  line,
const char *  function,
const char *  fmt,
va_list  ap 
)

Definition at line 2529 of file logger.c.

2530{
2531 ast_callid callid;
2532
2534
2535 if (level == __LOG_VERBOSE) {
2536 __ast_verbose_ap(file, line, function, 0, callid, fmt, ap);
2537 } else {
2538 ast_log_full(level, -1, file, line, function, callid, fmt, ap);
2539 }
2540}

References __ast_verbose_ap(), __LOG_VERBOSE, ast_log_full(), ast_read_threadstorage_callid(), logmsg::callid, logmsg::file, logmsg::function, logmsg::level, and logmsg::line.

Referenced by ast_log(), and module_load_error().

◆ ast_log_backtrace()

void ast_log_backtrace ( void  )

Log a backtrace of the current thread's execution stack to the Asterisk log.

Definition at line 2577 of file logger.c.

2578{
2579#ifdef HAVE_BKTR
2580 struct ast_bt *bt;
2581 int i = 0;
2582 struct ast_vector_string *strings;
2583
2584 if (!(bt = ast_bt_create())) {
2585 ast_log(LOG_WARNING, "Unable to allocate space for backtrace structure\n");
2586 return;
2587 }
2588
2589 if ((strings = ast_bt_get_symbols(bt->addresses, bt->num_frames))) {
2590 int count = AST_VECTOR_SIZE(strings);
2591 struct ast_str *buf = ast_str_create(bt->num_frames * 64);
2592
2593 if (buf) {
2594 ast_str_append(&buf, 0, "Got %d backtrace record%c\n", count - 3, count - 3 != 1 ? 's' : ' ');
2595 for (i = 3; i < AST_VECTOR_SIZE(strings); i++) {
2596 ast_str_append(&buf, 0, "#%2d: %s\n", i - 3, AST_VECTOR_GET(strings, i));
2597 }
2599 ast_free(buf);
2600 }
2601
2602 ast_bt_free_symbols(strings);
2603 } else {
2604 ast_log(LOG_ERROR, "Could not allocate memory for backtrace\n");
2605 }
2606 ast_bt_destroy(bt);
2607#else
2608 ast_log(LOG_WARNING, "Must run configure with '--with-execinfo' for stack backtraces.\n");
2609#endif /* defined(HAVE_BKTR) */
2610}
#define ast_bt_free_symbols(string_vector)
Definition backtrace.h:42
#define ast_bt_get_symbols(addresses, num_frames)
Definition backtrace.h:41
#define ast_bt_create()
Definition backtrace.h:39
#define ast_bt_destroy(bt)
Definition backtrace.h:40
char buf[BUFSIZE]
Definition eagi_proxy.c:66
#define __LOG_ERROR
#define LOG_WARNING
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.
Definition logger.c:2542
int ast_str_append(struct ast_str **buf, ssize_t max_len, const char *fmt,...)
Append to a thread local dynamic string.
Definition strings.h:1139
#define ast_str_create(init_len)
Create a malloc'ed dynamic length string.
Definition strings.h:659
char *attribute_pure ast_str_buffer(const struct ast_str *buf)
Returns the string buffer within the ast_str buf.
Definition strings.h:761
A structure to hold backtrace information. This structure provides an easy means to store backtrace i...
Definition backtrace.h:50
void * addresses[AST_MAX_BT_FRAMES]
Definition backtrace.h:52
int num_frames
Definition backtrace.h:54
Support for dynamic strings.
Definition strings.h:623
String vector definitions.
Definition vector.h:55
#define AST_VECTOR_SIZE(vec)
Get the number of elements in a vector.
Definition vector.h:637
#define AST_VECTOR_GET(vec, idx)
Get an element from a vector.
Definition vector.h:708

References __LOG_ERROR, ast_bt::addresses, ast_bt_create, ast_bt_destroy, ast_bt_free_symbols, ast_bt_get_symbols, ast_free, ast_log, ast_log_safe(), ast_str_append(), ast_str_buffer(), ast_str_create, AST_VECTOR_GET, AST_VECTOR_SIZE, buf, LOG_ERROR, LOG_WARNING, NULL, and ast_bt::num_frames.

Referenced by __ast_assert_failed(), ast_json_vpack(), ast_sched_del_nonrunning(), and AST_TEST_DEFINE().

◆ ast_log_callid()

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 functionally identical to the above logger function, it just include a call_id argument as well. If NULL is specified here, no attempt will be made to join the log message with a call_id.

Parameters
levelType of log event
fileWill be provided by the AST_LOG_* macro
lineWill be provided by the AST_LOG_* macro
functionWill be provided by the AST_LOG_* macro
callidThis is the ast_callid that is associated with the log message. May be NULL.
fmtThis is what is important. The format is the same as your favorite breed of printf. You know how that works, right? :-)

Definition at line 2568 of file logger.c.

2569{
2570 va_list ap;
2571 va_start(ap, fmt);
2572 ast_log_full(level, -1, file, line, function, callid, fmt, ap);
2573 va_end(ap);
2574}

References ast_log_full(), logmsg::callid, logmsg::file, logmsg::function, logmsg::level, and logmsg::line.

Referenced by ast_channel_destructor().

◆ ast_log_safe()

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.

Note
This function should be used by all error messages that might be directly or indirectly caused by logging.
See also
ast_log for documentation on the parameters.

Definition at line 2542 of file logger.c.

2543{
2544 va_list ap;
2545 void *recursed = ast_threadstorage_get_ptr(&in_safe_log);
2546 ast_callid callid;
2547
2548 if (recursed) {
2549 return;
2550 }
2551
2552 if (ast_threadstorage_set_ptr(&in_safe_log, &(int) { 1 })) {
2553 /* We've failed to set the flag that protects against
2554 * recursion, so bail. */
2555 return;
2556 }
2557
2559
2560 va_start(ap, fmt);
2561 ast_log_full(level, -1, file, line, function, callid, fmt, ap);
2562 va_end(ap);
2563
2564 /* Clear flag so the next allocation failure can be logged. */
2565 ast_threadstorage_set_ptr(&in_safe_log, NULL);
2566}
int ast_threadstorage_set_ptr(struct ast_threadstorage *ts, void *ptr)
Set a raw pointer from threadstorage.
void * ast_threadstorage_get_ptr(struct ast_threadstorage *ts)
Retrieve a raw pointer from threadstorage.

References ast_log_full(), ast_read_threadstorage_callid(), ast_threadstorage_get_ptr(), ast_threadstorage_set_ptr(), logmsg::callid, logmsg::file, logmsg::function, logmsg::level, logmsg::line, and NULL.

Referenced by __ast_str_helper(), and ast_log_backtrace().

◆ ast_logger_create_channel()

int ast_logger_create_channel ( const char *  log_channel,
const char *  components 
)

Create a log channel.

Parameters
log_channelLog channel to create
componentsLogging config levels to add to the log channel

Definition at line 1517 of file logger.c.

1518{
1519 struct logchannel *chan;
1520
1522 return AST_LOGGER_DECLINE;
1523 }
1524
1526
1527 chan = find_logchannel(log_channel);
1528 if (chan) {
1530 return AST_LOGGER_FAILURE;
1531 }
1532
1533 chan = make_logchannel(log_channel, components, 0, 1);
1534 if (!chan) {
1537 }
1538
1540 global_logmask |= chan->logmask;
1541
1543
1544 return AST_LOGGER_SUCCESS;
1545}
#define AST_RWLIST_WRLOCK(head)
Write locks a list.
Definition linkedlists.h:52
#define AST_RWLIST_INSERT_HEAD
static unsigned int global_logmask
Definition logger.c:85
static struct logchannel * make_logchannel(const char *channel, const char *components, int lineno, int dynamic)
Definition logger.c:659
static struct logchannel * find_logchannel(const char *channel)
Find a particular logger channel by name.
Definition logger.c:643
static force_inline int attribute_pure ast_strlen_zero(const char *s)
Definition strings.h:65
unsigned int logmask
Definition logger.c:147
struct logchannel::@396 list
char components[0]
Definition logger.c:167

References AST_LOGGER_ALLOC_ERROR, AST_LOGGER_DECLINE, AST_LOGGER_FAILURE, AST_LOGGER_SUCCESS, AST_RWLIST_INSERT_HEAD, AST_RWLIST_UNLOCK, AST_RWLIST_WRLOCK, ast_strlen_zero(), logchannel::components, find_logchannel(), global_logmask, logchannel::list, logchannel::logmask, and make_logchannel().

Referenced by ast_ari_asterisk_add_log(), handle_cli_queue_over_threshold_test(), handle_cli_queue_test(), and handle_logger_add_channel().

◆ ast_logger_get_channels()

int ast_logger_get_channels ( int(*)(const char *channel, const char *type, const char *status, const char *configuration, void *data)  logentry,
void *  data 
)

Retrieve the existing log channels.

Parameters
logentryA callback to an updater function
dataData passed into the callback for manipulation

For each of the logging channels, logentry will be executed with the channel file name, log type, status of the log, and configuration levels.

Return values
0on success
1on failure
-2on allocation error

Definition at line 1405 of file logger.c.

1407{
1408 struct logchannel *chan;
1409 struct ast_str *configs = ast_str_create(64);
1410 int res = AST_LOGGER_SUCCESS;
1411
1412 if (!configs) {
1414 }
1415
1417 AST_RWLIST_TRAVERSE(&logchannels, chan, list) {
1418 unsigned int level;
1419
1421
1422 for (level = 0; level < ARRAY_LEN(levels); level++) {
1423 if ((chan->logmask & (1 << level)) && levels[level]) {
1424 ast_str_append(&configs, 0, "%s ", levels[level]);
1425 }
1426 }
1427
1428 res = logentry(chan->filename, chan->type == LOGTYPE_CONSOLE ? "Console" :
1429 (chan->type == LOGTYPE_SYSLOG ? "Syslog" : "File"), chan->disabled ?
1430 "Disabled" : "Enabled", ast_str_buffer(configs), data);
1431
1432 if (res) {
1435 configs = NULL;
1436 return AST_LOGGER_FAILURE;
1437 }
1438 }
1440
1442 configs = NULL;
1443
1444 return AST_LOGGER_SUCCESS;
1445}
static const char type[]
#define AST_RWLIST_TRAVERSE
static char * levels[NUMLOGLEVELS]
Logging channels used in the Asterisk logging system.
Definition logger.c:227
@ LOGTYPE_CONSOLE
Definition logger.c:140
@ LOGTYPE_SYSLOG
Definition logger.c:138
void ast_str_reset(struct ast_str *buf)
Reset the content of a dynamic string. Useful before a series of ast_str_append.
Definition strings.h:693
enum logtypes type
Definition logger.c:155
char filename[PATH_MAX]
Definition logger.c:159
#define ARRAY_LEN(a)
Definition utils.h:706

References ARRAY_LEN, ast_free, AST_LOGGER_ALLOC_ERROR, AST_LOGGER_FAILURE, AST_LOGGER_SUCCESS, AST_RWLIST_RDLOCK, AST_RWLIST_TRAVERSE, AST_RWLIST_UNLOCK, ast_str_append(), ast_str_buffer(), ast_str_create, ast_str_reset(), logchannel::disabled, logchannel::filename, levels, logchannel::logmask, LOGTYPE_CONSOLE, LOGTYPE_SYSLOG, NULL, and logchannel::type.

Referenced by ast_ari_asterisk_list_log_channels().

◆ ast_logger_get_dateformat()

const char * ast_logger_get_dateformat ( void  )

Get the logger configured date format.

Returns
The date format string
Since
13.0.0

Definition at line 2994 of file logger.c.

2995{
2996 return dateformat;
2997}
static char dateformat[256]
Definition logger.c:79

References dateformat.

Referenced by set_header().

◆ ast_logger_get_dynamic_level()

int ast_logger_get_dynamic_level ( const char *  name)

Retrieve dynamic logging level id.

Parameters
nameThe name of the level
Returns
The unique integer id for the given level
Return values
-1if level name not found

Definition at line 2947 of file logger.c.

2948{
2949 int level = -1;
2950
2952
2954
2956
2957 return level;
2958}
static const char name[]
Definition format_mp3.c:68
static int logger_get_dynamic_level(const char *name)
Definition logger.c:2929

References AST_RWLIST_RDLOCK, AST_RWLIST_UNLOCK, logger_get_dynamic_level(), and name.

Referenced by log_exec().

◆ ast_logger_get_over_threshold_queue_limit()

int ast_logger_get_over_threshold_queue_limit ( void  )

Get the over threshold maximum number of messages allowed in the processing queue.

Returns
Over threshold queue limit

Definition at line 3014 of file logger.c.

3015{
3017}
static int logger_queue_over_threshold_limit
Definition logger.c:95

References logger_queue_over_threshold_limit.

Referenced by handle_cli_queue_over_threshold_test().

◆ ast_logger_get_queue_limit()

int ast_logger_get_queue_limit ( void  )

Get the maximum number of messages allowed in the processing queue.

Returns
Queue limit

Definition at line 3004 of file logger.c.

3005{
3006 return logger_queue_limit;
3007}
static int logger_queue_limit
Definition logger.c:94

References logger_queue_limit.

Referenced by handle_cli_queue_over_threshold_test(), and handle_cli_queue_test().

◆ ast_logger_register_level()

int ast_logger_register_level ( const char *  name)

Register a new logger level.

Parameters
nameThe name of the level to be registered
Return values
-1if an error occurs
non-zerolevel to be used with ast_log for sending messages to this level
Since
1.8

Definition at line 2918 of file logger.c.

2919{
2920 int available = 0;
2921
2925
2926 return available;
2927}
static int available(struct dahdi_pvt **pvt, int is_specific_channel)
static int logger_register_level(const char *name)
Definition logger.c:2881

References AST_RWLIST_UNLOCK, AST_RWLIST_WRLOCK, available(), logger_register_level(), and name.

Referenced by handle_cli_dynamic_level_test(), handle_cli_performance_test(), handle_cli_queue_over_threshold_test(), handle_cli_queue_test(), load_module(), load_module(), load_module(), and load_module().

◆ ast_logger_remove_channel()

int ast_logger_remove_channel ( const char *  log_channel)

Delete the specified log channel.

Parameters
log_channelThe log channel to delete

Definition at line 1583 of file logger.c.

1584{
1585 struct logchannel *chan;
1586
1588
1589 chan = find_logchannel(log_channel);
1590 if (chan && chan->dynamic) {
1592 } else {
1594 return AST_LOGGER_FAILURE;
1595 }
1597
1598 if (chan->fileptr) {
1599 fclose(chan->fileptr);
1600 chan->fileptr = NULL;
1601 }
1602 ast_free(chan);
1603 chan = NULL;
1604
1605 return AST_LOGGER_SUCCESS;
1606}
#define AST_RWLIST_REMOVE
int dynamic
Definition logger.c:165
FILE * fileptr
Definition logger.c:157

References ast_free, AST_LOGGER_FAILURE, AST_LOGGER_SUCCESS, AST_RWLIST_REMOVE, AST_RWLIST_UNLOCK, AST_RWLIST_WRLOCK, logchannel::dynamic, logchannel::fileptr, find_logchannel(), logchannel::list, and NULL.

Referenced by ast_ari_asterisk_delete_log(), handle_cli_queue_over_threshold_test(), handle_cli_queue_test(), and handle_logger_remove_channel().

◆ ast_logger_rotate()

int ast_logger_rotate ( void  )

Reload logger while rotating log files.

Definition at line 1323 of file logger.c.

1324{
1325 return reload_logger(1, NULL);
1326}
static int reload_logger(int rotate, const char *altconf)
Definition logger.c:1220

References NULL, and reload_logger().

Referenced by action_loggerrotate().

◆ ast_logger_rotate_channel()

int ast_logger_rotate_channel ( const char *  log_channel)

Rotate the specified log channel.

Parameters
log_channelThe log channel to rotate

Definition at line 1328 of file logger.c.

1329{
1330 struct logchannel *f;
1331 int success = AST_LOGGER_FAILURE;
1332 char filename[PATH_MAX];
1333
1334 make_filename(log_channel, filename, sizeof(filename));
1335
1337
1339
1341 if (f->disabled) {
1342 f->disabled = 0; /* Re-enable logging at reload */
1343 manager_event(EVENT_FLAG_SYSTEM, "LogChannel", "Channel: %s\r\nEnabled: Yes\r\n",
1344 f->filename);
1345 }
1346 if (f->fileptr && (f->fileptr != stdout) && (f->fileptr != stderr)) {
1347 fclose(f->fileptr); /* Close file */
1348 f->fileptr = NULL;
1349 if (strcmp(filename, f->filename) == 0) {
1351 success = AST_LOGGER_SUCCESS;
1352 }
1353 }
1354 }
1355
1357
1359
1360 return success;
1361}
#define PATH_MAX
Definition asterisk.h:40
static void make_filename(const char *channel, char *filename, size_t size)
create the filename that will be used for a logger channel.
Definition logger.c:602
static int init_logger_chain(const char *altconf)
Read config, setup channels.
Definition logger.c:772
static int rotate_file(const char *filename)
Definition logger.c:1053
#define manager_event(category, event, contents,...)
External routines may send asterisk manager events this way.
Definition manager.h:255
#define EVENT_FLAG_SYSTEM
Definition manager.h:75
const char * ast_config_AST_LOG_DIR
Definition options.c:160
int disabled
Definition logger.c:149
int ast_mkdir(const char *path, int mode)
Recursively create directory path.
Definition utils.c:2513

References ast_config_AST_LOG_DIR, AST_LOGGER_FAILURE, AST_LOGGER_SUCCESS, ast_mkdir(), AST_RWLIST_TRAVERSE, AST_RWLIST_UNLOCK, AST_RWLIST_WRLOCK, logchannel::disabled, EVENT_FLAG_SYSTEM, logchannel::filename, logchannel::fileptr, init_logger_chain(), logchannel::list, make_filename(), manager_event, NULL, PATH_MAX, and rotate_file().

Referenced by ast_ari_asterisk_rotate_log().

◆ ast_logger_set_over_threshold_queue_limit()

void ast_logger_set_over_threshold_queue_limit ( int  limit)

Set the threshold for the maximum number of WARNING/ERROR messages allowed in the processing queue that can exceed the logger queue's threshold. This acts as a buffer for WARNING/ERROR messages so that we can continue to queue them while discarding other message types. This threshold sits on top of the logger queue's message threshold, so the actual queue size will be the logger queue threshold PLUS this threshold.

Parameters
limit

Definition at line 3009 of file logger.c.

3010{
3012}

References logger_queue_over_threshold_limit.

Referenced by handle_cli_queue_over_threshold_test().

◆ ast_logger_set_queue_limit()

void ast_logger_set_queue_limit ( int  queue_limit)

Set the maximum number of messages allowed in the processing queue.

Parameters
queue_limit

Definition at line 2999 of file logger.c.

3000{
3001 logger_queue_limit = queue_limit;
3002}

References logger_queue_limit.

Referenced by handle_cli_queue_over_threshold_test(), and handle_cli_queue_test().

◆ ast_logger_unregister_level()

void ast_logger_unregister_level ( const char *  name)

Unregister a previously registered logger level.

Parameters
nameThe name of the level to be unregistered
Since
1.8

Definition at line 2976 of file logger.c.

2977{
2978 int x;
2979
2982
2983 if (x) {
2985 }
2986
2988
2989 if (x) {
2990 ast_debug(1, "Unregistered dynamic logger level '%s' with index %u.\n", name, x);
2991 }
2992}
#define ast_debug(level,...)
Log a DEBUG message.
static void update_logchannels(void)
Definition logger.c:2777
static int logger_unregister_level(const char *name)
Definition logger.c:2960

References ast_debug, AST_RWLIST_UNLOCK, AST_RWLIST_WRLOCK, logger_unregister_level(), name, and update_logchannels().

Referenced by handle_cli_dynamic_level_test(), handle_cli_performance_test(), handle_cli_queue_over_threshold_test(), handle_cli_queue_test(), load_module(), unload_module(), unload_module(), unload_module(), and unload_module().

◆ ast_queue_log()

void ast_queue_log ( const char *  queuename,
const char *  callid,
const char *  agent,
const char *  event,
const char *  fmt,
  ... 
)

Definition at line 973 of file logger.c.

974{
975 va_list ap;
976 struct timeval tv;
977 struct ast_tm tm;
978 char qlog_msg[8192];
979 int qlog_len;
980 char time_str[30];
981
982 if (!logger_initialized) {
983 /* You are too early. We are not open yet! */
984 return;
985 }
986 if (!queuelog_init) {
987 /* We must initialize now since someone is trying to log something. */
989 }
990
991 if (ast_check_realtime("queue_log")) {
992 tv = ast_tvnow();
993 ast_localtime(&tv, &tm, logfiles.queue_log_realtime_use_gmt ? "GMT" : NULL);
994 ast_strftime(time_str, sizeof(time_str), "%F %T.%6q", &tm);
995 va_start(ap, fmt);
996 vsnprintf(qlog_msg, sizeof(qlog_msg), fmt, ap);
997 va_end(ap);
998 if (logfiles.queue_adaptive_realtime) {
1000 AST_APP_ARG(data)[5];
1001 );
1002 AST_NONSTANDARD_APP_ARGS(args, qlog_msg, '|');
1003 /* Ensure fields are large enough to receive data */
1004 ast_realtime_require_field("queue_log",
1005 "data1", RQ_CHAR, strlen(S_OR(args.data[0], "")),
1006 "data2", RQ_CHAR, strlen(S_OR(args.data[1], "")),
1007 "data3", RQ_CHAR, strlen(S_OR(args.data[2], "")),
1008 "data4", RQ_CHAR, strlen(S_OR(args.data[3], "")),
1009 "data5", RQ_CHAR, strlen(S_OR(args.data[4], "")),
1010 SENTINEL);
1011
1012 /* Store the log */
1013 ast_store_realtime("queue_log", "time", time_str,
1014 "callid", callid,
1015 "queuename", queuename,
1016 "agent", agent,
1017 "event", event,
1018 "data1", S_OR(args.data[0], ""),
1019 "data2", S_OR(args.data[1], ""),
1020 "data3", S_OR(args.data[2], ""),
1021 "data4", S_OR(args.data[3], ""),
1022 "data5", S_OR(args.data[4], ""),
1023 SENTINEL);
1024 } else {
1025 ast_store_realtime("queue_log", "time", time_str,
1026 "callid", callid,
1027 "queuename", queuename,
1028 "agent", agent,
1029 "event", event,
1030 "data", qlog_msg,
1031 SENTINEL);
1032 }
1033
1034 if (!logfiles.queue_log_to_file) {
1035 return;
1036 }
1037 }
1038
1039 if (qlog) {
1040 va_start(ap, fmt);
1041 qlog_len = snprintf(qlog_msg, sizeof(qlog_msg), "%ld|%s|%s|%s|%s|", (long)time(NULL), callid, queuename, agent, event);
1042 vsnprintf(qlog_msg + qlog_len, sizeof(qlog_msg) - qlog_len, fmt, ap);
1043 va_end(ap);
1045 if (qlog) {
1046 fprintf(qlog, "%s\n", qlog_msg);
1047 fflush(qlog);
1048 }
1050 }
1051}
#define SENTINEL
Definition compiler.h:87
#define AST_APP_ARG(name)
Define an application argument.
#define AST_DECLARE_APP_ARGS(name, arglist)
Declare a structure to hold an application's arguments.
#define AST_NONSTANDARD_APP_ARGS(args, parse, sep)
Performs the 'nonstandard' argument separation process for an application.
int ast_realtime_require_field(const char *family,...) attribute_sentinel
Inform realtime what fields that may be stored.
int ast_check_realtime(const char *family)
Check if realtime engine is configured for family.
int ast_store_realtime(const char *family,...) attribute_sentinel
Create realtime configuration.
struct ast_tm * ast_localtime(const struct timeval *timep, struct ast_tm *p_tm, const char *zone)
Timezone-independent version of localtime_r(3).
Definition localtime.c:1739
int ast_strftime(char *buf, size_t len, const char *format, const struct ast_tm *tm)
Special version of strftime(3) that handles fractions of a second. Takes the same arguments as strfti...
Definition localtime.c:2524
static struct @395 logfiles
static int queuelog_init
Definition logger.c:86
void logger_queue_start(void)
Start the ast_queue_log() logger.
Definition logger.c:2175
static FILE * qlog
Definition logger.c:214
static struct @522 args
#define S_OR(a, b)
returns the equivalent of logic or for strings: first one if not empty, otherwise second one.
Definition strings.h:80
struct timeval ast_tvnow(void)
Returns current timeval. Meant to replace calls to gettimeofday().
Definition time.h:159

References args, AST_APP_ARG, ast_check_realtime(), AST_DECLARE_APP_ARGS, ast_localtime(), AST_NONSTANDARD_APP_ARGS, ast_realtime_require_field(), AST_RWLIST_RDLOCK, AST_RWLIST_UNLOCK, ast_store_realtime(), ast_strftime(), ast_tvnow(), logfiles, logger_initialized, logger_queue_start(), NULL, qlog, queuelog_init, RQ_CHAR, S_OR, and SENTINEL.

Referenced by aqm_exec(), find_queue_by_name_rt(), handle_blind_transfer(), handle_hangup(), handle_queue_add_member(), handle_queue_remove_member(), log_attended_transfer(), manager_add_queue_member(), manager_queue_log_custom(), manager_remove_queue_member(), ql_exec(), queue_agent_cb(), queue_exec(), qupd_exec(), rna(), rqm_exec(), rt_handle_member_record(), set_member_paused(), set_member_penalty_help_members(), set_queue_member_pause(), set_queue_member_ringinuse(), try_calling(), update_realtime_members(), wait_for_answer(), and wait_our_turn().

◆ ast_read_threadstorage_callid()

ast_callid ast_read_threadstorage_callid ( void  )

extracts the callid from the thread

Return values
Non-zeroCall id related to the thread
0if no call_id is present in the thread

Definition at line 2287 of file logger.c.

2288{
2289 ast_callid *callid;
2290
2291 callid = ast_threadstorage_get(&unique_callid, sizeof(*callid));
2292
2293 return callid ? *callid : 0;
2294}

References ast_threadstorage_get().

Referenced by __ast_pbx_run(), __ast_verbose(), ast_callid_threadstorage_auto(), ast_dial_run(), ast_log_ap(), ast_log_safe(), bridge_channel_internal_join(), bridge_impart_internal(), callid_set_chanloggroup(), common_recall_channel_setup(), iax2_request(), jingle_alloc(), launch_monitor_thread(), local_request_with_stream_topology(), media_request_helper(), and socket_process().

◆ ast_verb_console_get()

int ast_verb_console_get ( void  )

Get this thread's console verbosity level.

Returns
verbosity level of the console.

Definition at line 2740 of file logger.c.

2741{
2742 struct verb_console *console;
2743 int verb_level;
2744
2745 console = ast_threadstorage_get(&my_verb_console, sizeof(*console));
2747 if (!console) {
2748 verb_level = 0;
2749 } else if (console->level) {
2750 verb_level = *console->level;
2751 } else {
2752 verb_level = option_verbose;
2753 }
2755 return verb_level;
2756}
int option_verbose
Definition options.c:68

References AST_RWLIST_RDLOCK, AST_RWLIST_UNLOCK, ast_threadstorage_get(), and option_verbose.

Referenced by handle_show_settings(), and handle_verbose().

◆ ast_verb_console_register()

void ast_verb_console_register ( int *  level)

Register this thread's console verbosity level pointer.

Parameters
levelWhere the verbose level value is.

Definition at line 2713 of file logger.c.

2714{
2715 struct verb_console *console;
2716
2717 console = ast_threadstorage_get(&my_verb_console, sizeof(*console));
2718 if (!console || !level) {
2719 return;
2720 }
2721 console->level = level;
2722
2727}
void ast_verb_update(void)
Re-evaluate the system max verbosity level (ast_verb_sys_level).
Definition logger.c:2651
int * level
Definition logger.c:2642

References AST_RWLIST_INSERT_HEAD, AST_RWLIST_UNLOCK, AST_RWLIST_WRLOCK, ast_threadstorage_get(), ast_verb_update(), and verb_console::level.

Referenced by netconsole().

◆ ast_verb_console_set()

void ast_verb_console_set ( int  verb_level)

Set this thread's console verbosity level.

Parameters
verb_levelNew level to set.

Definition at line 2758 of file logger.c.

2759{
2760 struct verb_console *console;
2761
2762 console = ast_threadstorage_get(&my_verb_console, sizeof(*console));
2763 if (!console) {
2764 return;
2765 }
2766
2768 if (console->level) {
2769 *console->level = verb_level;
2770 } else {
2771 option_verbose = verb_level;
2772 }
2775}

References AST_RWLIST_UNLOCK, AST_RWLIST_WRLOCK, ast_threadstorage_get(), ast_verb_update(), and option_verbose.

Referenced by handle_verbose().

◆ ast_verb_console_unregister()

void ast_verb_console_unregister ( void  )

Unregister this thread's console verbosity level.

Definition at line 2729 of file logger.c.

2730{
2731 struct verb_console *console;
2732
2733 console = ast_threadstorage_get(&my_verb_console, sizeof(*console));
2734 if (!console) {
2735 return;
2736 }
2738}
static void verb_console_unregister(struct verb_console *console)
Definition logger.c:2692

References ast_threadstorage_get(), and verb_console_unregister().

Referenced by netconsole().

◆ ast_verb_update()

void ast_verb_update ( void  )

Re-evaluate the system max verbosity level (ast_verb_sys_level).

Definition at line 2651 of file logger.c.

2652{
2653 struct logchannel *log;
2654 struct verb_console *console;
2655 int verb_level;
2656
2658
2660
2661 /* Default to the root console verbosity. */
2662 verb_level = option_verbose;
2663
2664 /* Determine max remote console level. */
2666 if (verb_level < *console->level) {
2667 verb_level = *console->level;
2668 }
2669 }
2671
2672 /* Determine max logger channel level. */
2674 AST_RWLIST_TRAVERSE(&logchannels, log, list) {
2675 if (verb_level < log->verbosity) {
2676 verb_level = log->verbosity;
2677 }
2678 }
2680
2681 ast_verb_sys_level = verb_level;
2682
2684}
int ast_verb_sys_level
Definition options.c:65
#define ast_mutex_unlock(a)
Definition lock.h:197
#define ast_mutex_lock(a)
Definition lock.h:196
static ast_mutex_t verb_update_lock
Definition logger.c:2649
int verbosity
Definition logger.c:153

References AST_LIST_TRAVERSE, ast_mutex_lock, ast_mutex_unlock, AST_RWLIST_RDLOCK, AST_RWLIST_TRAVERSE, AST_RWLIST_UNLOCK, ast_verb_sys_level, verb_console::level, option_verbose, verb_update_lock, and logchannel::verbosity.

Referenced by ast_verb_console_register(), ast_verb_console_set(), init_logger(), reload_logger(), and verb_console_unregister().