Asterisk - The Open Source Telephony Project GIT-master-27fb039
Loading...
Searching...
No Matches
Data Structures | Macros | Enumerations | Functions | Variables
logger.c File Reference

Asterisk Logger. More...

#include "asterisk.h"
#include <syslog.h>
#include <signal.h>
#include <time.h>
#include <sys/stat.h>
#include <fcntl.h>
#include "asterisk/_private.h"
#include "asterisk/module.h"
#include "asterisk/paths.h"
#include "asterisk/logger.h"
#include "asterisk/logger_category.h"
#include "asterisk/lock.h"
#include "asterisk/channel.h"
#include "asterisk/config.h"
#include "asterisk/term.h"
#include "asterisk/cli.h"
#include "asterisk/utils.h"
#include "asterisk/manager.h"
#include "asterisk/astobj2.h"
#include "asterisk/threadstorage.h"
#include "asterisk/strings.h"
#include "asterisk/pbx.h"
#include "asterisk/app.h"
#include "asterisk/buildinfo.h"
#include "asterisk/ast_version.h"
#include "asterisk/backtrace.h"
#include "asterisk/json.h"
Include dependency graph for logger.c:

Go to the source code of this file.

Data Structures

struct  chan_group_lock
 map call ID to group More...
 
struct  chan_group_lock_list
 
struct  logchannel
 
struct  logchannels
 
struct  logformatter
 
struct  logmsg
 
struct  logmsgs
 
struct  verb_console
 
struct  verb_consoles
 

Macros

#define FORMATL   "%-35.35s %-8.8s %-10.10s %-9.9s "
 
#define FORMATL2   "%5s %s\n"
 
#define LOG_BUF_INIT_SIZE   256
 
#define LOGMSG_SIZE   MAX(BUFSIZ, 8192)
 
#define VERBOSE_BUF_INIT_SIZE   256
 

Enumerations

enum  logmsgtypes { LOGMSG_NORMAL = 0 , LOGMSG_VERBOSE }
 
enum  logtypes { LOGTYPE_SYSLOG , LOGTYPE_FILE , LOGTYPE_CONSOLE }
 
enum  rotatestrategy { NONE = 0 , SEQUENTIAL = 1 << 0 , ROTATE = 1 << 1 , TIMESTAMP = 1 << 2 }
 

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.
 
static void __reg_module (void)
 
static void __unreg_module (void)
 
static void _handle_SIGXFSZ (int sig)
 
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,...)
 
ast_callid ast_create_callid (void)
 factory function to create a new uniquely identifying callid.
 
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.
 
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
 
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_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 ()
 Reload logger while rotating log files.
 
int ast_logger_rotate_channel (const char *log_channel)
 Rotate the specified log channel.
 
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.
 
struct ast_moduleAST_MODULE_SELF_SYM (void)
 
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
 
 AST_THREADSTORAGE_CUSTOM_SCOPE (callid_group_name, NULL, ast_free_ptr, static)
 
 AST_THREADSTORAGE_CUSTOM_SCOPE (log_buf, NULL, ast_free_ptr, static)
 
 AST_THREADSTORAGE_CUSTOM_SCOPE (my_verb_console, NULL, verb_console_free, static)
 
 AST_THREADSTORAGE_CUSTOM_SCOPE (unique_callid, NULL, ast_free_ptr, static)
 
 AST_THREADSTORAGE_CUSTOM_SCOPE (verbose_buf, NULL, ast_free_ptr, static)
 
 AST_THREADSTORAGE_CUSTOM_SCOPE (verbose_build_buf, NULL, ast_free_ptr, static)
 
 AST_THREADSTORAGE_RAW (in_safe_log)
 
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).
 
static int callid_group_remove_filters (void)
 
static int callid_group_set_filter (const char *group, int enabled)
 
static int callid_logging_enabled (void)
 
static int callid_set_chanloggroup (const char *group)
 
void close_logger (void)
 
static int custom_level_still_exists (char **levels, char *level, size_t len)
 Checks if level exists in array of level names.
 
static struct logchannelfind_logchannel (const char *channel)
 Find a particular logger channel by name.
 
static int format_log_default (struct logchannel *chan, struct logmsg *msg, char *buf, size_t size)
 
static int format_log_json (struct logchannel *channel, struct logmsg *msg, char *buf, size_t size)
 
static struct logmsgformat_log_message (int level, int sublevel, const char *file, int line, const char *function, ast_callid callid, const char *fmt,...)
 
static struct logmsgformat_log_message_ap (int level, int sublevel, const char *file, int line, const char *function, ast_callid callid, const char *fmt, va_list ap)
 
static int format_log_plain (struct logchannel *chan, struct logmsg *msg, char *buf, size_t size)
 
static const char * get_callid_group (void)
 
static char * handle_logger_add_channel (struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
 
static char * handle_logger_chanloggroup_filter (struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
 
static char * handle_logger_filter_reset (struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
 
static char * handle_logger_filter_show (struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
 
static char * handle_logger_reload (struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
 
static char * handle_logger_remove_channel (struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
 
static char * handle_logger_rotate (struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
 
static char * handle_logger_set_level (struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
 
static char * handle_logger_show_channels (struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
 CLI command to show logging system configuration.
 
static char * handle_logger_show_levels (struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
 CLI command to show logging levels.
 
int init_logger (void)
 
static int init_logger_chain (const char *altconf)
 Read config, setup channels.
 
static int load_module (void)
 
static int log_group_write (struct ast_channel *chan, const char *cmd, char *data, const char *value)
 
static int logger_add_verbose_magic (struct logmsg *logmsg, char *buf, size_t size)
 
static int logger_get_dynamic_level (const char *name)
 
static void logger_print_normal (struct logmsg *logmsg)
 Print a normal log message to the channels.
 
static void logger_queue_init (void)
 
static int logger_queue_restart (int queue_rotate)
 
static int logger_queue_rt_start (void)
 
void logger_queue_start (void)
 Start the ast_queue_log() logger.
 
static int logger_register_level (const char *name)
 
static void * logger_thread (void *data)
 Actual logging thread.
 
static int logger_unregister_level (const char *name)
 
static void logmsg_free (struct logmsg *msg)
 
static void make_components (struct logchannel *chan)
 
static void make_filename (const char *channel, char *filename, size_t size)
 create the filename that will be used for a logger channel.
 
static struct logchannelmake_logchannel (const char *channel, const char *components, int lineno, int dynamic)
 
static int reload_logger (int rotate, const char *altconf)
 
static int reload_module (void)
 
static int rotate_file (const char *filename)
 
static int unload_module (void)
 
static void update_logchannels (void)
 
static void verb_console_free (void *v_console)
 
static void verb_console_unregister (struct verb_console *console)
 

Variables

static struct ast_module_info __mod_info = { .name = AST_MODULE, .flags = AST_MODFLAG_GLOBAL_SYMBOLS | AST_MODFLAG_LOAD_ORDER , .description = "Logger" , .key = ASTERISK_GPL_KEY , .buildopt_sum = AST_BUILDOPT_SUM, .support_level = AST_MODULE_SUPPORT_CORE, .load = load_module, .unload = unload_module, .reload = reload_module, .load_pri = 0, }
 
static const struct ast_module_infoast_module_info = &__mod_info
 
static int callid_filtering = 0
 
struct chan_group_lock_list chan_group_lock_list = AST_RWLIST_HEAD_INIT_VALUE
 
static struct ast_cli_entry cli_logger []
 
static int close_logger_thread = 0
 
static const int colors [NUMLOGLEVELS]
 Colors used in the console for logging.
 
static char * custom_dynamic_levels [NUMLOGLEVELS]
 Custom dynamic logging levels added by the user.
 
static char dateformat [256] = "%b %e %T"
 
static int display_callids
 
static char exec_after_rotate [256] = ""
 
static int filesize_reload_needed
 
static unsigned int global_logmask = 0xFFFF
 
static struct sigaction handle_SIGXFSZ
 
static unsigned int high_water_alert
 
static char hostname [MAXHOSTNAMELEN]
 
static char * levels [NUMLOGLEVELS]
 Logging channels used in the Asterisk logging system.
 
static struct ast_custom_function log_group_function
 
static struct logchannels logchannels = AST_RWLIST_HEAD_INIT_VALUE
 
static ast_cond_t logcond
 
struct { 
 
   unsigned int   queue_adaptive_realtime:1 
 
   unsigned int   queue_log:1 
 
   unsigned int   queue_log_realtime_use_gmt:1 
 
   unsigned int   queue_log_to_file:1 
 
logfiles = { 1 } 
 
static struct logformatter logformatter_default
 
static struct logformatter logformatter_json
 
static struct logformatter logformatter_plain
 
static int logger_initialized
 
static int logger_messages_discarded
 
static int logger_queue_limit = 1000
 
static int logger_queue_size
 
static struct logmsgs logmsgs = AST_LIST_HEAD_INIT_VALUE
 
static pthread_t logthread = AST_PTHREADT_NULL
 
static volatile int next_unique_callid = 1
 
static FILE * qlog
 
static char queue_log_name [256] = QUEUELOG
 
static int queuelog_init
 
static enum rotatestrategy rotatestrategy = SEQUENTIAL
 
static struct verb_consoles verb_consoles = AST_RWLIST_HEAD_INIT_VALUE
 
static ast_mutex_t verb_update_lock = AST_MUTEX_INIT_VALUE
 

Detailed Description

Asterisk Logger.

Logging routines

Author
Mark Spencer marks.nosp@m.ter@.nosp@m.digiu.nosp@m.m.co.nosp@m.m

Definition in file logger.c.

Macro Definition Documentation

◆ FORMATL

#define FORMATL   "%-35.35s %-8.8s %-10.10s %-9.9s "

◆ FORMATL2

#define FORMATL2   "%5s %s\n"

◆ LOG_BUF_INIT_SIZE

#define LOG_BUF_INIT_SIZE   256

Definition at line 271 of file logger.c.

◆ LOGMSG_SIZE

#define LOGMSG_SIZE   MAX(BUFSIZ, 8192)

Definition at line 100 of file logger.c.

◆ VERBOSE_BUF_INIT_SIZE

#define VERBOSE_BUF_INIT_SIZE   256

Definition at line 268 of file logger.c.

Enumeration Type Documentation

◆ logmsgtypes

Enumerator
LOGMSG_NORMAL 
LOGMSG_VERBOSE 

Definition at line 164 of file logger.c.

164 {
165 LOGMSG_NORMAL = 0,
167};
@ LOGMSG_NORMAL
Definition logger.c:165
@ LOGMSG_VERBOSE
Definition logger.c:166

◆ logtypes

enum logtypes
Enumerator
LOGTYPE_SYSLOG 
LOGTYPE_FILE 
LOGTYPE_CONSOLE 

Definition at line 129 of file logger.c.

129 {
133};
@ LOGTYPE_CONSOLE
Definition logger.c:132
@ LOGTYPE_FILE
Definition logger.c:131
@ LOGTYPE_SYSLOG
Definition logger.c:130

◆ rotatestrategy

Enumerator
NONE 
SEQUENTIAL 
ROTATE 
TIMESTAMP 

Definition at line 102 of file logger.c.

102 {
103 NONE = 0, /* Do not rotate log files at all, instead rely on external mechanisms */
104 SEQUENTIAL = 1 << 0, /* Original method - create a new file, in order */
105 ROTATE = 1 << 1, /* Rotate all files, such that the oldest file has the highest suffix */
106 TIMESTAMP = 1 << 2, /* Append the epoch timestamp onto the end of the archived file */
rotatestrategy
Definition logger.c:102
@ ROTATE
Definition logger.c:105
@ TIMESTAMP
Definition logger.c:106
@ SEQUENTIAL
Definition logger.c:104
@ NONE
Definition logger.c:103

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 2520 of file logger.c.

2521{
2522 ast_callid callid;
2523 va_list ap;
2524
2526
2527 va_start(ap, fmt);
2528 __ast_verbose_ap(file, line, func, level, callid, fmt, ap);
2529 va_end(ap);
2530}
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:2515
ast_callid ast_read_threadstorage_callid(void)
extracts the callid from the thread
Definition logger.c:2268

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 2515 of file logger.c.

2516{
2517 ast_log_full(__LOG_VERBOSE, level, file, line, func, callid, fmt, ap);
2518}
#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:2359

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 2532 of file logger.c.

2533{
2534 va_list ap;
2535 va_start(ap, fmt);
2536 __ast_verbose_ap(file, line, func, level, callid, fmt, ap);
2537 va_end(ap);
2538}

References __ast_verbose_ap().

◆ __reg_module()

static void __reg_module ( void  )
static

Definition at line 2935 of file logger.c.

◆ __unreg_module()

static void __unreg_module ( void  )
static

Definition at line 2935 of file logger.c.

◆ _handle_SIGXFSZ()

static void _handle_SIGXFSZ ( int  sig)
static

Definition at line 1884 of file logger.c.

1885{
1886 /* Indicate need to reload */
1888}
static int filesize_reload_needed
Definition logger.c:83

References filesize_reload_needed.

◆ 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 2258 of file logger.c.

2259{
2260 snprintf(buffer, buffer_size, "[C-%08x]", callid);
2261}

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 2290 of file logger.c.

2291{
2292 ast_callid *pointing;
2293
2294 pointing = ast_threadstorage_get(&unique_callid, sizeof(*pointing));
2295 if (!pointing) {
2296 return -1;
2297 }
2298
2299 if (*pointing) {
2300 ast_log(LOG_ERROR, "ast_callid_threadassoc_add(C-%08x) on thread "
2301 "already associated with callid [C-%08x].\n", callid, *pointing);
2302 return 1;
2303 }
2304
2305 *pointing = callid;
2306 return 0;
2307}
#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 2277 of file logger.c.

2278{
2279 ast_callid *id = ast_threadstorage_get(&unique_callid, sizeof(*id));
2280
2281 if (!id) {
2282 return -1;
2283 }
2284
2285 *id = callid;
2286
2287 return 0;
2288}

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 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 *pointing = 0;
2320 return 0;
2321 }
2322
2323 return -1;
2324}

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 2326 of file logger.c.

2327{
2328 ast_callid tmp;
2329
2330 /* Start by trying to see if a callid is available from thread storage */
2332 if (tmp) {
2333 *callid = tmp;
2334 return 0;
2335 }
2336
2337 /* If that failed, try to create a new one and bind it. */
2338 *callid = ast_create_callid();
2339 if (*callid) {
2341 return 1;
2342 }
2343
2344 /* If neither worked, then something must have gone wrong. */
2345 return -1;
2346}
int ast_callid_threadassoc_add(ast_callid callid)
Adds a known callid to thread storage of the calling thread.
Definition logger.c:2290
ast_callid ast_create_callid(void)
factory function to create a new uniquely identifying callid.
Definition logger.c:2263

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 2348 of file logger.c.

2349{
2350 if (callid && callid_created) {
2351 /* If the callid was created rather than simply grabbed from the thread storage, we need to unbind here. */
2353 }
2354}
int ast_callid_threadassoc_remove(void)
Removes callid from thread storage of the calling thread.
Definition logger.c:2309

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 913 of file logger.c.

914{
915 char *msg = NULL, *emsg = NULL, *sptr, *eptr;
916 va_list ap, aq;
917 int size;
918
919 va_start(ap, fmt);
920 va_copy(aq, ap);
921 if ((size = vsnprintf(msg, 0, fmt, ap)) < 0) {
922 va_end(ap);
923 va_end(aq);
924 return;
925 }
926 va_end(ap);
927
928 if (!(msg = ast_malloc(size + 1))) {
929 va_end(aq);
930 return;
931 }
932
933 vsnprintf(msg, size + 1, fmt, aq);
934 va_end(aq);
935
936 if (!(emsg = ast_malloc(size * 2 + 1))) {
937 ast_free(msg);
938 return;
939 }
940
941 for (sptr = msg, eptr = emsg; ; sptr++) {
942 if (*sptr == '"') {
943 *eptr++ = '\\';
944 }
945 *eptr++ = *sptr;
946 if (*sptr == '\0') {
947 break;
948 }
949 }
950 ast_free(msg);
951
952 fprintf(stdout, "verbose \"%s\" %d\n", emsg, level);
953 fflush(stdout);
954 ast_free(emsg);
955}
#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_create_callid()

ast_callid ast_create_callid ( void  )

factory function to create a new uniquely identifying callid.

Returns
The call id

Definition at line 2263 of file logger.c.

2264{
2266}
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:87

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_is_logger_initialized()

int ast_is_logger_initialized ( void  )

Test if logger is initialized.

Return values
trueif the logger is initialized

Definition at line 2145 of file logger.c.

2146{
2147 return logger_initialized;
2148}
static int logger_initialized
Definition logger.c:86

References logger_initialized.

Referenced by check_init().

◆ ast_log()

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 2423 of file logger.c.

2424{
2425 va_list ap;
2426
2427 va_start(ap, fmt);
2428 ast_log_ap(level, file, line, function, fmt, ap);
2429 va_end(ap);
2430}
void ast_log_ap(int level, const char *file, int line, const char *function, const char *fmt, va_list ap)
Definition logger.c:2432

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 2432 of file logger.c.

2433{
2434 ast_callid callid;
2435
2437
2438 if (level == __LOG_VERBOSE) {
2439 __ast_verbose_ap(file, line, function, 0, callid, fmt, ap);
2440 } else {
2441 ast_log_full(level, -1, file, line, function, callid, fmt, ap);
2442 }
2443}

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 2480 of file logger.c.

2481{
2482#ifdef HAVE_BKTR
2483 struct ast_bt *bt;
2484 int i = 0;
2485 struct ast_vector_string *strings;
2486
2487 if (!(bt = ast_bt_create())) {
2488 ast_log(LOG_WARNING, "Unable to allocate space for backtrace structure\n");
2489 return;
2490 }
2491
2492 if ((strings = ast_bt_get_symbols(bt->addresses, bt->num_frames))) {
2493 int count = AST_VECTOR_SIZE(strings);
2494 struct ast_str *buf = ast_str_create(bt->num_frames * 64);
2495
2496 if (buf) {
2497 ast_str_append(&buf, 0, "Got %d backtrace record%c\n", count - 3, count - 3 != 1 ? 's' : ' ');
2498 for (i = 3; i < AST_VECTOR_SIZE(strings); i++) {
2499 ast_str_append(&buf, 0, "#%2d: %s\n", i - 3, AST_VECTOR_GET(strings, i));
2500 }
2502 ast_free(buf);
2503 }
2504
2505 ast_bt_free_symbols(strings);
2506 } else {
2507 ast_log(LOG_ERROR, "Could not allocate memory for backtrace\n");
2508 }
2509 ast_bt_destroy(bt);
2510#else
2511 ast_log(LOG_WARNING, "Must run configure with '--with-execinfo' for stack backtraces.\n");
2512#endif /* defined(HAVE_BKTR) */
2513}
#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:2445
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:620
#define AST_VECTOR_GET(vec, idx)
Get an element from a vector.
Definition vector.h:691

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 2471 of file logger.c.

2472{
2473 va_list ap;
2474 va_start(ap, fmt);
2475 ast_log_full(level, -1, file, line, function, callid, fmt, ap);
2476 va_end(ap);
2477}

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

Referenced by ast_channel_destructor().

◆ ast_log_full()

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 
)
static

send log messages to syslog and/or the console

Definition at line 2359 of file logger.c.

2362{
2363 int hidecli = 0;
2364 struct logmsg *logmsg = NULL;
2365
2367 return;
2368 }
2369
2371 switch (level) {
2372 case __LOG_VERBOSE:
2373 case __LOG_DEBUG:
2374 case __LOG_TRACE:
2375 case __LOG_DTMF:
2376 hidecli = 1; /* Hide the message from the CLI, but still log to any log files */
2377 default: /* Always show NOTICE, WARNING, ERROR, etc. */
2378 break;
2379 }
2380 return;
2381 }
2382
2387 logmsg = format_log_message(__LOG_WARNING, 0, "logger", 0, "***", 0,
2388 "Log queue threshold (%d) exceeded. Discarding new messages.\n", logger_queue_limit);
2390 high_water_alert = 1;
2392 }
2394 return;
2395 }
2397
2399 if (!logmsg) {
2400 return;
2401 }
2402
2404
2405 /* If the logger thread is active, append it to the tail end of the list - otherwise skip that step */
2408 if (close_logger_thread) {
2409 /* Logger is either closing or closed. We cannot log this message. */
2411 } else {
2415 }
2417 } else {
2420 }
2421}
#define __LOG_TRACE
#define __LOG_DTMF
#define __LOG_DEBUG
#define __LOG_WARNING
#define AST_LIST_INSERT_TAIL(head, elm, field)
Appends a list entry to the tail of a list.
#define AST_LIST_LOCK(head)
Locks a list.
Definition linkedlists.h:40
#define AST_LIST_UNLOCK(head)
Attempts to unlock a list.
#define AST_PTHREADT_NULL
Definition lock.h:73
#define ast_cond_signal(cond)
Definition lock.h:210
static int callid_filtering
Definition logger.c:1653
static int close_logger_thread
Definition logger.c:196
static pthread_t logthread
Definition logger.c:194
static int logger_queue_limit
Definition logger.c:93
static int logger_queue_size
Definition logger.c:92
static unsigned int high_water_alert
Definition logger.c:95
static ast_cond_t logcond
Definition logger.c:195
static void logger_print_normal(struct logmsg *logmsg)
Print a normal log message to the channels.
Definition logger.c:1896
static int callid_logging_enabled(void)
Definition logger.c:1747
static struct logmsg * format_log_message_ap(int level, int sublevel, const char *file, int line, const char *function, ast_callid callid, const char *fmt, va_list ap)
Definition logger.c:1988
static int logger_messages_discarded
Definition logger.c:94
static struct logmsg * format_log_message(int level, int sublevel, const char *file, int line, const char *function, ast_callid callid, const char *fmt,...)
Definition logger.c:2052
static void logmsg_free(struct logmsg *msg)
Definition logger.c:187
#define ast_opt_remote
Definition options.h:124
#define ast_opt_exec
Definition options.h:125
int line
Definition logger.c:173
ast_callid callid
Definition logger.c:175
int sublevel
Definition logger.c:172
struct logmsg::@396 list
const ast_string_field file
Definition logger.c:183
const ast_string_field function
Definition logger.c:183
int level
Definition logger.c:171
unsigned int hidecli
Definition logger.c:176

References __LOG_DEBUG, __LOG_DTMF, __LOG_TRACE, __LOG_VERBOSE, __LOG_WARNING, ast_cond_signal, AST_LIST_INSERT_TAIL, AST_LIST_LOCK, AST_LIST_UNLOCK, ast_opt_exec, ast_opt_remote, AST_PTHREADT_NULL, logmsg::callid, callid_filtering, callid_logging_enabled(), close_logger_thread, logmsg::file, format_log_message(), format_log_message_ap(), logmsg::function, logmsg::hidecli, high_water_alert, logmsg::level, logmsg::line, logmsg::list, logcond, logger_messages_discarded, logger_print_normal(), logger_queue_limit, logger_queue_size, logmsg_free(), logthread, NULL, and logmsg::sublevel.

Referenced by __ast_verbose_ap(), ast_log_ap(), ast_log_callid(), and ast_log_safe().

◆ 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 2445 of file logger.c.

2446{
2447 va_list ap;
2448 void *recursed = ast_threadstorage_get_ptr(&in_safe_log);
2449 ast_callid callid;
2450
2451 if (recursed) {
2452 return;
2453 }
2454
2455 if (ast_threadstorage_set_ptr(&in_safe_log, &(int) { 1 })) {
2456 /* We've failed to set the flag that protects against
2457 * recursion, so bail. */
2458 return;
2459 }
2460
2462
2463 va_start(ap, fmt);
2464 ast_log_full(level, -1, file, line, function, callid, fmt, ap);
2465 va_end(ap);
2466
2467 /* Clear flag so the next allocation failure can be logged. */
2468 ast_threadstorage_set_ptr(&in_safe_log, NULL);
2469}
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 1501 of file logger.c.

1502{
1503 struct logchannel *chan;
1504
1506 return AST_LOGGER_DECLINE;
1507 }
1508
1510
1511 chan = find_logchannel(log_channel);
1512 if (chan) {
1514 return AST_LOGGER_FAILURE;
1515 }
1516
1517 chan = make_logchannel(log_channel, components, 0, 1);
1518 if (!chan) {
1521 }
1522
1524 global_logmask |= chan->logmask;
1525
1527
1528 return AST_LOGGER_SUCCESS;
1529}
@ AST_LOGGER_DECLINE
@ AST_LOGGER_FAILURE
@ AST_LOGGER_SUCCESS
@ AST_LOGGER_ALLOC_ERROR
#define AST_RWLIST_WRLOCK(head)
Write locks a list.
Definition linkedlists.h:52
#define AST_RWLIST_UNLOCK(head)
Attempts to unlock a read/write based list.
#define AST_RWLIST_INSERT_HEAD
static unsigned int global_logmask
Definition logger.c:84
static struct logchannel * make_logchannel(const char *channel, const char *components, int lineno, int dynamic)
Definition logger.c:643
static struct logchannel * find_logchannel(const char *channel)
Find a particular logger channel by name.
Definition logger.c:627
static force_inline int attribute_pure ast_strlen_zero(const char *s)
Definition strings.h:65
unsigned int logmask
Definition logger.c:139
struct logchannel::@395 list
char components[0]
Definition logger.c:159

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_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 1389 of file logger.c.

1391{
1392 struct logchannel *chan;
1393 struct ast_str *configs = ast_str_create(64);
1394 int res = AST_LOGGER_SUCCESS;
1395
1396 if (!configs) {
1398 }
1399
1401 AST_RWLIST_TRAVERSE(&logchannels, chan, list) {
1402 unsigned int level;
1403
1405
1406 for (level = 0; level < ARRAY_LEN(levels); level++) {
1407 if ((chan->logmask & (1 << level)) && levels[level]) {
1408 ast_str_append(&configs, 0, "%s ", levels[level]);
1409 }
1410 }
1411
1412 res = logentry(chan->filename, chan->type == LOGTYPE_CONSOLE ? "Console" :
1413 (chan->type == LOGTYPE_SYSLOG ? "Syslog" : "File"), chan->disabled ?
1414 "Disabled" : "Enabled", ast_str_buffer(configs), data);
1415
1416 if (res) {
1419 configs = NULL;
1420 return AST_LOGGER_FAILURE;
1421 }
1422 }
1424
1426 configs = NULL;
1427
1428 return AST_LOGGER_SUCCESS;
1429}
static const char type[]
#define AST_RWLIST_RDLOCK(head)
Read locks a list.
Definition linkedlists.h:78
#define AST_RWLIST_TRAVERSE
static char * levels[NUMLOGLEVELS]
Logging channels used in the Asterisk logging system.
Definition logger.c:211
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:147
char filename[PATH_MAX]
Definition logger.c:151
#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 2897 of file logger.c.

2898{
2899 return dateformat;
2900}
static char dateformat[256]
Definition logger.c:78

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 2850 of file logger.c.

2851{
2852 int level = -1;
2853
2855
2857
2859
2860 return level;
2861}
static const char name[]
Definition format_mp3.c:68
static int logger_get_dynamic_level(const char *name)
Definition logger.c:2832

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

Referenced by log_exec().

◆ 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 2907 of file logger.c.

2908{
2909 return logger_queue_limit;
2910}

References logger_queue_limit.

Referenced by 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 2821 of file logger.c.

2822{
2823 int available = 0;
2824
2828
2829 return available;
2830}
static int available(struct dahdi_pvt **pvt, int is_specific_channel)
static int logger_register_level(const char *name)
Definition logger.c:2784

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_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 1567 of file logger.c.

1568{
1569 struct logchannel *chan;
1570
1572
1573 chan = find_logchannel(log_channel);
1574 if (chan && chan->dynamic) {
1576 } else {
1578 return AST_LOGGER_FAILURE;
1579 }
1581
1582 if (chan->fileptr) {
1583 fclose(chan->fileptr);
1584 chan->fileptr = NULL;
1585 }
1586 ast_free(chan);
1587 chan = NULL;
1588
1589 return AST_LOGGER_SUCCESS;
1590}
#define AST_RWLIST_REMOVE
int dynamic
Definition logger.c:157
FILE * fileptr
Definition logger.c:149

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_test(), and handle_logger_remove_channel().

◆ ast_logger_rotate()

int ast_logger_rotate ( void  )

Reload logger while rotating log files.

Definition at line 1307 of file logger.c.

1308{
1309 return reload_logger(1, NULL);
1310}
static int reload_logger(int rotate, const char *altconf)
Definition logger.c:1204

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 1312 of file logger.c.

1313{
1314 struct logchannel *f;
1315 int success = AST_LOGGER_FAILURE;
1316 char filename[PATH_MAX];
1317
1318 make_filename(log_channel, filename, sizeof(filename));
1319
1321
1323
1325 if (f->disabled) {
1326 f->disabled = 0; /* Re-enable logging at reload */
1327 manager_event(EVENT_FLAG_SYSTEM, "LogChannel", "Channel: %s\r\nEnabled: Yes\r\n",
1328 f->filename);
1329 }
1330 if (f->fileptr && (f->fileptr != stdout) && (f->fileptr != stderr)) {
1331 fclose(f->fileptr); /* Close file */
1332 f->fileptr = NULL;
1333 if (strcmp(filename, f->filename) == 0) {
1335 success = AST_LOGGER_SUCCESS;
1336 }
1337 }
1338 }
1339
1341
1343
1344 return success;
1345}
#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:586
static int init_logger_chain(const char *altconf)
Read config, setup channels.
Definition logger.c:756
static int rotate_file(const char *filename)
Definition logger.c:1037
#define manager_event(category, event, contents,...)
External routines may send asterisk manager events this way.
Definition manager.h:254
#define EVENT_FLAG_SYSTEM
Definition manager.h:75
const char * ast_config_AST_LOG_DIR
Definition options.c:160
int disabled
Definition logger.c:141
int ast_mkdir(const char *path, int mode)
Recursively create directory path.
Definition utils.c:2515

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_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 2902 of file logger.c.

2903{
2904 logger_queue_limit = queue_limit;
2905}

References logger_queue_limit.

Referenced by 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 2879 of file logger.c.

2880{
2881 int x;
2882
2885
2886 if (x) {
2888 }
2889
2891
2892 if (x) {
2893 ast_debug(1, "Unregistered dynamic logger level '%s' with index %u.\n", name, x);
2894 }
2895}
#define ast_debug(level,...)
Log a DEBUG message.
static void update_logchannels(void)
Definition logger.c:2680
static int logger_unregister_level(const char *name)
Definition logger.c:2863

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_test(), load_module(), unload_module(), unload_module(), unload_module(), and unload_module().

◆ AST_MODULE_SELF_SYM()

struct ast_module * AST_MODULE_SELF_SYM ( void  )

Definition at line 2935 of file logger.c.

◆ 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 957 of file logger.c.

958{
959 va_list ap;
960 struct timeval tv;
961 struct ast_tm tm;
962 char qlog_msg[8192];
963 int qlog_len;
964 char time_str[30];
965
966 if (!logger_initialized) {
967 /* You are too early. We are not open yet! */
968 return;
969 }
970 if (!queuelog_init) {
971 /* We must initialize now since someone is trying to log something. */
973 }
974
975 if (ast_check_realtime("queue_log")) {
976 tv = ast_tvnow();
977 ast_localtime(&tv, &tm, logfiles.queue_log_realtime_use_gmt ? "GMT" : NULL);
978 ast_strftime(time_str, sizeof(time_str), "%F %T.%6q", &tm);
979 va_start(ap, fmt);
980 vsnprintf(qlog_msg, sizeof(qlog_msg), fmt, ap);
981 va_end(ap);
982 if (logfiles.queue_adaptive_realtime) {
984 AST_APP_ARG(data)[5];
985 );
986 AST_NONSTANDARD_APP_ARGS(args, qlog_msg, '|');
987 /* Ensure fields are large enough to receive data */
988 ast_realtime_require_field("queue_log",
989 "data1", RQ_CHAR, strlen(S_OR(args.data[0], "")),
990 "data2", RQ_CHAR, strlen(S_OR(args.data[1], "")),
991 "data3", RQ_CHAR, strlen(S_OR(args.data[2], "")),
992 "data4", RQ_CHAR, strlen(S_OR(args.data[3], "")),
993 "data5", RQ_CHAR, strlen(S_OR(args.data[4], "")),
994 SENTINEL);
995
996 /* Store the log */
997 ast_store_realtime("queue_log", "time", time_str,
998 "callid", callid,
999 "queuename", queuename,
1000 "agent", agent,
1001 "event", event,
1002 "data1", S_OR(args.data[0], ""),
1003 "data2", S_OR(args.data[1], ""),
1004 "data3", S_OR(args.data[2], ""),
1005 "data4", S_OR(args.data[3], ""),
1006 "data5", S_OR(args.data[4], ""),
1007 SENTINEL);
1008 } else {
1009 ast_store_realtime("queue_log", "time", time_str,
1010 "callid", callid,
1011 "queuename", queuename,
1012 "agent", agent,
1013 "event", event,
1014 "data", qlog_msg,
1015 SENTINEL);
1016 }
1017
1018 if (!logfiles.queue_log_to_file) {
1019 return;
1020 }
1021 }
1022
1023 if (qlog) {
1024 va_start(ap, fmt);
1025 qlog_len = snprintf(qlog_msg, sizeof(qlog_msg), "%ld|%s|%s|%s|%s|", (long)time(NULL), callid, queuename, agent, event);
1026 vsnprintf(qlog_msg + qlog_len, sizeof(qlog_msg) - qlog_len, fmt, ap);
1027 va_end(ap);
1029 if (qlog) {
1030 fprintf(qlog, "%s\n", qlog_msg);
1031 fflush(qlog);
1032 }
1034 }
1035}
#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 int queuelog_init
Definition logger.c:85
void logger_queue_start(void)
Start the ast_queue_log() logger.
Definition logger.c:2156
static FILE * qlog
Definition logger.c:198
static struct @394 logfiles
static struct @519 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(), logger_queue_start(), manager_add_queue_member(), manager_queue_log_custom(), manager_remove_queue_member(), ql_exec(), queue_agent_cb(), queue_exec(), qupd_exec(), reload_logger(), 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 2268 of file logger.c.

2269{
2270 ast_callid *callid;
2271
2272 callid = ast_threadstorage_get(&unique_callid, sizeof(*callid));
2273
2274 return callid ? *callid : 0;
2275}

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_THREADSTORAGE_CUSTOM_SCOPE() [1/6]

AST_THREADSTORAGE_CUSTOM_SCOPE ( callid_group_name  ,
NULL  ,
ast_free_ptr  ,
static   
)

◆ AST_THREADSTORAGE_CUSTOM_SCOPE() [2/6]

AST_THREADSTORAGE_CUSTOM_SCOPE ( log_buf  ,
NULL  ,
ast_free_ptr  ,
static   
)

◆ AST_THREADSTORAGE_CUSTOM_SCOPE() [3/6]

AST_THREADSTORAGE_CUSTOM_SCOPE ( my_verb_console  ,
NULL  ,
verb_console_free  ,
static   
)

Thread specific console verbosity level node.

◆ AST_THREADSTORAGE_CUSTOM_SCOPE() [4/6]

AST_THREADSTORAGE_CUSTOM_SCOPE ( unique_callid  ,
NULL  ,
ast_free_ptr  ,
static   
)

◆ AST_THREADSTORAGE_CUSTOM_SCOPE() [5/6]

AST_THREADSTORAGE_CUSTOM_SCOPE ( verbose_buf  ,
NULL  ,
ast_free_ptr  ,
static   
)

◆ AST_THREADSTORAGE_CUSTOM_SCOPE() [6/6]

AST_THREADSTORAGE_CUSTOM_SCOPE ( verbose_build_buf  ,
NULL  ,
ast_free_ptr  ,
static   
)

◆ AST_THREADSTORAGE_RAW()

AST_THREADSTORAGE_RAW ( in_safe_log  )

◆ 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 2643 of file logger.c.

2644{
2645 struct verb_console *console;
2646 int verb_level;
2647
2648 console = ast_threadstorage_get(&my_verb_console, sizeof(*console));
2650 if (!console) {
2651 verb_level = 0;
2652 } else if (console->level) {
2653 verb_level = *console->level;
2654 } else {
2655 verb_level = option_verbose;
2656 }
2658 return verb_level;
2659}
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 2616 of file logger.c.

2617{
2618 struct verb_console *console;
2619
2620 console = ast_threadstorage_get(&my_verb_console, sizeof(*console));
2621 if (!console || !level) {
2622 return;
2623 }
2624 console->level = level;
2625
2630}
void ast_verb_update(void)
Re-evaluate the system max verbosity level (ast_verb_sys_level).
Definition logger.c:2554
int * level
Definition logger.c:2545

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 2661 of file logger.c.

2662{
2663 struct verb_console *console;
2664
2665 console = ast_threadstorage_get(&my_verb_console, sizeof(*console));
2666 if (!console) {
2667 return;
2668 }
2669
2671 if (console->level) {
2672 *console->level = verb_level;
2673 } else {
2674 option_verbose = verb_level;
2675 }
2678}

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 2632 of file logger.c.

2633{
2634 struct verb_console *console;
2635
2636 console = ast_threadstorage_get(&my_verb_console, sizeof(*console));
2637 if (!console) {
2638 return;
2639 }
2641}
static void verb_console_unregister(struct verb_console *console)
Definition logger.c:2595

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 2554 of file logger.c.

2555{
2556 struct logchannel *log;
2557 struct verb_console *console;
2558 int verb_level;
2559
2561
2563
2564 /* Default to the root console verbosity. */
2565 verb_level = option_verbose;
2566
2567 /* Determine max remote console level. */
2569 if (verb_level < *console->level) {
2570 verb_level = *console->level;
2571 }
2572 }
2574
2575 /* Determine max logger channel level. */
2577 AST_RWLIST_TRAVERSE(&logchannels, log, list) {
2578 if (verb_level < log->verbosity) {
2579 verb_level = log->verbosity;
2580 }
2581 }
2583
2584 ast_verb_sys_level = verb_level;
2585
2587}
int ast_verb_sys_level
Definition options.c:65
#define AST_LIST_TRAVERSE(head, var, field)
Loops over (traverses) the entries in a list.
#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:2552
int verbosity
Definition logger.c:145

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().

◆ callid_group_remove_filters()

static int callid_group_remove_filters ( void  )
static

Definition at line 1694 of file logger.c.

1695{
1696 int i = 0;
1697 struct chan_group_lock *cgl;
1698
1701 ast_free(cgl);
1702 i++;
1703 }
1704 callid_filtering = 0;
1706 return i;
1707}
#define AST_RWLIST_REMOVE_HEAD
map call ID to group
Definition logger.c:1646
struct chan_group_lock::@397 entry

References ast_free, AST_RWLIST_REMOVE_HEAD, AST_RWLIST_UNLOCK, AST_RWLIST_WRLOCK, callid_filtering, and chan_group_lock::entry.

Referenced by close_logger(), and handle_logger_filter_reset().

◆ callid_group_set_filter()

static int callid_group_set_filter ( const char *  group,
int  enabled 
)
static

Definition at line 1709 of file logger.c.

1710{
1711 struct chan_group_lock *cgl;
1712
1715 if (!strcmp(group, cgl->name)) {
1716 if (!enabled) {
1718 ast_free(cgl);
1719 }
1720 break;
1721 }
1722 }
1724
1725 if (!enabled) {
1727 callid_filtering = 0;
1728 }
1730 return 0;
1731 }
1732
1733 if (!cgl) {
1734 cgl = ast_calloc(1, sizeof(*cgl) + strlen(group) + 1);
1735 if (!cgl) {
1737 return -1;
1738 }
1739 strcpy(cgl->name, group); /* Safe */
1741 } /* else, already existed, and was already enabled, no change */
1742 callid_filtering = 1;
1744 return 0;
1745}
#define ast_calloc(num, len)
A wrapper for calloc()
Definition astmm.h:202
static int enabled
Definition dnsmgr.c:91
#define AST_RWLIST_REMOVE_CURRENT
#define AST_RWLIST_TRAVERSE_SAFE_BEGIN
#define AST_LIST_EMPTY(head)
Checks whether the specified list contains any entries.
#define AST_RWLIST_TRAVERSE_SAFE_END
char name[0]
Definition logger.c:1648

References ast_calloc, ast_free, AST_LIST_EMPTY, AST_RWLIST_INSERT_HEAD, AST_RWLIST_REMOVE_CURRENT, AST_RWLIST_TRAVERSE_SAFE_BEGIN, AST_RWLIST_TRAVERSE_SAFE_END, AST_RWLIST_UNLOCK, AST_RWLIST_WRLOCK, callid_filtering, enabled, chan_group_lock::entry, and chan_group_lock::name.

Referenced by handle_logger_chanloggroup_filter().

◆ callid_logging_enabled()

static int callid_logging_enabled ( void  )
static

Definition at line 1747 of file logger.c.

1748{
1749 struct chan_group_lock *cgl;
1750 const char *callidgroup;
1751
1752 if (!callid_filtering) {
1753 return 1; /* Everything enabled by default, if no filtering */
1754 }
1755
1756 callidgroup = get_callid_group();
1757 if (!callidgroup) {
1758 return 0; /* Filtering, but no call group, not enabled */
1759 }
1760
1763 if (!strcmp(callidgroup, cgl->name)) {
1764 break;
1765 }
1766 }
1768 return cgl ? 1 : 0; /* If found, enabled, otherwise not */
1769}
static const char * get_callid_group(void)
Definition logger.c:1655

References AST_RWLIST_RDLOCK, AST_RWLIST_TRAVERSE, AST_RWLIST_UNLOCK, callid_filtering, chan_group_lock::entry, get_callid_group(), and chan_group_lock::name.

Referenced by ast_log_full().

◆ callid_set_chanloggroup()

static int callid_set_chanloggroup ( const char *  group)
static

Definition at line 1662 of file logger.c.

1663{
1664 /* Use threadstorage for constant time access, rather than a linked list */
1665 ast_callid callid;
1666 char **callid_group;
1667
1669 if (!callid) {
1670 /* Should never be called on non-PBX threads */
1671 ast_assert(0);
1672 return -1;
1673 }
1674
1675 callid_group = ast_threadstorage_get(&callid_group_name, sizeof(*callid_group));
1676
1677 if (!group) {
1678 /* Remove from list */
1679 if (!*callid_group) {
1680 return 0; /* Wasn't in any group to begin with */
1681 }
1682 ast_free(*callid_group);
1683 return 0; /* Set Call ID group for the first time */
1684 }
1685 /* Existing group */
1686 ast_free(*callid_group);
1687 *callid_group = ast_strdup(group);
1688 if (!*callid_group) {
1689 return -1;
1690 }
1691 return 0; /* Set Call ID group for the first time */
1692}
#define ast_strdup(str)
A wrapper for strdup()
Definition astmm.h:241
#define ast_assert(a)
Definition utils.h:779

References ast_assert, ast_free, ast_read_threadstorage_callid(), ast_strdup, and ast_threadstorage_get().

Referenced by log_group_write().

◆ close_logger()

void close_logger ( void  )

Provided by logger.c

Definition at line 2215 of file logger.c.

2216{
2217 struct logchannel *f = NULL;
2218
2220
2223
2225
2226 /* Stop logger thread */
2231
2233 pthread_join(logthread, NULL);
2234 }
2235
2237
2238 if (qlog) {
2239 fclose(qlog);
2240 qlog = NULL;
2241 }
2242
2243 while ((f = AST_LIST_REMOVE_HEAD(&logchannels, list))) {
2244 if (f->fileptr && (f->fileptr != stdout) && (f->fileptr != stderr)) {
2245 fclose(f->fileptr);
2246 f->fileptr = NULL;
2247 }
2248 ast_free(f);
2249 }
2250
2252
2253 closelog(); /* syslog */
2254
2256}
void ast_cli_unregister_multiple(void)
Definition ael_main.c:408
#define AST_LIST_REMOVE_HEAD(head, field)
Removes and returns the head entry from a list.
static int callid_group_remove_filters(void)
Definition logger.c:1694
static struct ast_custom_function log_group_function
Definition logger.c:1781
static struct ast_cli_entry cli_logger[]
Definition logger.c:1871
int ast_logger_category_unload(void)
Unload system wide logger category functionality.
int ast_custom_function_unregister(struct ast_custom_function *acf)
Unregister a custom function.

References ARRAY_LEN, ast_cli_unregister_multiple(), ast_cond_signal, ast_custom_function_unregister(), ast_free, AST_LIST_LOCK, AST_LIST_REMOVE_HEAD, AST_LIST_UNLOCK, ast_logger_category_unload(), AST_PTHREADT_NULL, AST_RWLIST_UNLOCK, AST_RWLIST_WRLOCK, callid_group_remove_filters(), cli_logger, close_logger_thread, logchannel::fileptr, logchannel::list, log_group_function, logcond, logger_initialized, logthread, NULL, and qlog.

Referenced by really_quit().

◆ custom_level_still_exists()

static int custom_level_still_exists ( char **  levels,
char *  level,
size_t  len 
)
static

Checks if level exists in array of level names.

Parameters
levelsArray of level names
levelName to search for
lenSize of levels
Return values
1Found
0Not Found

Definition at line 736 of file logger.c.

737{
738 int i;
739 for (i = 0; i < len; i++) {
740 if (!strcmp(levels[i], level)) {
741 return 1;
742 }
743 }
744 return 0;
745}
static int len(struct ast_channel *chan, const char *cmd, char *data, char *buf, size_t buflen)

References len(), and levels.

Referenced by init_logger_chain().

◆ find_logchannel()

static struct logchannel * find_logchannel ( const char *  channel)
static

Find a particular logger channel by name.

Precondition
logchannels list is locked
Parameters
channelThe name of the logger channel to find
Return values
non-NULLThe corresponding logger channel
NULLUnable to find a logger channel with that particular name

Definition at line 627 of file logger.c.

628{
629 char filename[PATH_MAX];
630 struct logchannel *chan;
631
632 make_filename(channel, filename, sizeof(filename));
633
635 if (!strcmp(chan->filename, filename)) {
636 return chan;
637 }
638 }
639
640 return NULL;
641}

References AST_RWLIST_TRAVERSE, logchannel::filename, logchannel::list, make_filename(), NULL, and PATH_MAX.

Referenced by ast_logger_create_channel(), and ast_logger_remove_channel().

◆ format_log_default()

static int format_log_default ( struct logchannel chan,
struct logmsg msg,
char *  buf,
size_t  size 
)
static

Definition at line 391 of file logger.c.

392{
393 char call_identifier_str[13];
394
395 if (msg->callid) {
396 snprintf(call_identifier_str, sizeof(call_identifier_str), "[C-%08x]", msg->callid);
397 } else {
398 call_identifier_str[0] = '\0';
399 }
400
401 switch (chan->type) {
402 case LOGTYPE_SYSLOG:
403 snprintf(buf, size, "%s[%d]%s: %s:%d in %s: %s",
404 levels[msg->level], msg->lwp, call_identifier_str, msg->file,
405 msg->line, msg->function, msg->message);
406 term_strip(buf, buf, size);
407 break;
408 case LOGTYPE_FILE:
409 snprintf(buf, size, "[%s] %s[%d]%s %s: %s",
410 msg->date, msg->level_name, msg->lwp, call_identifier_str,
411 msg->file, msg->message);
412 term_strip(buf, buf, size);
413 break;
414 case LOGTYPE_CONSOLE:
415 {
416 char linestr[32];
417 int has_file = !ast_strlen_zero(msg->file);
418 int has_line = (msg->line > 0);
419 int has_func = !ast_strlen_zero(msg->function);
420
421 /*
422 * Verbose messages are interpreted by console channels in their own
423 * special way
424 */
425 if (msg->level == __LOG_VERBOSE) {
426 return logger_add_verbose_magic(msg, buf, size);
427 }
428
429 /* Turn the numerical line number into a string */
430 snprintf(linestr, sizeof(linestr), "%d", msg->line);
431 /* Build string to print out */
432 snprintf(buf, size, "[%s] " COLORIZE_FMT "[%d]%s: " COLORIZE_FMT "%s" COLORIZE_FMT " " COLORIZE_FMT "%s %s",
433 msg->date,
434 COLORIZE(colors[msg->level], 0, msg->level_name),
435 msg->lwp,
436 call_identifier_str,
437 COLORIZE(COLOR_BRWHITE, 0, has_file ? msg->file : ""),
438 has_file ? ":" : "",
439 COLORIZE(COLOR_BRWHITE, 0, has_line ? linestr : ""),
440 COLORIZE(COLOR_BRWHITE, 0, has_func ? msg->function : ""),
441 has_func ? ":" : "",
442 msg->message);
443 }
444 break;
445 }
446
447 return 0;
448}
static int logger_add_verbose_magic(struct logmsg *logmsg, char *buf, size_t size)
Definition logger.c:333
static const int colors[NUMLOGLEVELS]
Colors used in the console for logging.
Definition logger.c:231
const ast_string_field level_name
Definition logger.c:183
int lwp
Definition logger.c:174
const ast_string_field message
Definition logger.c:183
const ast_string_field date
Definition logger.c:183
#define COLOR_BRWHITE
Definition term.h:65
char * term_strip(char *outbuf, const char *inbuf, int maxout)
Remove colorings from a specified string.
Definition term.c:362
#define COLORIZE(fg, bg, str)
Definition term.h:72
#define COLORIZE_FMT
Shortcut macros for coloring a set of text.
Definition term.h:71

References __LOG_VERBOSE, ast_strlen_zero(), buf, logmsg::callid, COLOR_BRWHITE, COLORIZE, COLORIZE_FMT, colors, logmsg::date, logmsg::file, logmsg::function, logmsg::level, logmsg::level_name, levels, logmsg::line, logger_add_verbose_magic(), LOGTYPE_CONSOLE, LOGTYPE_FILE, LOGTYPE_SYSLOG, logmsg::lwp, logmsg::message, term_strip(), and logchannel::type.

◆ format_log_json()

static int format_log_json ( struct logchannel channel,
struct logmsg msg,
char *  buf,
size_t  size 
)
static

Definition at line 273 of file logger.c.

274{
275 struct ast_json *json;
276 char *str;
277 char call_identifier_str[13];
278 size_t json_str_len;
279
280 if (msg->callid) {
281 snprintf(call_identifier_str, sizeof(call_identifier_str), "[C-%08x]", msg->callid);
282 } else {
283 call_identifier_str[0] = '\0';
284 }
285
286 json = ast_json_pack("{s: s, s: s, "
287 "s: {s: i, s: s}, "
288 "s: {s: {s: s, s: s, s: i}, "
289 "s: s, s: s} }",
290 "hostname", ast_config_AST_SYSTEM_NAME,
291 "timestamp", msg->date,
292 "identifiers",
293 "lwp", msg->lwp,
294 "callid", S_OR(call_identifier_str, ""),
295 "logmsg",
296 "location",
297 "filename", msg->file,
298 "function", msg->function,
299 "line", msg->line,
300 "level", msg->level_name,
301 "message", msg->message);
302 if (!json) {
303 return -1;
304 }
305
307 if (!str) {
308 ast_json_unref(json);
309 return -1;
310 }
311
312 ast_copy_string(buf, str, size);
313 json_str_len = strlen(str);
314 if (json_str_len > size - 1) {
315 json_str_len = size - 1;
316 }
317 buf[json_str_len] = '\n';
318 buf[json_str_len + 1] = '\0';
319
320 term_strip(buf, buf, size);
321
323 ast_json_unref(json);
324
325 return 0;
326}
const char * str
Definition app_jack.c:150
void ast_json_unref(struct ast_json *value)
Decrease refcount on value. If refcount reaches zero, value is freed.
Definition json.c:73
void ast_json_free(void *p)
Asterisk's custom JSON allocator. Exposed for use by unit tests.
Definition json.c:52
#define ast_json_dump_string(root)
Encode a JSON value to a compact string.
Definition json.h:810
struct ast_json * ast_json_pack(char const *format,...)
Helper for creating complex JSON values.
Definition json.c:612
const char * ast_config_AST_SYSTEM_NAME
Definition options.c:171
void ast_copy_string(char *dst, const char *src, size_t size)
Size-limited null-terminating string copy.
Definition strings.h:425
Abstract JSON element (object, array, string, int, ...).

References ast_config_AST_SYSTEM_NAME, ast_copy_string(), ast_json_dump_string, ast_json_free(), ast_json_pack(), ast_json_unref(), buf, logmsg::callid, logmsg::date, logmsg::file, logmsg::function, logmsg::level_name, logmsg::line, logmsg::lwp, logmsg::message, S_OR, str, and term_strip().

◆ format_log_message()

static struct logmsg * format_log_message ( int  level,
int  sublevel,
const char *  file,
int  line,
const char *  function,
ast_callid  callid,
const char *  fmt,
  ... 
)
static

Definition at line 2052 of file logger.c.

2055{
2056 struct logmsg *logmsg;
2057 va_list ap;
2058
2059 va_start(ap, fmt);
2061 va_end(ap);
2062
2063 return logmsg;
2064}

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

Referenced by ast_log_full(), and logger_thread().

◆ format_log_message_ap()

static struct logmsg * format_log_message_ap ( int  level,
int  sublevel,
const char *  file,
int  line,
const char *  function,
ast_callid  callid,
const char *  fmt,
va_list  ap 
)
static

Definition at line 1988 of file logger.c.

1991{
1992 struct logmsg *logmsg = NULL;
1993 struct ast_str *buf = NULL;
1994 struct ast_tm tm;
1995 struct timeval now = ast_tvnow();
1996 int res = 0;
1997 char datestring[256];
1998
1999 if (!(buf = ast_str_thread_get(&log_buf, LOG_BUF_INIT_SIZE))) {
2000 return NULL;
2001 }
2002
2003 /* Build string */
2004 res = ast_str_set_va(&buf, LOGMSG_SIZE, fmt, ap);
2005
2006 /* If the build failed, then abort and free this structure */
2007 if (res == AST_DYNSTR_BUILD_FAILED) {
2008 return NULL;
2009 }
2010
2011 /* Automatically add a newline to format strings that don't have one */
2012 if (!ast_ends_with(ast_str_buffer(buf), "\n")) {
2013 ast_str_append(&buf, 0, "\n");
2014 }
2015
2016 /* Create a new logging message */
2017 if (!(logmsg = ast_calloc_with_stringfields(1, struct logmsg, res + 128))) {
2018 return NULL;
2019 }
2020
2021 /* Copy string over */
2023
2024 /* Set type */
2025 if (level == __LOG_VERBOSE) {
2027 } else {
2029 }
2030
2031 if (display_callids && callid) {
2032 logmsg->callid = callid;
2033 }
2034
2035 /* Create our date/time */
2036 ast_localtime(&now, &tm, NULL);
2037 ast_strftime(datestring, sizeof(datestring), dateformat, &tm);
2038 ast_string_field_set(logmsg, date, datestring);
2039
2040 /* Copy over data */
2041 logmsg->level = level;
2042 logmsg->sublevel = sublevel;
2043 logmsg->line = line;
2044 ast_string_field_set(logmsg, level_name, levels[level]);
2045 ast_string_field_set(logmsg, file, file);
2046 ast_string_field_set(logmsg, function, function);
2047 logmsg->lwp = ast_get_tid();
2048
2049 return logmsg;
2050}
static int display_callids
Definition logger.c:88
#define LOG_BUF_INIT_SIZE
Definition logger.c:271
#define LOGMSG_SIZE
Definition logger.c:100
#define ast_calloc_with_stringfields(n, type, size)
Allocate a structure with embedded stringfields in a single allocation.
#define ast_string_field_set(x, field, data)
Set a field to a simple string value.
int ast_str_set_va(struct ast_str **buf, ssize_t max_len, const char *fmt, va_list ap)
Set a dynamic string from a va_list.
Definition strings.h:1030
static int force_inline attribute_pure ast_ends_with(const char *str, const char *suffix)
Checks whether a string ends with another.
Definition strings.h:116
@ AST_DYNSTR_BUILD_FAILED
Definition strings.h:943
struct ast_str * ast_str_thread_get(struct ast_threadstorage *ts, size_t init_len)
Retrieve a thread locally stored dynamic string.
Definition strings.h:909
enum logmsgtypes type
Definition logger.c:170
int ast_get_tid(void)
Get current thread ID.
Definition utils.c:2788

References __LOG_VERBOSE, ast_calloc_with_stringfields, AST_DYNSTR_BUILD_FAILED, ast_ends_with(), ast_get_tid(), ast_localtime(), ast_str_append(), ast_str_buffer(), ast_str_set_va(), ast_str_thread_get(), ast_strftime(), ast_string_field_set, ast_tvnow(), buf, logmsg::callid, dateformat, display_callids, logmsg::level, levels, logmsg::line, LOG_BUF_INIT_SIZE, LOGMSG_NORMAL, LOGMSG_SIZE, LOGMSG_VERBOSE, logmsg::lwp, NULL, logmsg::sublevel, and logmsg::type.

Referenced by ast_log_full(), and format_log_message().

◆ format_log_plain()

static int format_log_plain ( struct logchannel chan,
struct logmsg msg,
char *  buf,
size_t  size 
)
static

Definition at line 455 of file logger.c.

456{
457 char call_identifier_str[13];
458 char linestr[32];
459 int has_file = !ast_strlen_zero(msg->file);
460 int has_line = (msg->line > 0);
461 int has_func = !ast_strlen_zero(msg->function);
462
463 if (msg->callid) {
464 snprintf(call_identifier_str, sizeof(call_identifier_str), "[C-%08x]", msg->callid);
465 } else {
466 call_identifier_str[0] = '\0';
467 }
468
469 switch (chan->type) {
470 case LOGTYPE_SYSLOG:
471 snprintf(buf, size, "%s[%d]%s: %s:%d in %s: %s",
472 levels[msg->level], msg->lwp, call_identifier_str, msg->file,
473 msg->line, msg->function, msg->message);
474 term_strip(buf, buf, size);
475 break;
476 case LOGTYPE_FILE:
477 case LOGTYPE_CONSOLE:
478 /* Turn the numerical line number into a string */
479 snprintf(linestr, sizeof(linestr), "%d", msg->line);
480 /* Build string to print out */
481 snprintf(buf, size, "[%s] %s[%d]%s: %s%s%s%s%s%s%s",
482 msg->date,
483 msg->level_name,
484 msg->lwp,
485 call_identifier_str,
486 has_file ? msg->file : "",
487 has_file ? ":" : "",
488 has_line ? linestr : "",
489 has_line ? " " : "",
490 has_func ? msg->function : "",
491 has_func ? ": " : "",
492 msg->message);
493 term_strip(buf, buf, size);
494 break;
495 }
496
497 return 0;
498}

References ast_strlen_zero(), buf, logmsg::callid, logmsg::date, logmsg::file, logmsg::function, logmsg::level, logmsg::level_name, levels, logmsg::line, LOGTYPE_CONSOLE, LOGTYPE_FILE, LOGTYPE_SYSLOG, logmsg::lwp, logmsg::message, term_strip(), and logchannel::type.

◆ get_callid_group()

static const char * get_callid_group ( void  )
static

Definition at line 1655 of file logger.c.

1656{
1657 char **callid_group;
1658 callid_group = ast_threadstorage_get(&callid_group_name, sizeof(*callid_group));
1659 return callid_group ? *callid_group : NULL;
1660}

References ast_threadstorage_get(), and NULL.

Referenced by callid_logging_enabled().

◆ handle_logger_add_channel()

static char * handle_logger_add_channel ( struct ast_cli_entry e,
int  cmd,
struct ast_cli_args a 
)
static

Definition at line 1531 of file logger.c.

1532{
1533 switch (cmd) {
1534 case CLI_INIT:
1535 e->command = "logger add channel";
1536 e->usage =
1537 "Usage: logger add channel <name> <levels>\n"
1538 " Adds a temporary logger channel. This logger channel\n"
1539 " will exist until removed or until Asterisk is restarted.\n"
1540 " <levels> is a comma-separated list of desired logger\n"
1541 " levels such as: verbose,warning,error\n"
1542 " An optional formatter may be specified with the levels;\n"
1543 " valid values are '[json]' and '[default]'.\n";
1544 return NULL;
1545 case CLI_GENERATE:
1546 return NULL;
1547 }
1548
1549 if (a->argc < 5) {
1550 return CLI_SHOWUSAGE;
1551 }
1552
1553 switch (ast_logger_create_channel(a->argv[3], a->argv[4])) {
1554 case AST_LOGGER_SUCCESS:
1555 return CLI_SUCCESS;
1556 case AST_LOGGER_FAILURE:
1557 ast_cli(a->fd, "Logger channel '%s' already exists\n", a->argv[3]);
1558 return CLI_SUCCESS;
1559 case AST_LOGGER_DECLINE:
1561 default:
1562 ast_cli(a->fd, "ERROR: Unable to create log channel '%s'\n", a->argv[3]);
1563 return CLI_FAILURE;
1564 }
1565}
#define CLI_SHOWUSAGE
Definition cli.h:45
#define CLI_SUCCESS
Definition cli.h:44
void ast_cli(int fd, const char *fmt,...)
Definition clicompat.c:6
@ CLI_INIT
Definition cli.h:152
@ CLI_GENERATE
Definition cli.h:153
#define CLI_FAILURE
Definition cli.h:46
int ast_logger_create_channel(const char *log_channel, const char *components)
Create a log channel.
Definition logger.c:1501
char * command
Definition cli.h:186
const char * usage
Definition cli.h:177
static struct test_val a

References a, ast_cli(), AST_LOGGER_ALLOC_ERROR, ast_logger_create_channel(), AST_LOGGER_DECLINE, AST_LOGGER_FAILURE, AST_LOGGER_SUCCESS, CLI_FAILURE, CLI_GENERATE, CLI_INIT, CLI_SHOWUSAGE, CLI_SUCCESS, ast_cli_entry::command, NULL, and ast_cli_entry::usage.

◆ handle_logger_chanloggroup_filter()

static char * handle_logger_chanloggroup_filter ( struct ast_cli_entry e,
int  cmd,
struct ast_cli_args a 
)
static

Definition at line 1786 of file logger.c.

1787{
1788 int enabled;
1789
1790 switch (cmd) {
1791 case CLI_INIT:
1792 e->command = "logger filter changroup";
1793 e->usage =
1794 "Usage: logger filter changroup <group> {on|off}\n"
1795 " Add or remove channel groups from log filtering.\n"
1796 " If filtering is active, only channels assigned\n"
1797 " to a group that has been enabled using this command\n"
1798 " will have execution shown in the CLI.\n";
1799 return NULL;
1800 case CLI_GENERATE:
1801 return NULL;
1802 }
1803
1804 if (a->argc < 5) {
1805 return CLI_SHOWUSAGE;
1806 }
1807
1808 enabled = ast_true(a->argv[4]) ? 1 : 0;
1809 if (callid_group_set_filter(a->argv[3], enabled)) {
1810 ast_cli(a->fd, "Failed to set channel group filter for group %s\n", a->argv[3]);
1811 return CLI_FAILURE;
1812 }
1813
1814 ast_cli(a->fd, "Logging of channel group '%s' is now %s\n", a->argv[3], enabled ? "enabled" : "disabled");
1815 return CLI_SUCCESS;
1816}
static int callid_group_set_filter(const char *group, int enabled)
Definition logger.c:1709
int attribute_pure ast_true(const char *val)
Make sure something is true. Determine if a string containing a boolean value is "true"....
Definition utils.c:2235

References a, ast_cli(), ast_true(), callid_group_set_filter(), CLI_FAILURE, CLI_GENERATE, CLI_INIT, CLI_SHOWUSAGE, CLI_SUCCESS, ast_cli_entry::command, enabled, NULL, and ast_cli_entry::usage.

◆ handle_logger_filter_reset()

static char * handle_logger_filter_reset ( struct ast_cli_entry e,
int  cmd,
struct ast_cli_args a 
)
static

Definition at line 1848 of file logger.c.

1849{
1850 int removed;
1851
1852 switch (cmd) {
1853 case CLI_INIT:
1854 e->command = "logger filter reset";
1855 e->usage =
1856 "Usage: logger filter reset\n"
1857 " Reset the logger filter.\n"
1858 " This removes any channel groups from filtering\n"
1859 " (all channel execution will be shown)\n";
1860 return NULL;
1861 case CLI_GENERATE:
1862 return NULL;
1863 }
1864
1865 removed = callid_group_remove_filters();
1866
1867 ast_cli(a->fd, "Log filtering has been reset (%d filter%s removed)\n", removed, ESS(removed));
1868 return CLI_SUCCESS;
1869}
#define ESS(x)
Definition cli.h:59

References a, ast_cli(), callid_group_remove_filters(), CLI_GENERATE, CLI_INIT, CLI_SUCCESS, ast_cli_entry::command, ESS, NULL, and ast_cli_entry::usage.

◆ handle_logger_filter_show()

static char * handle_logger_filter_show ( struct ast_cli_entry e,
int  cmd,
struct ast_cli_args a 
)
static

Definition at line 1818 of file logger.c.

1819{
1820 int i = 0;
1821 struct chan_group_lock *cgl;
1822
1823 switch (cmd) {
1824 case CLI_INIT:
1825 e->command = "logger filter show";
1826 e->usage =
1827 "Usage: logger filter show\n"
1828 " Show current logger filtering settings.\n";
1829 return NULL;
1830 case CLI_GENERATE:
1831 return NULL;
1832 }
1833
1836 ast_cli(a->fd, "%3d %-32s\n", ++i, cgl->name);
1837 }
1839
1840 if (i) {
1841 ast_cli(a->fd, "%d channel group%s currently enabled\n", i, ESS(i));
1842 } else {
1843 ast_cli(a->fd, "No filtering currently active\n");
1844 }
1845 return CLI_SUCCESS;
1846}

References a, ast_cli(), AST_RWLIST_RDLOCK, AST_RWLIST_TRAVERSE, AST_RWLIST_UNLOCK, CLI_GENERATE, CLI_INIT, CLI_SUCCESS, ast_cli_entry::command, chan_group_lock::entry, ESS, chan_group_lock::name, NULL, and ast_cli_entry::usage.

◆ handle_logger_reload()

static char * handle_logger_reload ( struct ast_cli_entry e,
int  cmd,
struct ast_cli_args a 
)
static

Definition at line 1269 of file logger.c.

1270{
1271 switch (cmd) {
1272 case CLI_INIT:
1273 e->command = "logger reload";
1274 e->usage =
1275 "Usage: logger reload [<alt-conf>]\n"
1276 " Reloads the logger subsystem state. Use after restarting syslogd(8) if you are using syslog logging.\n";
1277 return NULL;
1278 case CLI_GENERATE:
1279 return NULL;
1280 }
1281 if (reload_logger(0, a->argc == 3 ? a->argv[2] : NULL)) {
1282 ast_cli(a->fd, "Failed to reload the logger\n");
1283 return CLI_FAILURE;
1284 }
1285 return CLI_SUCCESS;
1286}

References a, ast_cli(), CLI_FAILURE, CLI_GENERATE, CLI_INIT, CLI_SUCCESS, ast_cli_entry::command, NULL, reload_logger(), and ast_cli_entry::usage.

◆ handle_logger_remove_channel()

static char * handle_logger_remove_channel ( struct ast_cli_entry e,
int  cmd,
struct ast_cli_args a 
)
static

Definition at line 1592 of file logger.c.

1593{
1594 struct logchannel *chan;
1595 int gen_count = 0;
1596 char *gen_ret = NULL;
1597
1598 switch (cmd) {
1599 case CLI_INIT:
1600 e->command = "logger remove channel";
1601 e->usage =
1602 "Usage: logger remove channel <name>\n"
1603 " Removes a temporary logger channel.\n";
1604 return NULL;
1605 case CLI_GENERATE:
1606 if (a->argc > 4 || (a->argc == 4 && a->pos > 3)) {
1607 return NULL;
1608 }
1611 if (chan->dynamic && (ast_strlen_zero(a->argv[3])
1612 || !strncmp(a->argv[3], chan->filename, strlen(a->argv[3])))) {
1613 if (gen_count == a->n) {
1614 gen_ret = ast_strdup(chan->filename);
1615 break;
1616 }
1617 gen_count++;
1618 }
1619 }
1621 return gen_ret;
1622 }
1623
1624 if (a->argc < 4) {
1625 return CLI_SHOWUSAGE;
1626 }
1627
1628 switch (ast_logger_remove_channel(a->argv[3])) {
1629 case AST_LOGGER_SUCCESS:
1630 ast_cli(a->fd, "Removed dynamic logger channel '%s'\n", a->argv[3]);
1631 return CLI_SUCCESS;
1632 case AST_LOGGER_FAILURE:
1633 ast_cli(a->fd, "Unable to find dynamic logger channel '%s'\n", a->argv[3]);
1634 return CLI_SUCCESS;
1635 default:
1636 ast_cli(a->fd, "Internal failure attempting to delete dynamic logger channel '%s'\n", a->argv[3]);
1637 return CLI_FAILURE;
1638 }
1639}
int ast_logger_remove_channel(const char *log_channel)
Delete the specified log channel.
Definition logger.c:1567

References a, ast_cli(), AST_LOGGER_FAILURE, ast_logger_remove_channel(), AST_LOGGER_SUCCESS, AST_RWLIST_RDLOCK, AST_RWLIST_TRAVERSE, AST_RWLIST_UNLOCK, ast_strdup, ast_strlen_zero(), CLI_FAILURE, CLI_GENERATE, CLI_INIT, CLI_SHOWUSAGE, CLI_SUCCESS, ast_cli_entry::command, logchannel::dynamic, logchannel::filename, logchannel::list, NULL, and ast_cli_entry::usage.

◆ handle_logger_rotate()

static char * handle_logger_rotate ( struct ast_cli_entry e,
int  cmd,
struct ast_cli_args a 
)
static

Definition at line 1288 of file logger.c.

1289{
1290 switch (cmd) {
1291 case CLI_INIT:
1292 e->command = "logger rotate";
1293 e->usage =
1294 "Usage: logger rotate\n"
1295 " Rotates and Reopens the log files.\n";
1296 return NULL;
1297 case CLI_GENERATE:
1298 return NULL;
1299 }
1300 if (reload_logger(1, NULL)) {
1301 ast_cli(a->fd, "Failed to reload the logger and rotate log files\n");
1302 return CLI_FAILURE;
1303 }
1304 return CLI_SUCCESS;
1305}

References a, ast_cli(), CLI_FAILURE, CLI_GENERATE, CLI_INIT, CLI_SUCCESS, ast_cli_entry::command, NULL, reload_logger(), and ast_cli_entry::usage.

◆ handle_logger_set_level()

static char * handle_logger_set_level ( struct ast_cli_entry e,
int  cmd,
struct ast_cli_args a 
)
static

Definition at line 1347 of file logger.c.

1348{
1349 int x;
1350 int state;
1351 int level = -1;
1352
1353 switch (cmd) {
1354 case CLI_INIT:
1355 e->command = "logger set level {DEBUG|TRACE|NOTICE|WARNING|ERROR|VERBOSE|DTMF} {on|off}";
1356 e->usage =
1357 "Usage: logger set level {DEBUG|TRACE|NOTICE|WARNING|ERROR|VERBOSE|DTMF} {on|off}\n"
1358 " Set a specific log level to enabled/disabled for this console.\n";
1359 return NULL;
1360 case CLI_GENERATE:
1361 return NULL;
1362 }
1363
1364 if (a->argc < 5)
1365 return CLI_SHOWUSAGE;
1366
1368
1369 for (x = 0; x < ARRAY_LEN(levels); x++) {
1370 if (levels[x] && !strcasecmp(a->argv[3], levels[x])) {
1371 level = x;
1372 break;
1373 }
1374 }
1375
1377
1378 state = ast_true(a->argv[4]) ? 1 : 0;
1379
1380 if (level != -1) {
1381 ast_console_toggle_loglevel(a->fd, level, state);
1382 ast_cli(a->fd, "Logger status for '%s' has been set to '%s'.\n", levels[level], state ? "on" : "off");
1383 } else
1384 return CLI_SHOWUSAGE;
1385
1386 return CLI_SUCCESS;
1387}
void ast_console_toggle_loglevel(int fd, int level, int state)
enables or disables logging of a specified level to the console
Definition asterisk.c:1263

References a, ARRAY_LEN, ast_cli(), ast_console_toggle_loglevel(), AST_RWLIST_UNLOCK, AST_RWLIST_WRLOCK, ast_true(), CLI_GENERATE, CLI_INIT, CLI_SHOWUSAGE, CLI_SUCCESS, ast_cli_entry::command, levels, NULL, and ast_cli_entry::usage.

◆ handle_logger_show_channels()

static char * handle_logger_show_channels ( struct ast_cli_entry e,
int  cmd,
struct ast_cli_args a 
)
static

CLI command to show logging system configuration.

Definition at line 1432 of file logger.c.

1433{
1434#define FORMATL "%-35.35s %-8.8s %-10.10s %-9.9s "
1435 struct logchannel *chan;
1436 switch (cmd) {
1437 case CLI_INIT:
1438 e->command = "logger show channels";
1439 e->usage =
1440 "Usage: logger show channels\n"
1441 " List configured logger channels.\n";
1442 return NULL;
1443 case CLI_GENERATE:
1444 return NULL;
1445 }
1446 ast_cli(a->fd, "Logger queue limit: %d\n\n", logger_queue_limit);
1447 ast_cli(a->fd, FORMATL, "Channel", "Type", "Formatter", "Status");
1448 ast_cli(a->fd, "Configuration\n");
1449 ast_cli(a->fd, FORMATL, "-------", "----", "---------", "------");
1450 ast_cli(a->fd, "-------------\n");
1453 unsigned int level;
1454
1455 ast_cli(a->fd, FORMATL, chan->filename, chan->type == LOGTYPE_CONSOLE ? "Console" : (chan->type == LOGTYPE_SYSLOG ? "Syslog" : "File"),
1456 chan->formatter.name,
1457 chan->disabled ? "Disabled" : "Enabled");
1458 ast_cli(a->fd, " - ");
1459 for (level = 0; level < ARRAY_LEN(levels); level++) {
1460 if ((chan->logmask & (1 << level)) && levels[level]) {
1461 ast_cli(a->fd, "%s ", levels[level]);
1462 }
1463 }
1464 ast_cli(a->fd, "\n");
1465 }
1467 ast_cli(a->fd, "\n");
1468
1469 return CLI_SUCCESS;
1470}
#define FORMATL
struct logformatter formatter
Definition logger.c:137

References a, ARRAY_LEN, ast_cli(), AST_RWLIST_RDLOCK, AST_RWLIST_TRAVERSE, AST_RWLIST_UNLOCK, CLI_GENERATE, CLI_INIT, CLI_SUCCESS, ast_cli_entry::command, logchannel::disabled, logchannel::filename, FORMATL, logchannel::formatter, levels, logchannel::list, logger_queue_limit, logchannel::logmask, LOGTYPE_CONSOLE, LOGTYPE_SYSLOG, logformatter::name, NULL, logchannel::type, and ast_cli_entry::usage.

◆ handle_logger_show_levels()

static char * handle_logger_show_levels ( struct ast_cli_entry e,
int  cmd,
struct ast_cli_args a 
)
static

CLI command to show logging levels.

Definition at line 1473 of file logger.c.

1474{
1475#define FORMATL2 "%5s %s\n"
1476 unsigned int level;
1477 switch (cmd) {
1478 case CLI_INIT:
1479 e->command = "logger show levels";
1480 e->usage =
1481 "Usage: logger show levels\n"
1482 " List configured logger levels.\n";
1483 return NULL;
1484 case CLI_GENERATE:
1485 return NULL;
1486 }
1487 ast_cli(a->fd, FORMATL2, "Level", "Name");
1488 ast_cli(a->fd, FORMATL2, "-----", "----");
1490 for (level = 0; level < ARRAY_LEN(levels); level++) {
1491 if (levels[level]) {
1492 ast_cli(a->fd, "%5d %s\n", level, levels[level]);
1493 }
1494 }
1496 ast_cli(a->fd, "\n");
1497
1498 return CLI_SUCCESS;
1499}
#define FORMATL2

References a, ARRAY_LEN, ast_cli(), AST_RWLIST_RDLOCK, AST_RWLIST_UNLOCK, CLI_GENERATE, CLI_INIT, CLI_SUCCESS, ast_cli_entry::command, FORMATL2, levels, NULL, and ast_cli_entry::usage.

◆ init_logger()

int init_logger ( void  )

Provided by logger.c

Definition at line 2172 of file logger.c.

2173{
2174 int res;
2175 /* auto rotate if sig SIGXFSZ comes a-knockin */
2176 sigaction(SIGXFSZ, &handle_SIGXFSZ, NULL);
2177
2178 /* Re-initialize the logmsgs mutex. The recursive mutex can be accessed prior
2179 * to Asterisk being forked into the background, which can cause the thread
2180 * ID tracked by the underlying pthread mutex to be different than the ID of
2181 * the thread that unlocks the mutex. Since init_logger is called after the
2182 * fork, it is safe to initialize the mutex here for future accesses.
2183 */
2187
2188 /* start logger thread */
2191 return -1;
2192 }
2193
2194 /* register the logger cli commands */
2197
2199
2200 /* create log channels */
2202 res = init_logger_chain(NULL);
2206 if (res) {
2207 ast_log(LOG_ERROR, "Errors detected in logger.conf. Default console logging is being used.\n");
2208 }
2209
2211
2212 return 0;
2213}
#define ast_cli_register_multiple(e, len)
Register multiple commands.
Definition cli.h:265
#define ast_cond_destroy(cond)
Definition lock.h:209
#define ast_cond_init(cond, attr)
Definition lock.h:208
#define ast_mutex_init(pmutex)
Definition lock.h:193
#define ast_mutex_destroy(a)
Definition lock.h:195
static struct sigaction handle_SIGXFSZ
Definition logger.c:1890
static void * logger_thread(void *data)
Actual logging thread.
Definition logger.c:2067
int ast_logger_category_load(void)
Load/Initialize system wide logger category functionality.
#define ast_custom_function_register(acf)
Register a custom function.
Definition pbx.h:1562
ast_mutex_t lock
Definition logger.c:193
#define ast_pthread_create(a, b, c, d)
Definition utils.h:624

References ARRAY_LEN, ast_cli_register_multiple, ast_cond_destroy, ast_cond_init, ast_config_AST_LOG_DIR, ast_custom_function_register, ast_log, ast_logger_category_load(), ast_mkdir(), ast_mutex_destroy, ast_mutex_init, ast_pthread_create, AST_RWLIST_UNLOCK, AST_RWLIST_WRLOCK, ast_verb_update(), cli_logger, handle_SIGXFSZ, init_logger_chain(), logmsgs::lock, LOG_ERROR, log_group_function, logcond, logger_initialized, logger_thread(), logthread, and NULL.

Referenced by asterisk_daemon().

◆ init_logger_chain()

static int init_logger_chain ( const char *  altconf)
static

Read config, setup channels.

Parameters
altconfAlternate configuration file to read.
Precondition
logchannels list is write locked
Return values
0Success
-1No config found or Failed

Definition at line 756 of file logger.c.

757{
758 struct logchannel *chan;
759 struct ast_config *cfg;
760 struct ast_variable *var;
761 const char *s;
762 struct ast_flags config_flags = { 0 };
763
764 if (!(cfg = ast_config_load2(S_OR(altconf, "logger.conf"), "logger", config_flags)) || cfg == CONFIG_STATUS_FILEINVALID) {
765 cfg = NULL;
766 }
767
768 /* Set defaults */
769 hostname[0] = '\0';
770 display_callids = 1;
771 memset(&logfiles, 0, sizeof(logfiles));
772 logfiles.queue_log = 1;
773 ast_copy_string(dateformat, "%b %e %T", sizeof(dateformat));
775 exec_after_rotate[0] = '\0';
777
778 /* delete our list of log channels */
779 while ((chan = AST_RWLIST_REMOVE_HEAD(&logchannels, list))) {
780 ast_free(chan);
781 }
782 global_logmask = 0;
783
784 errno = 0;
785 /* close syslog */
786 closelog();
787
788 /* If no config file, we're fine, set default options. */
789 if (!cfg) {
790 chan = make_logchannel("console", "error,warning,notice,verbose", 0, 0);
791 if (!chan) {
792 fprintf(stderr, "ERROR: Failed to initialize default logging\n");
793 return -1;
794 }
795
797 global_logmask |= chan->logmask;
798
799 return -1;
800 }
801
802 if ((s = ast_variable_retrieve(cfg, "general", "appendhostname"))) {
803 if (ast_true(s)) {
804 if (gethostname(hostname, sizeof(hostname) - 1)) {
805 ast_copy_string(hostname, "unknown", sizeof(hostname));
806 fprintf(stderr, "What box has no hostname???\n");
807 }
808 }
809 }
810 if ((s = ast_variable_retrieve(cfg, "general", "display_callids"))) {
812 }
813 if ((s = ast_variable_retrieve(cfg, "general", "dateformat"))) {
815 }
816 if ((s = ast_variable_retrieve(cfg, "general", "queue_log"))) {
817 logfiles.queue_log = ast_true(s);
818 }
819 if ((s = ast_variable_retrieve(cfg, "general", "queue_log_to_file"))) {
820 logfiles.queue_log_to_file = ast_true(s);
821 }
822 if ((s = ast_variable_retrieve(cfg, "general", "queue_log_name"))) {
824 }
825 if ((s = ast_variable_retrieve(cfg, "general", "queue_log_realtime_use_gmt"))) {
826 logfiles.queue_log_realtime_use_gmt = ast_true(s);
827 }
828 if ((s = ast_variable_retrieve(cfg, "general", "exec_after_rotate"))) {
830 }
831 if ((s = ast_variable_retrieve(cfg, "general", "rotatestrategy"))) {
832 if (strcasecmp(s, "timestamp") == 0) {
834 } else if (strcasecmp(s, "rotate") == 0) {
836 } else if (strcasecmp(s, "sequential") == 0) {
838 } else if (strcasecmp(s, "none") == 0) {
840 } else {
841 fprintf(stderr, "Unknown rotatestrategy: %s\n", s);
842 }
843 }
844 if ((s = ast_variable_retrieve(cfg, "general", "logger_queue_limit"))) {
845 if (sscanf(s, "%30d", &logger_queue_limit) != 1) {
846 fprintf(stderr, "logger_queue_limit has an invalid value. Leaving at default of %d.\n",
848 }
849 if (logger_queue_limit < 10) {
850 fprintf(stderr, "logger_queue_limit must be >= 10. Setting to 10.\n");
852 }
853 }
854
855 /* Custom dynamic logging levels defined by user */
856 if ((s = ast_variable_retrieve(cfg, "general", "custom_levels"))) {
857 char *customlogs = ast_strdupa(s);
858 char *logfile;
859 char *new_custom_levels[16] = { };
860 unsigned int level, new_level = 0;
861
862 /* get the custom levels we need to register or reload */
863 while ((logfile = strsep(&customlogs, ","))) {
864 new_custom_levels[new_level++] = logfile;
865 }
866
867 /* unregister existing custom levels, if they're not still
868 specified in customlogs, to make room for new levels */
869 for (level = 16; level < ARRAY_LEN(levels); level++) {
870 if (levels[level] && custom_dynamic_levels[level] &&
871 !custom_level_still_exists(new_custom_levels, levels[level], ARRAY_LEN(new_custom_levels))) {
873 custom_dynamic_levels[level] = 0;
874 }
875 }
876
877 new_level = 0;
878 while ((logfile = new_custom_levels[new_level++])) {
879 /* Lock already held, so directly register the level,
880 unless it's already registered (as during reload) */
881 if (logger_get_dynamic_level(logfile) == -1) {
882 int custom_level = logger_register_level(logfile);
883 custom_dynamic_levels[custom_level] = logfile;
884 }
885 }
886 }
887
888 var = ast_variable_browse(cfg, "logfiles");
889 for (; var; var = var->next) {
890 chan = make_logchannel(var->name, var->value, var->lineno, 0);
891 if (!chan) {
892 /* Print error message directly to the consoles since the lock is held
893 * and we don't want to unlock with the list partially built */
894 ast_console_puts_mutable("ERROR: Unable to create log channel '", __LOG_ERROR);
897 continue;
898 }
900 global_logmask |= chan->logmask;
901 }
902
903 if (qlog) {
904 fclose(qlog);
905 qlog = NULL;
906 }
907
909
910 return 0;
911}
#define var
Definition ast_expr2f.c:605
char * strsep(char **str, const char *delims)
#define ast_strdupa(s)
duplicate a string in memory from the stack
Definition astmm.h:298
struct ast_config * ast_config_load2(const char *filename, const char *who_asked, struct ast_flags flags)
Load a config file.
#define CONFIG_STATUS_FILEINVALID
void ast_config_destroy(struct ast_config *cfg)
Destroys a config.
Definition extconf.c:1287
const char * ast_variable_retrieve(struct ast_config *config, const char *category, const char *variable)
struct ast_variable * ast_variable_browse(const struct ast_config *config, const char *category_name)
Definition extconf.c:1213
void ast_console_puts_mutable(const char *string, int level)
log the string to the console, and all attached console clients
Definition asterisk.c:1328
#define QUEUELOG
static int custom_level_still_exists(char **levels, char *level, size_t len)
Checks if level exists in array of level names.
Definition logger.c:736
static char * custom_dynamic_levels[NUMLOGLEVELS]
Custom dynamic logging levels added by the user.
Definition logger.c:228
static char exec_after_rotate[256]
Definition logger.c:81
static char queue_log_name[256]
Definition logger.c:80
static char hostname[MAXHOSTNAMELEN]
Definition logger.c:116
int errno
Structure used to handle boolean flags.
Definition utils.h:220
Structure for variables, used for configurations and for channel variables.

References __LOG_ERROR, ARRAY_LEN, ast_config_destroy(), ast_config_load2(), ast_console_puts_mutable(), ast_copy_string(), ast_free, AST_RWLIST_INSERT_HEAD, AST_RWLIST_REMOVE_HEAD, ast_strdupa, ast_true(), ast_variable_browse(), ast_variable_retrieve(), CONFIG_STATUS_FILEINVALID, custom_dynamic_levels, custom_level_still_exists(), dateformat, display_callids, errno, exec_after_rotate, global_logmask, hostname, levels, logfiles, logger_get_dynamic_level(), logger_queue_limit, logger_register_level(), logger_unregister_level(), logchannel::logmask, make_logchannel(), NONE, NULL, qlog, queue_log_name, QUEUELOG, ROTATE, S_OR, SEQUENTIAL, strsep(), TIMESTAMP, and var.

Referenced by ast_logger_rotate_channel(), init_logger(), and reload_logger().

◆ load_module()

static int load_module ( void  )
static

Definition at line 2922 of file logger.c.

2923{
2925}
@ AST_MODULE_LOAD_SUCCESS
Definition module.h:70

References AST_MODULE_LOAD_SUCCESS.

◆ log_group_write()

static int log_group_write ( struct ast_channel chan,
const char *  cmd,
char *  data,
const char *  value 
)
static

Definition at line 1771 of file logger.c.

1772{
1773 int res = callid_set_chanloggroup(value);
1774 if (res) {
1775 ast_log(LOG_ERROR, "Failed to set channel log group for %s\n", ast_channel_name(chan));
1776 return -1;
1777 }
1778 return 0;
1779}
const char * ast_channel_name(const struct ast_channel *chan)
static int callid_set_chanloggroup(const char *group)
Definition logger.c:1662
int value
Definition syslog.c:37

References ast_channel_name(), ast_log, callid_set_chanloggroup(), LOG_ERROR, and value.

◆ logger_add_verbose_magic()

static int logger_add_verbose_magic ( struct logmsg logmsg,
char *  buf,
size_t  size 
)
static

Definition at line 333 of file logger.c.

334{
335 const char *p;
336 const char *fmt;
337 struct ast_str *prefixed;
338 signed char magic = logmsg->sublevel > 9 ? -10 : -logmsg->sublevel - 1; /* 0 => -1, 1 => -2, etc. Can't pass NUL, as it is EOS-delimiter */
339
340 /* For compatibility with modules still calling ast_verbose() directly instead of using ast_verb() */
341 if (logmsg->sublevel < 0) {
342 if (!strncmp(logmsg->message, VERBOSE_PREFIX_10, strlen(VERBOSE_PREFIX_10))) {
343 magic = -11;
344 } else if (!strncmp(logmsg->message, VERBOSE_PREFIX_9, strlen(VERBOSE_PREFIX_9))) {
345 magic = -10;
346 } else if (!strncmp(logmsg->message, VERBOSE_PREFIX_8, strlen(VERBOSE_PREFIX_8))) {
347 magic = -9;
348 } else if (!strncmp(logmsg->message, VERBOSE_PREFIX_7, strlen(VERBOSE_PREFIX_7))) {
349 magic = -8;
350 } else if (!strncmp(logmsg->message, VERBOSE_PREFIX_6, strlen(VERBOSE_PREFIX_6))) {
351 magic = -7;
352 } else if (!strncmp(logmsg->message, VERBOSE_PREFIX_5, strlen(VERBOSE_PREFIX_5))) {
353 magic = -6;
354 } else if (!strncmp(logmsg->message, VERBOSE_PREFIX_4, strlen(VERBOSE_PREFIX_4))) {
355 magic = -5;
356 } else if (!strncmp(logmsg->message, VERBOSE_PREFIX_3, strlen(VERBOSE_PREFIX_3))) {
357 magic = -4;
358 } else if (!strncmp(logmsg->message, VERBOSE_PREFIX_2, strlen(VERBOSE_PREFIX_2))) {
359 magic = -3;
360 } else if (!strncmp(logmsg->message, VERBOSE_PREFIX_1, strlen(VERBOSE_PREFIX_1))) {
361 magic = -2;
362 } else {
363 magic = -1;
364 }
365 }
366
367 if (!(prefixed = ast_str_thread_get(&verbose_buf, VERBOSE_BUF_INIT_SIZE))) {
368 return -1;
369 }
370
371 ast_str_reset(prefixed);
372
373 /* for every newline found in the buffer add verbose prefix data */
374 fmt = logmsg->message;
375 do {
376 if (!(p = strchr(fmt, '\n'))) {
377 p = strchr(fmt, '\0') - 1;
378 }
379 ++p;
380
381 ast_str_append(&prefixed, 0, "%c", (char)magic);
382 ast_str_append_substr(&prefixed, 0, fmt, p - fmt);
383 fmt = p;
384 } while (p && *p);
385
386 snprintf(buf, size, "%s", ast_str_buffer(prefixed));
387
388 return 0;
389}
#define VERBOSE_PREFIX_10
#define VERBOSE_PREFIX_6
#define VERBOSE_PREFIX_2
#define VERBOSE_PREFIX_8
#define VERBOSE_PREFIX_7
#define VERBOSE_PREFIX_4
#define VERBOSE_PREFIX_5
#define VERBOSE_PREFIX_1
#define VERBOSE_PREFIX_9
#define VERBOSE_BUF_INIT_SIZE
Definition logger.c:268
char * ast_str_append_substr(struct ast_str **buf, ssize_t maxlen, const char *src, size_t maxsrc)
Append a non-NULL terminated substring to the end of a dynamic string.
Definition strings.h:1062

References ast_str_append(), ast_str_append_substr(), ast_str_buffer(), ast_str_reset(), ast_str_thread_get(), buf, logmsg::message, logmsg::sublevel, VERBOSE_BUF_INIT_SIZE, VERBOSE_PREFIX_1, VERBOSE_PREFIX_10, VERBOSE_PREFIX_2, VERBOSE_PREFIX_3, VERBOSE_PREFIX_4, VERBOSE_PREFIX_5, VERBOSE_PREFIX_6, VERBOSE_PREFIX_7, VERBOSE_PREFIX_8, and VERBOSE_PREFIX_9.

Referenced by format_log_default().

◆ logger_get_dynamic_level()

static int logger_get_dynamic_level ( const char *  name)
static

Definition at line 2832 of file logger.c.

2833{
2834 int level = -1;
2835 unsigned int x;
2836
2837 for (x = 16; x < ARRAY_LEN(levels); x++) {
2838 if (!levels[x]) {
2839 continue;
2840 }
2841 if (!strcasecmp(levels[x], name)) {
2842 level = x;
2843 break;
2844 }
2845 }
2846
2847 return level;
2848}

References ARRAY_LEN, levels, and name.

Referenced by ast_logger_get_dynamic_level(), init_logger_chain(), and logger_unregister_level().

◆ logger_print_normal()

static void logger_print_normal ( struct logmsg logmsg)
static

Print a normal log message to the channels.

Definition at line 1896 of file logger.c.

1897{
1898 struct logchannel *chan = NULL;
1899 char buf[LOGMSG_SIZE];
1900 int level = 0;
1901
1905
1906 /* If the channel is disabled, then move on to the next one */
1907 if (chan->disabled) {
1908 continue;
1909 }
1910 if (logmsg->level == __LOG_VERBOSE
1911 && (((chan->verbosity < 0) ? option_verbose : chan->verbosity)) < level) {
1912 continue;
1913 }
1914
1915 if (!(chan->logmask & (1 << logmsg->level))) {
1916 continue;
1917 }
1918
1919 switch (chan->type) {
1920 case LOGTYPE_SYSLOG:
1921 {
1922 int syslog_level = ast_syslog_priority_from_loglevel(logmsg->level);
1923
1924 if (syslog_level < 0) {
1925 /* we are locked here, so cannot ast_log() */
1926 fprintf(stderr, "ast_log_vsyslog called with bogus level: %d\n", logmsg->level);
1927 continue;
1928 }
1929
1930 /* Don't use LOG_MAKEPRI because it's broken in glibc<2.17 */
1931 syslog_level = chan->facility | syslog_level; /* LOG_MAKEPRI(chan->facility, syslog_level); */
1932 if (!chan->formatter.format_log(chan, logmsg, buf, sizeof(buf))) {
1933 syslog(syslog_level, "%s", buf);
1934 }
1935 }
1936 break;
1937 case LOGTYPE_CONSOLE:
1938 if (!logmsg->hidecli && !chan->formatter.format_log(chan, logmsg, buf, sizeof(buf))) {
1940 }
1941 break;
1942 case LOGTYPE_FILE:
1943 {
1944 int res = 0;
1945
1946 if (!chan->fileptr) {
1947 continue;
1948 }
1949
1950 if (chan->formatter.format_log(chan, logmsg, buf, sizeof(buf))) {
1951 continue;
1952 }
1953
1954 /* Print out to the file */
1955 res = fprintf(chan->fileptr, "%s", buf);
1956 if (res > 0) {
1957 fflush(chan->fileptr);
1958 } else if (res <= 0 && !ast_strlen_zero(logmsg->message)) {
1959 fprintf(stderr, "**** Asterisk Logging Error: ***********\n");
1960 if (errno == ENOMEM || errno == ENOSPC) {
1961 fprintf(stderr, "Asterisk logging error: Out of disk space, can't log to log file %s\n", chan->filename);
1962 } else {
1963 fprintf(stderr, "Logger Warning: Unable to write to log file '%s': %s (disabled)\n", chan->filename, strerror(errno));
1964 }
1965
1966 manager_event(EVENT_FLAG_SYSTEM, "LogChannel", "Channel: %s\r\nEnabled: No\r\nReason: %d - %s\r\n", chan->filename, errno, strerror(errno));
1967 chan->disabled = 1;
1968 }
1969 }
1970 break;
1971 }
1972 }
1973 } else if (logmsg->level != __LOG_VERBOSE || option_verbose >= logmsg->sublevel) {
1974 fputs(logmsg->message, stdout);
1975 }
1976
1978
1979 /* If we need to reload because of the file size, then do so */
1981 reload_logger(-1, NULL);
1982 ast_verb(1, "Rotated Logs Per SIGXFSZ (Exceeded file size limit)\n");
1983 }
1984
1985 return;
1986}
#define ast_verb(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
Definition asterisk.c:1335
#define AST_RWLIST_EMPTY
int facility
Definition logger.c:143
int(*const format_log)(struct logchannel *channel, struct logmsg *msg, char *buf, size_t size)
Definition logger.c:126
int ast_syslog_priority_from_loglevel(int level)
Maps an Asterisk log level (i.e. LOG_ERROR) to a syslog priority constant.
Definition syslog.c:162

References __LOG_VERBOSE, ast_console_puts_mutable_full(), AST_RWLIST_EMPTY, AST_RWLIST_RDLOCK, AST_RWLIST_TRAVERSE, AST_RWLIST_UNLOCK, ast_strlen_zero(), ast_syslog_priority_from_loglevel(), ast_verb, buf, logchannel::disabled, errno, EVENT_FLAG_SYSTEM, logchannel::facility, logchannel::filename, logchannel::fileptr, filesize_reload_needed, logformatter::format_log, logchannel::formatter, logmsg::hidecli, logmsg::level, logchannel::list, logchannel::logmask, LOGMSG_SIZE, LOGTYPE_CONSOLE, LOGTYPE_FILE, LOGTYPE_SYSLOG, manager_event, logmsg::message, NULL, option_verbose, reload_logger(), logmsg::sublevel, logchannel::type, and logchannel::verbosity.

Referenced by ast_log_full(), and logger_thread().

◆ logger_queue_init()

static void logger_queue_init ( void  )
static

Definition at line 2121 of file logger.c.

2122{
2123 ast_unload_realtime("queue_log");
2124 if (logfiles.queue_log) {
2125 char qfname[PATH_MAX];
2126
2127 if (logger_queue_rt_start()) {
2128 return;
2129 }
2130
2131 /* Open the log file. */
2132 snprintf(qfname, sizeof(qfname), "%s/%s", ast_config_AST_LOG_DIR,
2134 if (qlog) {
2135 /* Just in case it was already open. */
2136 fclose(qlog);
2137 }
2138 qlog = fopen(qfname, "a");
2139 if (!qlog) {
2140 ast_log(LOG_ERROR, "Unable to create queue log: %s\n", strerror(errno));
2141 }
2142 }
2143}
int ast_unload_realtime(const char *family)
Release any resources cached for a realtime family.
static int logger_queue_rt_start(void)
Definition logger.c:1141

References ast_config_AST_LOG_DIR, ast_log, ast_unload_realtime(), errno, LOG_ERROR, logfiles, logger_queue_rt_start(), PATH_MAX, qlog, and queue_log_name.

Referenced by logger_queue_start().

◆ logger_queue_restart()

static int logger_queue_restart ( int  queue_rotate)
static

Definition at line 1176 of file logger.c.

1177{
1178 int res = 0;
1179 char qfname[PATH_MAX];
1180
1181 if (logger_queue_rt_start()) {
1182 return res;
1183 }
1184
1185 snprintf(qfname, sizeof(qfname), "%s/%s", ast_config_AST_LOG_DIR, queue_log_name);
1186 if (qlog) {
1187 /* Just in case it was still open. */
1188 fclose(qlog);
1189 qlog = NULL;
1190 }
1191 if (queue_rotate) {
1192 rotate_file(qfname);
1193 }
1194
1195 /* Open the log file. */
1196 qlog = fopen(qfname, "a");
1197 if (!qlog) {
1198 ast_log(LOG_ERROR, "Unable to create queue log: %s\n", strerror(errno));
1199 res = -1;
1200 }
1201 return res;
1202}

References ast_config_AST_LOG_DIR, ast_log, errno, LOG_ERROR, logger_queue_rt_start(), NULL, PATH_MAX, qlog, queue_log_name, and rotate_file().

Referenced by reload_logger().

◆ logger_queue_rt_start()

static int logger_queue_rt_start ( void  )
static

Definition at line 1141 of file logger.c.

1142{
1143 if (ast_check_realtime("queue_log")) {
1144 if (!ast_realtime_require_field("queue_log",
1145 "time", RQ_DATETIME, 26,
1146 "data1", RQ_CHAR, 20,
1147 "data2", RQ_CHAR, 20,
1148 "data3", RQ_CHAR, 20,
1149 "data4", RQ_CHAR, 20,
1150 "data5", RQ_CHAR, 20,
1151 SENTINEL)) {
1152 logfiles.queue_adaptive_realtime = 1;
1153 } else {
1154 logfiles.queue_adaptive_realtime = 0;
1155 }
1156
1157 if (!logfiles.queue_log_to_file) {
1158 /* Don't open the log file. */
1159 return 1;
1160 }
1161 }
1162 return 0;
1163}

References ast_check_realtime(), ast_realtime_require_field(), logfiles, RQ_CHAR, RQ_DATETIME, and SENTINEL.

Referenced by logger_queue_init(), and logger_queue_restart().

◆ logger_queue_start()

void logger_queue_start ( void  )

Start the ast_queue_log() logger.

Note
Called when the system is fully booted after startup so preloaded realtime modules can get up.

Definition at line 2156 of file logger.c.

2157{
2158 /* Must not be called before the logger is initialized. */
2160
2162 if (!queuelog_init) {
2164 queuelog_init = 1;
2166 ast_queue_log("NONE", "NONE", "NONE", "QUEUESTART", "%s", "");
2167 } else {
2169 }
2170}
void ast_queue_log(const char *queuename, const char *callid, const char *agent, const char *event, const char *fmt,...)
Definition logger.c:957
static void logger_queue_init(void)
Definition logger.c:2121

References ast_assert, ast_queue_log(), AST_RWLIST_UNLOCK, AST_RWLIST_WRLOCK, logger_initialized, logger_queue_init(), and queuelog_init.

Referenced by ast_queue_log(), and asterisk_daemon().

◆ logger_register_level()

static int logger_register_level ( const char *  name)
static

Definition at line 2784 of file logger.c.

2785{
2786 unsigned int level;
2787 unsigned int available = 0;
2788
2789 for (level = 0; level < ARRAY_LEN(levels); level++) {
2790 if ((level >= 16) && !available && !levels[level]) {
2791 available = level;
2792 continue;
2793 }
2794
2795 if (levels[level] && !strcasecmp(levels[level], name)) {
2797 "Unable to register dynamic logger level '%s': a standard logger level uses that name.\n",
2798 name);
2799
2800 return -1;
2801 }
2802 }
2803
2804 if (!available) {
2806 "Unable to register dynamic logger level '%s'; maximum number of levels registered.\n",
2807 name);
2808
2809 return -1;
2810 }
2811
2813
2814 ast_debug(1, "Registered dynamic logger level '%s' with index %u.\n", name, available);
2815
2817
2818 return available;
2819}

References ARRAY_LEN, ast_debug, ast_log, ast_strdup, available(), levels, LOG_WARNING, name, and update_logchannels().

Referenced by ast_logger_register_level(), and init_logger_chain().

◆ logger_thread()

static void * logger_thread ( void *  data)
static

Actual logging thread.

Definition at line 2067 of file logger.c.

2068{
2069 struct logmsg *next = NULL, *msg = NULL;
2070
2071 for (;;) {
2072 /* We lock the message list, and see if any message exists... if not we wait on the condition to be signalled */
2074 if (AST_LIST_EMPTY(&logmsgs)) {
2075 if (close_logger_thread) {
2077 break;
2078 } else {
2080 }
2081 }
2082
2083 if (high_water_alert) {
2084 msg = format_log_message(__LOG_WARNING, 0, "logger", 0, "***", 0,
2085 "Logging resumed. %d message%s discarded.\n",
2087 if (msg) {
2089 }
2090 high_water_alert = 0;
2092 }
2093
2098
2099 /* Otherwise go through and process each message in the order added */
2100 while ((msg = next)) {
2101 /* Get the next entry now so that we can free our current structure later */
2102 next = AST_LIST_NEXT(msg, list);
2103
2104 /* Depending on the type, send it to the proper function */
2106
2107 /* Free the data since we are done */
2108 logmsg_free(msg);
2109 }
2110 }
2111
2112 return NULL;
2113}
#define AST_LIST_HEAD_INIT_NOLOCK(head)
Initializes a list head structure.
#define AST_LIST_FIRST(head)
Returns the first entry contained in a list.
#define AST_LIST_NEXT(elm, field)
Returns the next entry in the list after the given entry.
#define ast_cond_wait(cond, mutex)
Definition lock.h:212
struct logmsg * next
Definition logger.c:184

References __LOG_WARNING, ast_cond_wait, AST_LIST_EMPTY, AST_LIST_FIRST, AST_LIST_HEAD_INIT_NOLOCK, AST_LIST_INSERT_TAIL, AST_LIST_LOCK, AST_LIST_NEXT, AST_LIST_UNLOCK, close_logger_thread, format_log_message(), high_water_alert, logmsg::list, logmsgs::lock, logcond, logger_messages_discarded, logger_print_normal(), logger_queue_size, logmsg_free(), logmsg::next, and NULL.

Referenced by init_logger().

◆ logger_unregister_level()

static int logger_unregister_level ( const char *  name)
static

Definition at line 2863 of file logger.c.

2863 {
2864 unsigned int x;
2865
2867 if (x == -1) {
2868 return 0;
2869 }
2870 /* take this level out of the global_logmask, to ensure that no new log messages
2871 * will be queued for it
2872 */
2873 global_logmask &= ~(1 << x);
2874 ast_free(levels[x]);
2875 levels[x] = NULL;
2876 return x;
2877}

References ast_free, global_logmask, levels, logger_get_dynamic_level(), name, and NULL.

Referenced by ast_logger_unregister_level(), and init_logger_chain().

◆ logmsg_free()

static void logmsg_free ( struct logmsg msg)
static

Definition at line 187 of file logger.c.

188{
190 ast_free(msg);
191}
#define ast_string_field_free_memory(x)
free all memory - to be called before destroying the object

References ast_free, and ast_string_field_free_memory.

Referenced by ast_log_full(), and logger_thread().

◆ make_components()

static void make_components ( struct logchannel chan)
static

Definition at line 505 of file logger.c.

506{
507 char *w;
508 unsigned int logmask = 0;
509 char *stringp = ast_strdupa(chan->components);
510 unsigned int x;
511 unsigned int verb_level;
512
513 /* Default to using option_verbose as the verbosity level of the logging channel. */
514 verb_level = -1;
515
516 w = strchr(stringp, '[');
517 if (w) {
518 char *end = strchr(w + 1, ']');
519 if (!end) {
520 fprintf(stderr, "Logger Warning: bad formatter definition for %s in logger.conf\n", chan->filename);
521 } else {
522 char *formatter_name = w + 1;
523
524 *end = '\0';
525 stringp = end + 1;
526
527 if (!strcasecmp(formatter_name, "json")) {
528 memcpy(&chan->formatter, &logformatter_json, sizeof(chan->formatter));
529 } else if (!strcasecmp(formatter_name, "default")) {
530 memcpy(&chan->formatter, &logformatter_default, sizeof(chan->formatter));
531 } else if (!strcasecmp(formatter_name, "plain")) {
532 memcpy(&chan->formatter, &logformatter_plain, sizeof(chan->formatter));
533 } else {
534 fprintf(stderr, "Logger Warning: Unknown formatter definition %s for %s in logger.conf; using 'default'\n",
535 formatter_name, chan->filename);
536 memcpy(&chan->formatter, &logformatter_default, sizeof(chan->formatter));
537 }
538 }
539 }
540
541 if (!chan->formatter.name) {
542 memcpy(&chan->formatter, &logformatter_default, sizeof(chan->formatter));
543 }
544
545 while ((w = strsep(&stringp, ","))) {
546 w = ast_strip(w);
547 if (ast_strlen_zero(w)) {
548 continue;
549 }
550 if (!strcmp(w, "*")) {
551 logmask = 0xFFFFFFFF;
552 } else if (!strncasecmp(w, "verbose(", 8)) {
553 if (levels[__LOG_VERBOSE] && sscanf(w + 8, "%30u)", &verb_level) == 1) {
554 logmask |= (1 << __LOG_VERBOSE);
555 }
556 } else {
557 for (x = 0; x < ARRAY_LEN(levels); ++x) {
558 if (levels[x] && !strcasecmp(w, levels[x])) {
559 logmask |= (1 << x);
560 break;
561 }
562 }
563 }
564 }
565 if (chan->type == LOGTYPE_CONSOLE) {
566 /*
567 * Force to use the root console verbose level so if the
568 * user specified any verbose level then it does not interfere
569 * with calculating the ast_verb_sys_level value.
570 */
571 chan->verbosity = -1;
572 logmask |= (1 << __LOG_VERBOSE);
573 } else {
574 chan->verbosity = verb_level;
575 }
576 chan->logmask = logmask;
577}
char * end
Definition eagi_proxy.c:73
static struct logformatter logformatter_json
Definition logger.c:328
static struct logformatter logformatter_default
Definition logger.c:450
static struct logformatter logformatter_plain
Definition logger.c:500
char * ast_strip(char *s)
Strip leading/trailing whitespace from a string.
Definition strings.h:223
const char * name
Definition logger.c:124

References __LOG_VERBOSE, ARRAY_LEN, ast_strdupa, ast_strip(), ast_strlen_zero(), logchannel::components, end, logchannel::filename, logchannel::formatter, levels, logformatter_default, logformatter_json, logformatter_plain, logchannel::logmask, LOGTYPE_CONSOLE, logformatter::name, strsep(), logchannel::type, and logchannel::verbosity.

Referenced by make_logchannel(), and update_logchannels().

◆ make_filename()

static void make_filename ( const char *  channel,
char *  filename,
size_t  size 
)
static

create the filename that will be used for a logger channel.

Parameters
channelThe name of the logger channel
[out]filenameThe filename for the logger channel
sizeThe size of the filename buffer

Definition at line 586 of file logger.c.

587{
588 const char *log_dir_prefix = "";
589 const char *log_dir_separator = "";
590
591 *filename = '\0';
592
593 if (!strcasecmp(channel, "console")) {
594 return;
595 }
596
597 if (!strncasecmp(channel, "syslog", 6)) {
598 ast_copy_string(filename, channel, size);
599 return;
600 }
601
602 /* It's a filename */
603
604 if (channel[0] != '/') {
605 log_dir_prefix = ast_config_AST_LOG_DIR;
606 log_dir_separator = "/";
607 }
608
610 snprintf(filename, size, "%s%s%s.%s",
611 log_dir_prefix, log_dir_separator, channel, hostname);
612 } else {
613 snprintf(filename, size, "%s%s%s",
614 log_dir_prefix, log_dir_separator, channel);
615 }
616}

References ast_config_AST_LOG_DIR, ast_copy_string(), ast_strlen_zero(), and hostname.

Referenced by ast_logger_rotate_channel(), find_logchannel(), and make_logchannel().

◆ make_logchannel()

static struct logchannel * make_logchannel ( const char *  channel,
const char *  components,
int  lineno,
int  dynamic 
)
static

Definition at line 643 of file logger.c.

644{
645 struct logchannel *chan;
646 char *facility;
647 struct ast_tm tm;
648 struct timeval now = ast_tvnow();
649 char datestring[256];
650
651 if (ast_strlen_zero(channel) || !(chan = ast_calloc(1, sizeof(*chan) + strlen(components) + 1)))
652 return NULL;
653
654 strcpy(chan->components, components);
655 chan->lineno = lineno;
656 chan->dynamic = dynamic;
657
658 make_filename(channel, chan->filename, sizeof(chan->filename));
659
660 if (!strcasecmp(channel, "console")) {
661 chan->type = LOGTYPE_CONSOLE;
662 } else if (!strncasecmp(channel, "syslog", 6)) {
663 /*
664 * syntax is:
665 * syslog.facility => level,level,level
666 */
667 facility = strchr(channel, '.');
668 if (!facility++ || !facility) {
669 facility = "local0";
670 }
671
672 chan->facility = ast_syslog_facility(facility);
673
674 if (chan->facility < 0) {
675 fprintf(stderr, "Logger Warning: bad syslog facility in logger.conf\n");
676 ast_free(chan);
677 return NULL;
678 }
679
680 chan->type = LOGTYPE_SYSLOG;
681 openlog("asterisk", LOG_PID, chan->facility);
682 } else {
683 if (!(chan->fileptr = fopen(chan->filename, "a"))) {
684 /* Can't do real logging here since we're called with a lock
685 * so log to any attached consoles */
686 ast_console_puts_mutable("ERROR: Unable to open log file '", __LOG_ERROR);
691 ast_free(chan);
692 return NULL;
693 } else {
694 /* Create our date/time */
695 ast_localtime(&now, &tm, NULL);
696 ast_strftime(datestring, sizeof(datestring), dateformat, &tm);
697
698 fprintf(chan->fileptr, "[%s] Asterisk %s built by %s @ %s on a %s running %s on %s\n",
701 fflush(chan->fileptr);
702 }
703 chan->type = LOGTYPE_FILE;
704 }
705 make_components(chan);
706
707 return chan;
708}
const char * ast_get_version(void)
Retrieve the Asterisk version string.
const char * ast_build_os
Definition buildinfo.c:32
const char * ast_build_machine
Definition buildinfo.c:31
const char * ast_build_hostname
Definition buildinfo.c:29
const char * ast_build_user
Definition buildinfo.c:34
const char * ast_build_date
Definition buildinfo.c:33
static void make_components(struct logchannel *chan)
Definition logger.c:505
int lineno
Definition logger.c:155
int ast_syslog_facility(const char *facility)
Maps a syslog facility name from a string to a syslog facility constant.
Definition syslog.c:85

References __LOG_ERROR, ast_build_date, ast_build_hostname, ast_build_machine, ast_build_os, ast_build_user, ast_calloc, ast_console_puts_mutable(), ast_free, ast_get_version(), ast_localtime(), ast_strftime(), ast_strlen_zero(), ast_syslog_facility(), ast_tvnow(), logchannel::components, dateformat, logchannel::dynamic, errno, logchannel::facility, logchannel::filename, logchannel::fileptr, logchannel::lineno, LOGTYPE_CONSOLE, LOGTYPE_FILE, LOGTYPE_SYSLOG, make_components(), make_filename(), NULL, and logchannel::type.

Referenced by ast_logger_create_channel(), and init_logger_chain().

◆ reload_logger()

static int reload_logger ( int  rotate,
const char *  altconf 
)
static

Definition at line 1204 of file logger.c.

1205{
1206 int queue_rotate = rotate;
1207 struct logchannel *f;
1208 int res = 0;
1209
1211
1212 if (qlog) {
1213 if (rotate < 0) {
1214 /* Check filesize - this one typically doesn't need an auto-rotate */
1215 if (ftello(qlog) > 0x40000000) { /* Arbitrarily, 1 GB */
1216 fclose(qlog);
1217 qlog = NULL;
1218 } else {
1219 queue_rotate = 0;
1220 }
1221 } else {
1222 fclose(qlog);
1223 qlog = NULL;
1224 }
1225 } else {
1226 queue_rotate = 0;
1227 }
1228
1230
1232 if (f->disabled) {
1233 f->disabled = 0; /* Re-enable logging at reload */
1234 manager_event(EVENT_FLAG_SYSTEM, "LogChannel", "Channel: %s\r\nEnabled: Yes\r\n", f->filename);
1235 }
1236 if (f->fileptr && (f->fileptr != stdout) && (f->fileptr != stderr)) {
1237 int rotate_this = 0;
1238 if (rotatestrategy != NONE && ftello(f->fileptr) > 0x40000000) { /* Arbitrarily, 1 GB */
1239 /* Be more proactive about rotating massive log files */
1240 rotate_this = 1;
1241 }
1242 fclose(f->fileptr); /* Close file */
1243 f->fileptr = NULL;
1244 if (rotate || rotate_this) {
1246 }
1247 }
1248 }
1249
1251
1252 init_logger_chain(altconf);
1253
1254 ast_unload_realtime("queue_log");
1255 if (logfiles.queue_log) {
1256 res = logger_queue_restart(queue_rotate);
1259 ast_queue_log("NONE", "NONE", "NONE", "CONFIGRELOAD", "%s", "");
1260 ast_verb(1, "Asterisk Queue Logger restarted\n");
1261 } else {
1264 }
1265
1266 return res;
1267}
static int logger_queue_restart(int queue_rotate)
Definition logger.c:1176

References ast_config_AST_LOG_DIR, ast_mkdir(), ast_queue_log(), AST_RWLIST_TRAVERSE, AST_RWLIST_UNLOCK, AST_RWLIST_WRLOCK, ast_unload_realtime(), ast_verb, ast_verb_update(), logchannel::disabled, EVENT_FLAG_SYSTEM, logchannel::filename, logchannel::fileptr, filesize_reload_needed, init_logger_chain(), logchannel::list, logfiles, logger_queue_restart(), manager_event, NONE, NULL, qlog, and rotate_file().

Referenced by ast_logger_rotate(), handle_logger_reload(), handle_logger_rotate(), logger_print_normal(), and reload_module().

◆ reload_module()

static int reload_module ( void  )
static

Definition at line 2912 of file logger.c.

2913{
2914 return reload_logger(0, NULL);
2915}

References NULL, and reload_logger().

◆ rotate_file()

static int rotate_file ( const char *  filename)
static

Definition at line 1037 of file logger.c.

1038{
1039 char old[PATH_MAX];
1040 char new[PATH_MAX];
1041 int x, y, which, found, res = 0, fd;
1042 char *suffixes[4] = { "", ".gz", ".bz2", ".Z" };
1043
1044 switch (rotatestrategy) {
1045 case NONE:
1046 /* No rotation */
1047 break;
1048 case SEQUENTIAL:
1049 for (x = 0; ; x++) {
1050 snprintf(new, sizeof(new), "%s.%d", filename, x);
1051 fd = open(new, O_RDONLY);
1052 if (fd > -1)
1053 close(fd);
1054 else
1055 break;
1056 }
1057 if (rename(filename, new)) {
1058 fprintf(stderr, "Unable to rename file '%s' to '%s'\n", filename, new);
1059 res = -1;
1060 } else {
1061 filename = new;
1062 }
1063 break;
1064 case TIMESTAMP:
1065 snprintf(new, sizeof(new), "%s.%ld", filename, (long)time(NULL));
1066 if (rename(filename, new)) {
1067 fprintf(stderr, "Unable to rename file '%s' to '%s'\n", filename, new);
1068 res = -1;
1069 } else {
1070 filename = new;
1071 }
1072 break;
1073 case ROTATE:
1074 /* Find the next empty slot, including a possible suffix */
1075 for (x = 0; ; x++) {
1076 found = 0;
1077 for (which = 0; which < ARRAY_LEN(suffixes); which++) {
1078 snprintf(new, sizeof(new), "%s.%d%s", filename, x, suffixes[which]);
1079 fd = open(new, O_RDONLY);
1080 if (fd > -1) {
1081 close(fd);
1082 found = 1;
1083 break;
1084 }
1085 }
1086 if (!found) {
1087 break;
1088 }
1089 }
1090
1091 /* Found an empty slot */
1092 for (y = x; y > 0; y--) {
1093 for (which = 0; which < ARRAY_LEN(suffixes); which++) {
1094 snprintf(old, sizeof(old), "%s.%d%s", filename, y - 1, suffixes[which]);
1095 fd = open(old, O_RDONLY);
1096 if (fd > -1) {
1097 /* Found the right suffix */
1098 close(fd);
1099 snprintf(new, sizeof(new), "%s.%d%s", filename, y, suffixes[which]);
1100 if (rename(old, new)) {
1101 fprintf(stderr, "Unable to rename file '%s' to '%s'\n", old, new);
1102 res = -1;
1103 }
1104 break;
1105 }
1106 }
1107 }
1108
1109 /* Finally, rename the current file */
1110 snprintf(new, sizeof(new), "%s.0", filename);
1111 if (rename(filename, new)) {
1112 fprintf(stderr, "Unable to rename file '%s' to '%s'\n", filename, new);
1113 res = -1;
1114 } else {
1115 filename = new;
1116 }
1117 }
1118
1121 char buf[512];
1122
1123 pbx_builtin_setvar_helper(c, "filename", filename);
1125 if (c) {
1127 }
1128 if (ast_safe_system(buf) == -1) {
1129 ast_log(LOG_WARNING, "error executing '%s'\n", buf);
1130 }
1131 }
1132 return res;
1133}
#define ast_channel_unref(c)
Decrease channel reference count.
Definition channel.h:3018
#define ast_dummy_channel_alloc()
Create a fake channel structure.
Definition channel.h:1328
int ast_safe_system(const char *s)
Safely spawn an OS shell command while closing file descriptors.
Definition extconf.c:827
int pbx_builtin_setvar_helper(struct ast_channel *chan, const char *name, const char *value)
Add a variable to the channel variable stack, removing the most recently set value for the same name.
void pbx_substitute_variables_helper(struct ast_channel *c, const char *cp1, char *cp2, int count)
Definition ael_main.c:211
Main Channel structure associated with a channel.
static struct test_val c

References ARRAY_LEN, ast_channel_unref, ast_dummy_channel_alloc, ast_log, ast_safe_system(), ast_strlen_zero(), buf, c, exec_after_rotate, LOG_WARNING, NONE, NULL, PATH_MAX, pbx_builtin_setvar_helper(), pbx_substitute_variables_helper(), ROTATE, SEQUENTIAL, and TIMESTAMP.

Referenced by ast_logger_rotate_channel(), logger_queue_restart(), and reload_logger().

◆ unload_module()

static int unload_module ( void  )
static

Definition at line 2917 of file logger.c.

2918{
2919 return 0;
2920}

◆ update_logchannels()

static void update_logchannels ( void  )
static

Definition at line 2680 of file logger.c.

2681{
2682 struct logchannel *cur;
2683
2684 global_logmask = 0;
2685
2687 make_components(cur);
2688 global_logmask |= cur->logmask;
2689 }
2690}

References AST_RWLIST_TRAVERSE, global_logmask, logchannel::list, logchannel::logmask, and make_components().

Referenced by ast_logger_unregister_level(), and logger_register_level().

◆ verb_console_free()

static void verb_console_free ( void *  v_console)
static

Definition at line 2605 of file logger.c.

2606{
2607 struct verb_console *console = v_console;
2608
2611}

References ast_free, and verb_console_unregister().

◆ verb_console_unregister()

static void verb_console_unregister ( struct verb_console console)
static

Variable Documentation

◆ __mod_info

struct ast_module_info __mod_info = { .name = AST_MODULE, .flags = AST_MODFLAG_GLOBAL_SYMBOLS | AST_MODFLAG_LOAD_ORDER , .description = "Logger" , .key = ASTERISK_GPL_KEY , .buildopt_sum = AST_BUILDOPT_SUM, .support_level = AST_MODULE_SUPPORT_CORE, .load = load_module, .unload = unload_module, .reload = reload_module, .load_pri = 0, }
static

Definition at line 2935 of file logger.c.

◆ ast_module_info

const struct ast_module_info* ast_module_info = &__mod_info
static

Definition at line 2935 of file logger.c.

◆ callid_filtering

int callid_filtering = 0
static

◆ chan_group_lock_list

◆ cli_logger

struct ast_cli_entry cli_logger[]
static

Definition at line 1871 of file logger.c.

1871 {
1872 AST_CLI_DEFINE(handle_logger_show_channels, "List configured log channels"),
1873 AST_CLI_DEFINE(handle_logger_show_levels, "List configured log levels"),
1874 AST_CLI_DEFINE(handle_logger_reload, "Reopens the log files"),
1875 AST_CLI_DEFINE(handle_logger_rotate, "Rotates and reopens the log files"),
1876 AST_CLI_DEFINE(handle_logger_set_level, "Enables/Disables a specific logging level for this console"),
1877 AST_CLI_DEFINE(handle_logger_add_channel, "Adds a new logging channel"),
1878 AST_CLI_DEFINE(handle_logger_remove_channel, "Removes a logging channel"),
1879 AST_CLI_DEFINE(handle_logger_chanloggroup_filter, "Filter PBX logs by channel log group"),
1880 AST_CLI_DEFINE(handle_logger_filter_show, "Show current PBX channel filtering"),
1881 AST_CLI_DEFINE(handle_logger_filter_reset, "Reset PBX channel filtering"),
1882};
#define AST_CLI_DEFINE(fn, txt,...)
Definition cli.h:197
static char * handle_logger_remove_channel(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
Definition logger.c:1592
static char * handle_logger_show_channels(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
CLI command to show logging system configuration.
Definition logger.c:1432
static char * handle_logger_show_levels(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
CLI command to show logging levels.
Definition logger.c:1473
static char * handle_logger_chanloggroup_filter(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
Definition logger.c:1786
static char * handle_logger_filter_show(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
Definition logger.c:1818
static char * handle_logger_filter_reset(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
Definition logger.c:1848
static char * handle_logger_set_level(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
Definition logger.c:1347
static char * handle_logger_add_channel(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
Definition logger.c:1531
static char * handle_logger_reload(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
Definition logger.c:1269
static char * handle_logger_rotate(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
Definition logger.c:1288

Referenced by close_logger(), and init_logger().

◆ close_logger_thread

int close_logger_thread = 0
static

Definition at line 196 of file logger.c.

Referenced by ast_log_full(), close_logger(), and logger_thread().

◆ colors

const int colors[NUMLOGLEVELS]
static

Colors used in the console for logging.

Definition at line 231 of file logger.c.

231 {
233 COLOR_BRBLUE, /* no longer used */
236 COLOR_RED,
239 0,
240 0,
241 0,
242 0,
243 0,
244 0,
245 0,
246 0,
247 0,
264};
#define COLOR_BRGREEN
Definition term.h:55
#define COLOR_BRRED
Definition term.h:53
#define COLOR_YELLOW
Definition term.h:57
#define COLOR_RED
Definition term.h:52
#define COLOR_GREEN
Definition term.h:54
#define COLOR_BRBLUE
Definition term.h:59

Referenced by format_log_default().

◆ custom_dynamic_levels

char* custom_dynamic_levels[NUMLOGLEVELS]
static

Custom dynamic logging levels added by the user.

The first 16 levels are reserved for system usage, and the remaining levels are reserved for usage by dynamic levels registered via ast_logger_register_level.

Definition at line 228 of file logger.c.

Referenced by init_logger_chain().

◆ dateformat

char dateformat[256] = "%b %e %T"
static

◆ display_callids

int display_callids
static

Definition at line 88 of file logger.c.

Referenced by format_log_message_ap(), and init_logger_chain().

◆ exec_after_rotate

char exec_after_rotate[256] = ""
static

Definition at line 81 of file logger.c.

Referenced by init_logger_chain(), and rotate_file().

◆ filesize_reload_needed

int filesize_reload_needed
static

Definition at line 83 of file logger.c.

Referenced by _handle_SIGXFSZ(), logger_print_normal(), and reload_logger().

◆ global_logmask

unsigned int global_logmask = 0xFFFF
static

◆ handle_SIGXFSZ

struct sigaction handle_SIGXFSZ
static
Initial value:
= {
.sa_handler = _handle_SIGXFSZ,
.sa_flags = SA_RESTART,
}
static void _handle_SIGXFSZ(int sig)
Definition logger.c:1884

Definition at line 1890 of file logger.c.

1890 {
1891 .sa_handler = _handle_SIGXFSZ,
1892 .sa_flags = SA_RESTART,
1893};

Referenced by init_logger().

◆ high_water_alert

unsigned int high_water_alert
static

Definition at line 95 of file logger.c.

Referenced by ast_log_full(), and logger_thread().

◆ hostname

char hostname[MAXHOSTNAMELEN]
static

◆ levels

char* levels[NUMLOGLEVELS]
static

Logging channels used in the Asterisk logging system.

The first 16 levels are reserved for system usage, and the remaining levels are reserved for usage by dynamic levels registered via ast_logger_register_level.

Examples
app_skel.c.

Definition at line 211 of file logger.c.

211 {
212 "DEBUG",
213 "TRACE",
214 "NOTICE",
215 "WARNING",
216 "ERROR",
217 "VERBOSE",
218 "DTMF",
219};

Referenced by ast_logger_get_channels(), ast_network_puts_mutable(), custom_level_still_exists(), format_log_default(), format_log_message_ap(), format_log_plain(), handle_logger_set_level(), handle_logger_show_channels(), handle_logger_show_levels(), init_logger_chain(), logger_get_dynamic_level(), logger_register_level(), logger_unregister_level(), and make_components().

◆ log_group_function

struct ast_custom_function log_group_function
static
Initial value:
= {
.name = "LOG_GROUP",
.write = log_group_write,
}
static int log_group_write(struct ast_channel *chan, const char *cmd, char *data, const char *value)
Definition logger.c:1771

Definition at line 1781 of file logger.c.

1781 {
1782 .name = "LOG_GROUP",
1783 .write = log_group_write,
1784};

Referenced by close_logger(), and init_logger().

◆ logchannels

◆ logcond

ast_cond_t logcond
static

Definition at line 195 of file logger.c.

Referenced by ast_log_full(), close_logger(), init_logger(), and logger_thread().

◆ [struct]

struct { ... } logfiles

◆ logformatter_default

struct logformatter logformatter_default
static
Initial value:
= {
.name = "default",
.format_log = format_log_default,
}
static int format_log_default(struct logchannel *chan, struct logmsg *msg, char *buf, size_t size)
Definition logger.c:391

Definition at line 450 of file logger.c.

450 {
451 .name = "default",
452 .format_log = format_log_default,
453};

Referenced by make_components().

◆ logformatter_json

struct logformatter logformatter_json
static
Initial value:
= {
.name = "json",
.format_log = format_log_json
}
static int format_log_json(struct logchannel *channel, struct logmsg *msg, char *buf, size_t size)
Definition logger.c:273

Definition at line 328 of file logger.c.

328 {
329 .name = "json",
330 .format_log = format_log_json
331};

Referenced by make_components().

◆ logformatter_plain

struct logformatter logformatter_plain
static
Initial value:
= {
.name = "plain",
.format_log = format_log_plain,
}
static int format_log_plain(struct logchannel *chan, struct logmsg *msg, char *buf, size_t size)
Definition logger.c:455

Definition at line 500 of file logger.c.

500 {
501 .name = "plain",
502 .format_log = format_log_plain,
503};

Referenced by make_components().

◆ logger_initialized

int logger_initialized
static

◆ logger_messages_discarded

int logger_messages_discarded
static

Definition at line 94 of file logger.c.

Referenced by ast_log_full(), and logger_thread().

◆ logger_queue_limit

int logger_queue_limit = 1000
static

◆ logger_queue_size

int logger_queue_size
static

Definition at line 92 of file logger.c.

Referenced by ast_log_full(), and logger_thread().

◆ logmsgs

◆ logthread

pthread_t logthread = AST_PTHREADT_NULL
static

Definition at line 194 of file logger.c.

Referenced by ast_log_full(), close_logger(), and init_logger().

◆ next_unique_callid

volatile int next_unique_callid = 1
static

Definition at line 87 of file logger.c.

Referenced by ast_create_callid().

◆ qlog

FILE* qlog
static

◆ queue_adaptive_realtime

unsigned int queue_adaptive_realtime

Definition at line 112 of file logger.c.

◆ queue_log

unsigned int queue_log

Definition at line 110 of file logger.c.

◆ queue_log_name

char queue_log_name[256] = QUEUELOG
static

Definition at line 80 of file logger.c.

Referenced by init_logger_chain(), logger_queue_init(), and logger_queue_restart().

◆ queue_log_realtime_use_gmt

unsigned int queue_log_realtime_use_gmt

Definition at line 113 of file logger.c.

◆ queue_log_to_file

unsigned int queue_log_to_file

Definition at line 111 of file logger.c.

◆ queuelog_init

int queuelog_init
static

Definition at line 85 of file logger.c.

Referenced by ast_queue_log(), and logger_queue_start().

◆ rotatestrategy

◆ verb_consoles

◆ verb_update_lock

ast_mutex_t verb_update_lock = AST_MUTEX_INIT_VALUE
static

ast_verb_update() reentrancy protection lock.

Definition at line 2552 of file logger.c.

Referenced by ast_verb_update().