Asterisk - The Open Source Telephony Project GIT-master-8f1982c
All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Macros Modules Pages
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) More...
 
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. More...
 
static void __init_callid_group_name (void)
 
static void __init_log_buf (void)
 
static void __init_my_verb_console (void)
 
static void __init_unique_callid (void)
 
static void __init_verbose_buf (void)
 
static void __init_verbose_build_buf (void)
 
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 More...
 
int ast_callid_threadassoc_add (ast_callid callid)
 Adds a known callid to thread storage of the calling thread. More...
 
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. More...
 
int ast_callid_threadassoc_remove (void)
 Removes callid from thread storage of the calling thread. More...
 
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. More...
 
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. More...
 
void ast_child_verbose (int level, const char *fmt,...)
 
ast_callid ast_create_callid (void)
 factory function to create a new uniquely identifying callid. More...
 
void ast_init_logger_for_socket_console (void)
 load logger.conf configuration for console socket connections More...
 
int ast_is_logger_initialized (void)
 Test if logger is initialized. More...
 
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. More...
 
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. More...
 
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. More...
 
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 More...
 
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. More...
 
int ast_logger_create_channel (const char *log_channel, const char *components)
 Create a log channel. More...
 
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. More...
 
const char * ast_logger_get_dateformat (void)
 Get the logger configured date format. More...
 
int ast_logger_get_dynamic_level (const char *name)
 Retrieve dynamic logging level id. More...
 
int ast_logger_get_queue_limit (void)
 Get the maximum number of messages allowed in the processing queue. More...
 
int ast_logger_register_level (const char *name)
 Register a new logger level. More...
 
int ast_logger_remove_channel (const char *log_channel)
 Delete the specified log channel. More...
 
int ast_logger_rotate ()
 Reload logger while rotating log files. More...
 
int ast_logger_rotate_channel (const char *log_channel)
 Rotate the specified log channel. More...
 
void ast_logger_set_queue_limit (int queue_limit)
 Set the maximum number of messages allowed in the processing queue. More...
 
void ast_logger_unregister_level (const char *name)
 Unregister a previously registered logger level. More...
 
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 callerid from the thread More...
 
 AST_THREADSTORAGE_RAW (in_safe_log)
 
int ast_verb_console_get (void)
 Get this thread's console verbosity level. More...
 
void ast_verb_console_register (int *level)
 Register this thread's console verbosity level pointer. More...
 
void ast_verb_console_set (int verb_level)
 Set this thread's console verbosity level. More...
 
void ast_verb_console_unregister (void)
 Unregister this thread's console verbosity level. More...
 
void ast_verb_update (void)
 Re-evaluate the system max verbosity level (ast_verb_sys_level). More...
 
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. More...
 
static struct logchannelfind_logchannel (const char *channel)
 Find a particular logger channel by name. More...
 
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. More...
 
static char * handle_logger_show_levels (struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
 CLI command to show logging levels. More...
 
int init_logger (void)
 
static int init_logger_chain (const char *altconf)
 Read config, setup channels. More...
 
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. More...
 
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. More...
 
static int logger_register_level (const char *name)
 
static void * logger_thread (void *data)
 Actual logging thread. More...
 
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. More...
 
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 = "This paragraph is copyright (c) 2006 by Digium, Inc. \In order for your module to load, it must return this \key via a function called \"key\". Any code which \includes this paragraph must be licensed under the GNU \General Public License version 2 or later (at your \option). In addition to Digium's general reservations \of rights, Digium expressly reserves the right to \allow other parties to license this paragraph under \different terms. Any use of Digium, Inc. trademarks or \logos (including \"Asterisk\" or \"Digium\") without \express written permission of Digium, Inc. is prohibited.\n" , .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
 
static struct ast_threadstorage callid_group_name = { .once = PTHREAD_ONCE_INIT , .key_init = __init_callid_group_name , .custom_init = NULL , }
 
struct chan_group_lock_list chan_group_lock_list = { .first = NULL, .last = NULL, .lock = { PTHREAD_RWLOCK_INITIALIZER , NULL, {1, 0} } , }
 
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. More...
 
static char * custom_dynamic_levels [NUMLOGLEVELS]
 Custom dynamic logging levels added by the user. More...
 
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. More...
 
static struct ast_threadstorage log_buf = { .once = PTHREAD_ONCE_INIT , .key_init = __init_log_buf , .custom_init = NULL , }
 
static struct ast_custom_function log_group_function
 
static struct logchannels logchannels = { .first = NULL, .last = NULL, .lock = { PTHREAD_RWLOCK_INITIALIZER , NULL, {1, 0} } , }
 
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 = { .first = NULL, .last = NULL, .lock = { PTHREAD_RECURSIVE_MUTEX_INITIALIZER_NP , NULL, {1, 0} } , }
 
static pthread_t logthread = AST_PTHREADT_NULL
 
static struct ast_threadstorage my_verb_console = { .once = PTHREAD_ONCE_INIT , .key_init = __init_my_verb_console , .custom_init = 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 ast_threadstorage unique_callid = { .once = PTHREAD_ONCE_INIT , .key_init = __init_unique_callid , .custom_init = NULL , }
 
static struct verb_consoles verb_consoles = { .first = NULL, .last = NULL, .lock = { PTHREAD_RWLOCK_INITIALIZER , NULL, {1, 0} } , }
 
static ast_mutex_t verb_update_lock = { PTHREAD_RECURSIVE_MUTEX_INITIALIZER_NP , NULL, {1, 0} }
 
static struct ast_threadstorage verbose_buf = { .once = PTHREAD_ONCE_INIT , .key_init = __init_verbose_buf , .custom_init = NULL , }
 
static struct ast_threadstorage verbose_build_buf = { .once = PTHREAD_ONCE_INIT , .key_init = __init_verbose_build_buf , .custom_init = NULL , }
 

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");

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

2526{
2527 ast_callid callid;
2528 va_list ap;
2529
2531
2532 va_start(ap, fmt);
2533 __ast_verbose_ap(file, line, func, level, callid, fmt, ap);
2534 va_end(ap);
2535}
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:2520
ast_callid ast_read_threadstorage_callid(void)
extracts the callerid from the thread
Definition: logger.c:2273

References __ast_verbose_ap(), ast_read_threadstorage_callid(), and make_ari_stubs::file.

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

2521{
2522 ast_log_full(__LOG_VERBOSE, level, file, line, func, callid, fmt, ap);
2523}
#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:2364

References __LOG_VERBOSE, ast_log_full(), and make_ari_stubs::file.

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

2538{
2539 va_list ap;
2540 va_start(ap, fmt);
2541 __ast_verbose_ap(file, line, func, level, callid, fmt, ap);
2542 va_end(ap);
2543}

References __ast_verbose_ap(), and make_ari_stubs::file.

◆ __init_callid_group_name()

static void __init_callid_group_name ( void  )
static

Definition at line 1648 of file logger.c.

1651{

◆ __init_log_buf()

static void __init_log_buf ( void  )
static

Definition at line 270 of file logger.c.

274{

◆ __init_my_verb_console()

static void __init_my_verb_console ( void  )
static

Thread specific console verbosity level node.

Definition at line 2619 of file logger.c.

2622{

◆ __init_unique_callid()

static void __init_unique_callid ( void  )
static

Definition at line 90 of file logger.c.

102{

◆ __init_verbose_buf()

static void __init_verbose_buf ( void  )
static

Definition at line 266 of file logger.c.

274{

◆ __init_verbose_build_buf()

static void __init_verbose_build_buf ( void  )
static

Definition at line 267 of file logger.c.

274{

◆ __reg_module()

static void __reg_module ( void  )
static

Definition at line 2940 of file logger.c.

◆ __unreg_module()

static void __unreg_module ( void  )
static

Definition at line 2940 of file logger.c.

◆ _handle_SIGXFSZ()

static void _handle_SIGXFSZ ( int  sig)
static

Definition at line 1889 of file logger.c.

1890{
1891 /* Indicate need to reload */
1893}
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 2263 of file logger.c.

2264{
2265 snprintf(buffer, buffer_size, "[C-%08x]", callid);
2266}

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

2296{
2297 ast_callid *pointing;
2298
2299 pointing = ast_threadstorage_get(&unique_callid, sizeof(*pointing));
2300 if (!pointing) {
2301 return -1;
2302 }
2303
2304 if (*pointing) {
2305 ast_log(LOG_ERROR, "ast_callid_threadassoc_add(C-%08x) on thread "
2306 "already associated with callid [C-%08x].\n", callid, *pointing);
2307 return 1;
2308 }
2309
2310 *pointing = callid;
2311 return 0;
2312}
#define LOG_ERROR
void ast_log(int level, const char *file, int line, const char *function, const char *fmt,...)
Used for sending a log message This is the standard logger function. Probably the only way you will i...
Definition: logger.c:2428
static struct ast_threadstorage unique_callid
Definition: logger.c:90
void * ast_threadstorage_get(struct ast_threadstorage *ts, size_t init_size)
Retrieve thread storage.

References ast_log(), ast_threadstorage_get(), LOG_ERROR, and unique_callid.

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

2283{
2284 ast_callid *id = ast_threadstorage_get(&unique_callid, sizeof(*id));
2285
2286 if (!id) {
2287 return -1;
2288 }
2289
2290 *id = callid;
2291
2292 return 0;
2293}

References ast_threadstorage_get(), and unique_callid.

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

2315{
2316 ast_callid *pointing;
2317
2318 pointing = ast_threadstorage_get(&unique_callid, sizeof(*pointing));
2319 if (!pointing) {
2320 return -1;
2321 }
2322
2323 if (*pointing) {
2324 *pointing = 0;
2325 return 0;
2326 }
2327
2328 return -1;
2329}

References ast_threadstorage_get(), and unique_callid.

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

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

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

2354{
2355 if (callid && callid_created) {
2356 /* If the callid was created rather than simply grabbed from the thread storage, we need to unbind here. */
2358 }
2359}
int ast_callid_threadassoc_remove(void)
Removes callid from thread storage of the calling thread.
Definition: logger.c:2314

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

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

2269{
2271}
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 2150 of file logger.c.

2151{
2152 return logger_initialized;
2153}
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 2428 of file logger.c.

2429{
2430 va_list ap;
2431
2432 va_start(ap, fmt);
2433 ast_log_ap(level, file, line, function, fmt, ap);
2434 va_end(ap);
2435}
void ast_log_ap(int level, const char *file, int line, const char *function, const char *fmt, va_list ap)
Definition: logger.c:2437

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

Referenced by ast_callid_threadassoc_add(), ast_log_backtrace(), init_logger(), log_group_write(), logger_queue_init(), logger_queue_restart(), logger_register_level(), and rotate_file().

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

2438{
2439 ast_callid callid;
2440
2442
2443 if (level == __LOG_VERBOSE) {
2444 __ast_verbose_ap(file, line, function, 0, callid, fmt, ap);
2445 } else {
2446 ast_log_full(level, -1, file, line, function, callid, fmt, ap);
2447 }
2448}

References __ast_verbose_ap(), __LOG_VERBOSE, ast_log_full(), ast_read_threadstorage_callid(), logmsg::callid, make_ari_stubs::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 2485 of file logger.c.

2486{
2487#ifdef HAVE_BKTR
2488 struct ast_bt *bt;
2489 int i = 0;
2490 struct ast_vector_string *strings;
2491
2492 if (!(bt = ast_bt_create())) {
2493 ast_log(LOG_WARNING, "Unable to allocate space for backtrace structure\n");
2494 return;
2495 }
2496
2497 if ((strings = ast_bt_get_symbols(bt->addresses, bt->num_frames))) {
2498 int count = AST_VECTOR_SIZE(strings);
2499 struct ast_str *buf = ast_str_create(bt->num_frames * 64);
2500
2501 if (buf) {
2502 ast_str_append(&buf, 0, "Got %d backtrace record%c\n", count - 3, count - 3 != 1 ? 's' : ' ');
2503 for (i = 3; i < AST_VECTOR_SIZE(strings); i++) {
2504 ast_str_append(&buf, 0, "#%2d: %s\n", i - 3, AST_VECTOR_GET(strings, i));
2505 }
2507 ast_free(buf);
2508 }
2509
2510 ast_bt_free_symbols(strings);
2511 } else {
2512 ast_log(LOG_ERROR, "Could not allocate memory for backtrace\n");
2513 }
2514 ast_bt_destroy(bt);
2515#else
2516 ast_log(LOG_WARNING, "Must run configure with '--with-execinfo' for stack backtraces.\n");
2517#endif /* defined(HAVE_BKTR) */
2518}
#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:2450
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
char * ast_str_buffer(const struct ast_str *buf)
Returns the string buffer within the ast_str buf.
Definition: strings.h:761
#define ast_str_create(init_len)
Create a malloc'ed dynamic length string.
Definition: strings.h:659
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:609
#define AST_VECTOR_GET(vec, idx)
Get an element from a vector.
Definition: vector.h:680

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

2477{
2478 va_list ap;
2479 va_start(ap, fmt);
2480 ast_log_full(level, -1, file, line, function, callid, fmt, ap);
2481 va_end(ap);
2482}

References ast_log_full(), logmsg::callid, make_ari_stubs::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 2364 of file logger.c.

2367{
2368 int hidecli = 0;
2369 struct logmsg *logmsg = NULL;
2370
2372 return;
2373 }
2374
2376 switch (level) {
2377 case __LOG_VERBOSE:
2378 case __LOG_DEBUG:
2379 case __LOG_TRACE:
2380 case __LOG_DTMF:
2381 hidecli = 1; /* Hide the message from the CLI, but still log to any log files */
2382 default: /* Always show NOTICE, WARNING, ERROR, etc. */
2383 break;
2384 }
2385 return;
2386 }
2387
2392 logmsg = format_log_message(__LOG_WARNING, 0, "logger", 0, "***", 0,
2393 "Log queue threshold (%d) exceeded. Discarding new messages.\n", logger_queue_limit);
2395 high_water_alert = 1;
2397 }
2399 return;
2400 }
2402
2404 if (!logmsg) {
2405 return;
2406 }
2407
2409
2410 /* If the logger thread is active, append it to the tail end of the list - otherwise skip that step */
2413 if (close_logger_thread) {
2414 /* Logger is either closing or closed. We cannot log this message. */
2416 } else {
2420 }
2422 } else {
2425 }
2426}
#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.
Definition: linkedlists.h:731
#define AST_LIST_LOCK(head)
Locks a list.
Definition: linkedlists.h:40
#define AST_LIST_UNLOCK(head)
Attempts to unlock a list.
Definition: linkedlists.h:140
#define AST_PTHREADT_NULL
Definition: lock.h:73
#define ast_cond_signal(cond)
Definition: lock.h:210
static int callid_filtering
Definition: logger.c:1658
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:1901
static int callid_logging_enabled(void)
Definition: logger.c:1752
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:1993
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:2057
static void logmsg_free(struct logmsg *msg)
Definition: logger.c:187
#define ast_opt_remote
Definition: options.h:115
#define ast_opt_exec
Definition: options.h:116
Definition: logger.c:169
int line
Definition: logger.c:173
ast_callid callid
Definition: logger.c:175
int sublevel
Definition: logger.c:172
struct logmsg::@372 list
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, make_ari_stubs::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 2450 of file logger.c.

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

1507{
1508 struct logchannel *chan;
1509
1511 return AST_LOGGER_DECLINE;
1512 }
1513
1515
1516 chan = find_logchannel(log_channel);
1517 if (chan) {
1519 return AST_LOGGER_FAILURE;
1520 }
1521
1522 chan = make_logchannel(log_channel, components, 0, 1);
1523 if (!chan) {
1526 }
1527
1529 global_logmask |= chan->logmask;
1530
1532
1533 return AST_LOGGER_SUCCESS;
1534}
@ 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.
Definition: linkedlists.h:151
#define AST_RWLIST_INSERT_HEAD
Definition: linkedlists.h:718
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::@371 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 1394 of file logger.c.

1396{
1397 struct logchannel *chan;
1398 struct ast_str *configs = ast_str_create(64);
1399 int res = AST_LOGGER_SUCCESS;
1400
1401 if (!configs) {
1403 }
1404
1406 AST_RWLIST_TRAVERSE(&logchannels, chan, list) {
1407 unsigned int level;
1408
1410
1411 for (level = 0; level < ARRAY_LEN(levels); level++) {
1412 if ((chan->logmask & (1 << level)) && levels[level]) {
1413 ast_str_append(&configs, 0, "%s ", levels[level]);
1414 }
1415 }
1416
1417 res = logentry(chan->filename, chan->type == LOGTYPE_CONSOLE ? "Console" :
1418 (chan->type == LOGTYPE_SYSLOG ? "Syslog" : "File"), chan->disabled ?
1419 "Disabled" : "Enabled", ast_str_buffer(configs), data);
1420
1421 if (res) {
1424 configs = NULL;
1425 return AST_LOGGER_FAILURE;
1426 }
1427 }
1429
1431 configs = NULL;
1432
1433 return AST_LOGGER_SUCCESS;
1434}
#define AST_RWLIST_RDLOCK(head)
Read locks a list.
Definition: linkedlists.h:78
#define AST_RWLIST_TRAVERSE
Definition: linkedlists.h:494
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
int disabled
Definition: logger.c:141
#define ARRAY_LEN(a)
Definition: utils.h:666

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

2903{
2904 return dateformat;
2905}
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 2855 of file logger.c.

2856{
2857 int level = -1;
2858
2860
2862
2864
2865 return level;
2866}
static const char name[]
Definition: format_mp3.c:68
static int logger_get_dynamic_level(const char *name)
Definition: logger.c:2837

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

2913{
2914 return logger_queue_limit;
2915}

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

2827{
2828 int available = 0;
2829
2833
2834 return available;
2835}
static int available(struct dahdi_pvt **pvt, int is_specific_channel)
Definition: chan_dahdi.c:13574
static int logger_register_level(const char *name)
Definition: logger.c:2789

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(), 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 1572 of file logger.c.

1573{
1574 struct logchannel *chan;
1575
1577
1578 chan = find_logchannel(log_channel);
1579 if (chan && chan->dynamic) {
1581 } else {
1583 return AST_LOGGER_FAILURE;
1584 }
1586
1587 if (chan->fileptr) {
1588 fclose(chan->fileptr);
1589 chan->fileptr = NULL;
1590 }
1591 ast_free(chan);
1592 chan = NULL;
1593
1594 return AST_LOGGER_SUCCESS;
1595}
#define AST_RWLIST_REMOVE
Definition: linkedlists.h:885
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 1312 of file logger.c.

1313{
1314 return reload_logger(1, NULL);
1315}
static int reload_logger(int rotate, const char *altconf)
Definition: logger.c:1209

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

1318{
1319 struct logchannel *f;
1320 int success = AST_LOGGER_FAILURE;
1321 char filename[PATH_MAX];
1322
1323 make_filename(log_channel, filename, sizeof(filename));
1324
1326
1328
1330 if (f->disabled) {
1331 f->disabled = 0; /* Re-enable logging at reload */
1332 manager_event(EVENT_FLAG_SYSTEM, "LogChannel", "Channel: %s\r\nEnabled: Yes\r\n",
1333 f->filename);
1334 }
1335 if (f->fileptr && (f->fileptr != stdout) && (f->fileptr != stderr)) {
1336 fclose(f->fileptr); /* Close file */
1337 f->fileptr = NULL;
1338 if (strcmp(filename, f->filename) == 0) {
1340 success = AST_LOGGER_SUCCESS;
1341 }
1342 }
1343 }
1344
1346
1348
1349 return success;
1350}
#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:1042
#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 ast_mkdir(const char *path, int mode)
Recursively create directory path.
Definition: utils.c:2479

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

2908{
2909 logger_queue_limit = queue_limit;
2910}

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

2885{
2886 int x;
2887
2890
2891 if (x) {
2893 }
2894
2896
2897 if (x) {
2898 ast_debug(1, "Unregistered dynamic logger level '%s' with index %u.\n", name, x);
2899 }
2900}
#define ast_debug(level,...)
Log a DEBUG message.
static void update_logchannels(void)
Definition: logger.c:2685
static int logger_unregister_level(const char *name)
Definition: logger.c:2868

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

◆ AST_MODULE_SELF_SYM()

struct ast_module * AST_MODULE_SELF_SYM ( void  )

Definition at line 2940 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 962 of file logger.c.

963{
964 va_list ap;
965 struct timeval tv;
966 struct ast_tm tm;
967 char qlog_msg[8192];
968 int qlog_len;
969 char time_str[30];
970
971 if (!logger_initialized) {
972 /* You are too early. We are not open yet! */
973 return;
974 }
975 if (!queuelog_init) {
976 /* We must initialize now since someone is trying to log something. */
978 }
979
980 if (ast_check_realtime("queue_log")) {
981 tv = ast_tvnow();
982 ast_localtime(&tv, &tm, logfiles.queue_log_realtime_use_gmt ? "GMT" : NULL);
983 ast_strftime(time_str, sizeof(time_str), "%F %T.%6q", &tm);
984 va_start(ap, fmt);
985 vsnprintf(qlog_msg, sizeof(qlog_msg), fmt, ap);
986 va_end(ap);
987 if (logfiles.queue_adaptive_realtime) {
989 AST_APP_ARG(data)[5];
990 );
991 AST_NONSTANDARD_APP_ARGS(args, qlog_msg, '|');
992 /* Ensure fields are large enough to receive data */
993 ast_realtime_require_field("queue_log",
994 "data1", RQ_CHAR, strlen(S_OR(args.data[0], "")),
995 "data2", RQ_CHAR, strlen(S_OR(args.data[1], "")),
996 "data3", RQ_CHAR, strlen(S_OR(args.data[2], "")),
997 "data4", RQ_CHAR, strlen(S_OR(args.data[3], "")),
998 "data5", RQ_CHAR, strlen(S_OR(args.data[4], "")),
999 SENTINEL);
1000
1001 /* Store the log */
1002 ast_store_realtime("queue_log", "time", time_str,
1003 "callid", callid,
1004 "queuename", queuename,
1005 "agent", agent,
1006 "event", event,
1007 "data1", S_OR(args.data[0], ""),
1008 "data2", S_OR(args.data[1], ""),
1009 "data3", S_OR(args.data[2], ""),
1010 "data4", S_OR(args.data[3], ""),
1011 "data5", S_OR(args.data[4], ""),
1012 SENTINEL);
1013 } else {
1014 ast_store_realtime("queue_log", "time", time_str,
1015 "callid", callid,
1016 "queuename", queuename,
1017 "agent", agent,
1018 "event", event,
1019 "data", qlog_msg,
1020 SENTINEL);
1021 }
1022
1023 if (!logfiles.queue_log_to_file) {
1024 return;
1025 }
1026 }
1027
1028 if (qlog) {
1029 va_start(ap, fmt);
1030 qlog_len = snprintf(qlog_msg, sizeof(qlog_msg), "%ld|%s|%s|%s|%s|", (long)time(NULL), callid, queuename, agent, event);
1031 vsnprintf(qlog_msg + qlog_len, sizeof(qlog_msg) - qlog_len, fmt, ap);
1032 va_end(ap);
1034 if (qlog) {
1035 fprintf(qlog, "%s\n", qlog_msg);
1036 fflush(qlog);
1037 }
1039 }
1040}
#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.
Definition: main/config.c:3769
int ast_check_realtime(const char *family)
Check if realtime engine is configured for family.
Definition: main/config.c:3750
int ast_store_realtime(const char *family,...) attribute_sentinel
Create realtime configuration.
Definition: main/config.c:3960
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:2161
static FILE * qlog
Definition: logger.c:198
static struct @370 logfiles
#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
Definition: astman.c:222
const char * args
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 callerid from the thread

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

Definition at line 2273 of file logger.c.

2274{
2275 ast_callid *callid;
2276
2277 callid = ast_threadstorage_get(&unique_callid, sizeof(*callid));
2278
2279 return callid ? *callid : 0;
2280}

References ast_threadstorage_get(), and unique_callid.

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

2649{
2650 struct verb_console *console;
2651 int verb_level;
2652
2655 if (!console) {
2656 verb_level = 0;
2657 } else if (console->level) {
2658 verb_level = *console->level;
2659 } else {
2660 verb_level = option_verbose;
2661 }
2663 return verb_level;
2664}
int option_verbose
Definition: options.c:68
static struct ast_threadstorage my_verb_console
Definition: logger.c:2619

References AST_RWLIST_RDLOCK, AST_RWLIST_UNLOCK, ast_threadstorage_get(), my_verb_console, 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 2621 of file logger.c.

2622{
2623 struct verb_console *console;
2624
2626 if (!console || !level) {
2627 return;
2628 }
2629 console->level = level;
2630
2635}
void ast_verb_update(void)
Re-evaluate the system max verbosity level (ast_verb_sys_level).
Definition: logger.c:2559
Definition: test_heap.c:38
int * level
Definition: logger.c:2550

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

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

2667{
2668 struct verb_console *console;
2669
2671 if (!console) {
2672 return;
2673 }
2674
2676 if (console->level) {
2677 *console->level = verb_level;
2678 } else {
2679 option_verbose = verb_level;
2680 }
2683}

References AST_RWLIST_UNLOCK, AST_RWLIST_WRLOCK, ast_threadstorage_get(), ast_verb_update(), my_verb_console, 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 2637 of file logger.c.

2638{
2639 struct verb_console *console;
2640
2642 if (!console) {
2643 return;
2644 }
2646}
static void verb_console_unregister(struct verb_console *console)
Definition: logger.c:2600

References ast_threadstorage_get(), my_verb_console, 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 2559 of file logger.c.

2560{
2561 struct logchannel *log;
2562 struct verb_console *console;
2563 int verb_level;
2564
2566
2568
2569 /* Default to the root console verbosity. */
2570 verb_level = option_verbose;
2571
2572 /* Determine max remote console level. */
2574 if (verb_level < *console->level) {
2575 verb_level = *console->level;
2576 }
2577 }
2579
2580 /* Determine max logger channel level. */
2582 AST_RWLIST_TRAVERSE(&logchannels, log, list) {
2583 if (verb_level < log->verbosity) {
2584 verb_level = log->verbosity;
2585 }
2586 }
2588
2589 ast_verb_sys_level = verb_level;
2590
2592}
int ast_verb_sys_level
Definition: options.c:65
#define AST_LIST_TRAVERSE(head, var, field)
Loops over (traverses) the entries in a list.
Definition: linkedlists.h:491
#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:2557
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 1699 of file logger.c.

1700{
1701 int i = 0;
1702 struct chan_group_lock *cgl;
1703
1705 while ((cgl = AST_RWLIST_REMOVE_HEAD(&chan_group_lock_list, entry))) {
1706 ast_free(cgl);
1707 i++;
1708 }
1709 callid_filtering = 0;
1711 return i;
1712}
#define AST_RWLIST_REMOVE_HEAD
Definition: linkedlists.h:844
map call ID to group
Definition: logger.c:1651

References ast_free, AST_RWLIST_REMOVE_HEAD, AST_RWLIST_UNLOCK, AST_RWLIST_WRLOCK, and callid_filtering.

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

1715{
1716 struct chan_group_lock *cgl;
1717
1720 if (!strcmp(group, cgl->name)) {
1721 if (!enabled) {
1723 ast_free(cgl);
1724 }
1725 break;
1726 }
1727 }
1729
1730 if (!enabled) {
1732 callid_filtering = 0;
1733 }
1735 return 0;
1736 }
1737
1738 if (!cgl) {
1739 cgl = ast_calloc(1, sizeof(*cgl) + strlen(group) + 1);
1740 if (!cgl) {
1742 return -1;
1743 }
1744 strcpy(cgl->name, group); /* Safe */
1746 } /* else, already existed, and was already enabled, no change */
1747 callid_filtering = 1;
1749 return 0;
1750}
#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
Definition: linkedlists.h:570
#define AST_RWLIST_TRAVERSE_SAFE_BEGIN
Definition: linkedlists.h:545
#define AST_LIST_EMPTY(head)
Checks whether the specified list contains any entries.
Definition: linkedlists.h:450
#define AST_RWLIST_TRAVERSE_SAFE_END
Definition: linkedlists.h:617

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, and enabled.

Referenced by handle_logger_chanloggroup_filter().

◆ callid_logging_enabled()

static int callid_logging_enabled ( void  )
static

Definition at line 1752 of file logger.c.

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

References AST_RWLIST_RDLOCK, AST_RWLIST_TRAVERSE, AST_RWLIST_UNLOCK, callid_filtering, and get_callid_group().

Referenced by ast_log_full().

◆ callid_set_chanloggroup()

static int callid_set_chanloggroup ( const char *  group)
static

Definition at line 1667 of file logger.c.

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

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

Referenced by log_group_write().

◆ close_logger()

void close_logger ( void  )

Provided by logger.c

Definition at line 2220 of file logger.c.

2221{
2222 struct logchannel *f = NULL;
2223
2225
2228
2230
2231 /* Stop logger thread */
2236
2238 pthread_join(logthread, NULL);
2239 }
2240
2242
2243 if (qlog) {
2244 fclose(qlog);
2245 qlog = NULL;
2246 }
2247
2248 while ((f = AST_LIST_REMOVE_HEAD(&logchannels, list))) {
2249 if (f->fileptr && (f->fileptr != stdout) && (f->fileptr != stderr)) {
2250 fclose(f->fileptr);
2251 f->fileptr = NULL;
2252 }
2253 ast_free(f);
2254 }
2255
2257
2258 closelog(); /* syslog */
2259
2261}
int ast_cli_unregister_multiple(struct ast_cli_entry *e, int len)
Unregister multiple commands.
Definition: clicompat.c:30
#define AST_LIST_REMOVE_HEAD(head, field)
Removes and returns the head entry from a list.
Definition: linkedlists.h:833
static int callid_group_remove_filters(void)
Definition: logger.c:1699
static struct ast_custom_function log_group_function
Definition: logger.c:1786
static struct ast_cli_entry cli_logger[]
Definition: logger.c:1876
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 file
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 2057 of file logger.c.

2060{
2061 struct logmsg *logmsg;
2062 va_list ap;
2063
2064 va_start(ap, fmt);
2066 va_end(ap);
2067
2068 return logmsg;
2069}

References logmsg::callid, make_ari_stubs::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 1993 of file logger.c.

1996{
1997 struct logmsg *logmsg = NULL;
1998 struct ast_str *buf = NULL;
1999 struct ast_tm tm;
2000 struct timeval now = ast_tvnow();
2001 int res = 0;
2002 char datestring[256];
2003
2005 return NULL;
2006 }
2007
2008 /* Build string */
2009 res = ast_str_set_va(&buf, LOGMSG_SIZE, fmt, ap);
2010
2011 /* If the build failed, then abort and free this structure */
2012 if (res == AST_DYNSTR_BUILD_FAILED) {
2013 return NULL;
2014 }
2015
2016 /* Automatically add a newline to format strings that don't have one */
2017 if (!ast_ends_with(ast_str_buffer(buf), "\n")) {
2018 ast_str_append(&buf, 0, "\n");
2019 }
2020
2021 /* Create a new logging message */
2022 if (!(logmsg = ast_calloc_with_stringfields(1, struct logmsg, res + 128))) {
2023 return NULL;
2024 }
2025
2026 /* Copy string over */
2028
2029 /* Set type */
2030 if (level == __LOG_VERBOSE) {
2032 } else {
2034 }
2035
2036 if (display_callids && callid) {
2037 logmsg->callid = callid;
2038 }
2039
2040 /* Create our date/time */
2041 ast_localtime(&now, &tm, NULL);
2042 ast_strftime(datestring, sizeof(datestring), dateformat, &tm);
2043 ast_string_field_set(logmsg, date, datestring);
2044
2045 /* Copy over data */
2046 logmsg->level = level;
2047 logmsg->sublevel = sublevel;
2048 logmsg->line = line;
2049 ast_string_field_set(logmsg, level_name, levels[level]);
2051 ast_string_field_set(logmsg, function, function);
2052 logmsg->lwp = ast_get_tid();
2053
2054 return logmsg;
2055}
static int display_callids
Definition: logger.c:88
#define LOG_BUF_INIT_SIZE
Definition: logger.c:271
#define LOGMSG_SIZE
Definition: logger.c:100
static struct ast_threadstorage log_buf
Definition: logger.c:270
#define ast_calloc_with_stringfields(n, type, size)
Allocate a structure with embedded stringfields in a single allocation.
Definition: stringfields.h:432
#define ast_string_field_set(x, field, data)
Set a field to a simple string value.
Definition: stringfields.h:521
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:2752

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, make_ari_stubs::file, logmsg::level, levels, logmsg::line, log_buf, 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 1660 of file logger.c.

1661{
1662 char **callid_group;
1663 callid_group = ast_threadstorage_get(&callid_group_name, sizeof(*callid_group));
1664 return callid_group ? *callid_group : NULL;
1665}

References ast_threadstorage_get(), callid_group_name, 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 1536 of file logger.c.

1537{
1538 switch (cmd) {
1539 case CLI_INIT:
1540 e->command = "logger add channel";
1541 e->usage =
1542 "Usage: logger add channel <name> <levels>\n"
1543 " Adds a temporary logger channel. This logger channel\n"
1544 " will exist until removed or until Asterisk is restarted.\n"
1545 " <levels> is a comma-separated list of desired logger\n"
1546 " levels such as: verbose,warning,error\n"
1547 " An optional formatter may be specified with the levels;\n"
1548 " valid values are '[json]' and '[default]'.\n";
1549 return NULL;
1550 case CLI_GENERATE:
1551 return NULL;
1552 }
1553
1554 if (a->argc < 5) {
1555 return CLI_SHOWUSAGE;
1556 }
1557
1558 switch (ast_logger_create_channel(a->argv[3], a->argv[4])) {
1559 case AST_LOGGER_SUCCESS:
1560 return CLI_SUCCESS;
1561 case AST_LOGGER_FAILURE:
1562 ast_cli(a->fd, "Logger channel '%s' already exists\n", a->argv[3]);
1563 return CLI_SUCCESS;
1564 case AST_LOGGER_DECLINE:
1566 default:
1567 ast_cli(a->fd, "ERROR: Unable to create log channel '%s'\n", a->argv[3]);
1568 return CLI_FAILURE;
1569 }
1570}
#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:1506
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 1791 of file logger.c.

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

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

1854{
1855 int removed;
1856
1857 switch (cmd) {
1858 case CLI_INIT:
1859 e->command = "logger filter reset";
1860 e->usage =
1861 "Usage: logger filter reset\n"
1862 " Reset the logger filter.\n"
1863 " This removes any channel groups from filtering\n"
1864 " (all channel execution will be shown)\n";
1865 return NULL;
1866 case CLI_GENERATE:
1867 return NULL;
1868 }
1869
1870 removed = callid_group_remove_filters();
1871
1872 ast_cli(a->fd, "Log filtering has been reset (%d filter%s removed)\n", removed, ESS(removed));
1873 return CLI_SUCCESS;
1874}
#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 1823 of file logger.c.

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

References a, ast_cli(), AST_RWLIST_RDLOCK, AST_RWLIST_TRAVERSE, AST_RWLIST_UNLOCK, CLI_GENERATE, CLI_INIT, CLI_SUCCESS, ast_cli_entry::command, ESS, 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 1274 of file logger.c.

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

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

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

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

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

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

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

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, state, 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 1437 of file logger.c.

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

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

1479{
1480#define FORMATL2 "%5s %s\n"
1481 unsigned int level;
1482 switch (cmd) {
1483 case CLI_INIT:
1484 e->command = "logger show levels";
1485 e->usage =
1486 "Usage: logger show levels\n"
1487 " List configured logger levels.\n";
1488 return NULL;
1489 case CLI_GENERATE:
1490 return NULL;
1491 }
1492 ast_cli(a->fd, FORMATL2, "Level", "Name");
1493 ast_cli(a->fd, FORMATL2, "-----", "----");
1495 for (level = 0; level < ARRAY_LEN(levels); level++) {
1496 if (levels[level]) {
1497 ast_cli(a->fd, "%5d %s\n", level, levels[level]);
1498 }
1499 }
1501 ast_cli(a->fd, "\n");
1502
1503 return CLI_SUCCESS;
1504}
#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 2177 of file logger.c.

2178{
2179 int res;
2180 /* auto rotate if sig SIGXFSZ comes a-knockin */
2181 sigaction(SIGXFSZ, &handle_SIGXFSZ, NULL);
2182
2183 /* Re-initialize the logmsgs mutex. The recursive mutex can be accessed prior
2184 * to Asterisk being forked into the background, which can cause the thread
2185 * ID tracked by the underlying pthread mutex to be different than the ID of
2186 * the thread that unlocks the mutex. Since init_logger is called after the
2187 * fork, it is safe to initialize the mutex here for future accesses.
2188 */
2192
2193 /* start logger thread */
2196 return -1;
2197 }
2198
2199 /* register the logger cli commands */
2202
2204
2205 /* create log channels */
2207 res = init_logger_chain(NULL);
2211 if (res) {
2212 ast_log(LOG_ERROR, "Errors detected in logger.conf. Default console logging is being used.\n");
2213 }
2214
2216
2217 return 0;
2218}
#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:1895
static void * logger_thread(void *data)
Actual logging thread.
Definition: logger.c:2072
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:1559
ast_mutex_t lock
Definition: logger.c:193
#define ast_pthread_create(a, b, c, d)
Definition: utils.h:584

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 } else {
844 if ((s = ast_variable_retrieve(cfg, "general", "rotatetimestamp"))) {
846 fprintf(stderr, "rotatetimestamp option has been deprecated. Please use rotatestrategy instead.\n");
847 }
848 }
849 if ((s = ast_variable_retrieve(cfg, "general", "logger_queue_limit"))) {
850 if (sscanf(s, "%30d", &logger_queue_limit) != 1) {
851 fprintf(stderr, "logger_queue_limit has an invalid value. Leaving at default of %d.\n",
853 }
854 if (logger_queue_limit < 10) {
855 fprintf(stderr, "logger_queue_limit must be >= 10. Setting to 10.\n");
857 }
858 }
859
860 /* Custom dynamic logging levels defined by user */
861 if ((s = ast_variable_retrieve(cfg, "general", "custom_levels"))) {
862 char *customlogs = ast_strdupa(s);
863 char *logfile;
864 char *new_custom_levels[16] = { };
865 unsigned int level, new_level = 0;
866
867 /* get the custom levels we need to register or reload */
868 while ((logfile = strsep(&customlogs, ","))) {
869 new_custom_levels[new_level++] = logfile;
870 }
871
872 /* unregister existing custom levels, if they're not still
873 specified in customlogs, to make room for new levels */
874 for (level = 16; level < ARRAY_LEN(levels); level++) {
875 if (levels[level] && custom_dynamic_levels[level] &&
876 !custom_level_still_exists(new_custom_levels, levels[level], ARRAY_LEN(new_custom_levels))) {
878 custom_dynamic_levels[level] = 0;
879 }
880 }
881
882 new_level = 0;
883 while ((logfile = new_custom_levels[new_level++])) {
884 /* Lock already held, so directly register the level,
885 unless it's already registered (as during reload) */
886 if (logger_get_dynamic_level(logfile) == -1) {
887 int custom_level = logger_register_level(logfile);
888 custom_dynamic_levels[custom_level] = logfile;
889 }
890 }
891 }
892
893 var = ast_variable_browse(cfg, "logfiles");
894 for (; var; var = var->next) {
895 chan = make_logchannel(var->name, var->value, var->lineno, 0);
896 if (!chan) {
897 /* Print error message directly to the consoles since the lock is held
898 * and we don't want to unlock with the list partially built */
899 ast_console_puts_mutable("ERROR: Unable to create log channel '", __LOG_ERROR);
902 continue;
903 }
905 global_logmask |= chan->logmask;
906 }
907
908 if (qlog) {
909 fclose(qlog);
910 qlog = NULL;
911 }
912
914
915 return 0;
916}
#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.
Definition: main/config.c:3541
#define CONFIG_STATUS_FILEINVALID
void ast_config_destroy(struct ast_config *cfg)
Destroys a config.
Definition: extconf.c:1289
const char * ast_variable_retrieve(struct ast_config *config, const char *category, const char *variable)
Definition: main/config.c:869
struct ast_variable * ast_variable_browse(const struct ast_config *config, const char *category_name)
Definition: extconf.c:1215
void ast_console_puts_mutable(const char *string, int level)
log the string to the console, and all attached console clients
Definition: asterisk.c:1326
#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:199
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 2927 of file logger.c.

2928{
2930}
@ 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 1776 of file logger.c.

1777{
1778 int res = callid_set_chanloggroup(value);
1779 if (res) {
1780 ast_log(LOG_ERROR, "Failed to set channel log group for %s\n", ast_channel_name(chan));
1781 return -1;
1782 }
1783 return 0;
1784}
const char * ast_channel_name(const struct ast_channel *chan)
static int callid_set_chanloggroup(const char *group)
Definition: logger.c:1667
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
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_3
#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
static struct ast_threadstorage verbose_buf
Definition: logger.c:266
#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, 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 2837 of file logger.c.

2838{
2839 int level = -1;
2840 unsigned int x;
2841
2842 for (x = 16; x < ARRAY_LEN(levels); x++) {
2843 if (!levels[x]) {
2844 continue;
2845 }
2846 if (!strcasecmp(levels[x], name)) {
2847 level = x;
2848 break;
2849 }
2850 }
2851
2852 return level;
2853}

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

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

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

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

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

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

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

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

2162{
2163 /* Must not be called before the logger is initialized. */
2165
2167 if (!queuelog_init) {
2169 queuelog_init = 1;
2171 ast_queue_log("NONE", "NONE", "NONE", "QUEUESTART", "%s", "");
2172 } else {
2174 }
2175}
void ast_queue_log(const char *queuename, const char *callid, const char *agent, const char *event, const char *fmt,...)
Definition: logger.c:962
static void logger_queue_init(void)
Definition: logger.c:2126

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

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

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

2073{
2074 struct logmsg *next = NULL, *msg = NULL;
2075
2076 for (;;) {
2077 /* We lock the message list, and see if any message exists... if not we wait on the condition to be signalled */
2079 if (AST_LIST_EMPTY(&logmsgs)) {
2080 if (close_logger_thread) {
2082 break;
2083 } else {
2085 }
2086 }
2087
2088 if (high_water_alert) {
2089 msg = format_log_message(__LOG_WARNING, 0, "logger", 0, "***", 0,
2090 "Logging resumed. %d message%s discarded.\n",
2092 if (msg) {
2094 }
2095 high_water_alert = 0;
2097 }
2098
2103
2104 /* Otherwise go through and process each message in the order added */
2105 while ((msg = next)) {
2106 /* Get the next entry now so that we can free our current structure later */
2107 next = AST_LIST_NEXT(msg, list);
2108
2109 /* Depending on the type, send it to the proper function */
2111
2112 /* Free the data since we are done */
2113 logmsg_free(msg);
2114 }
2115 }
2116
2117 return NULL;
2118}
#define AST_LIST_HEAD_INIT_NOLOCK(head)
Initializes a list head structure.
Definition: linkedlists.h:681
#define AST_LIST_FIRST(head)
Returns the first entry contained in a list.
Definition: linkedlists.h:421
#define AST_LIST_NEXT(elm, field)
Returns the next entry in the list after the given entry.
Definition: linkedlists.h:439
#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 2868 of file logger.c.

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

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
Definition: stringfields.h:374

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

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

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

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

2918{
2919 return reload_logger(0, NULL);
2920}

References NULL, and reload_logger().

◆ rotate_file()

static int rotate_file ( const char *  filename)
static

Definition at line 1042 of file logger.c.

1043{
1044 char old[PATH_MAX];
1045 char new[PATH_MAX];
1046 int x, y, which, found, res = 0, fd;
1047 char *suffixes[4] = { "", ".gz", ".bz2", ".Z" };
1048
1049 switch (rotatestrategy) {
1050 case NONE:
1051 /* No rotation */
1052 break;
1053 case SEQUENTIAL:
1054 for (x = 0; ; x++) {
1055 snprintf(new, sizeof(new), "%s.%d", filename, x);
1056 fd = open(new, O_RDONLY);
1057 if (fd > -1)
1058 close(fd);
1059 else
1060 break;
1061 }
1062 if (rename(filename, new)) {
1063 fprintf(stderr, "Unable to rename file '%s' to '%s'\n", filename, new);
1064 res = -1;
1065 } else {
1066 filename = new;
1067 }
1068 break;
1069 case TIMESTAMP:
1070 snprintf(new, sizeof(new), "%s.%ld", filename, (long)time(NULL));
1071 if (rename(filename, new)) {
1072 fprintf(stderr, "Unable to rename file '%s' to '%s'\n", filename, new);
1073 res = -1;
1074 } else {
1075 filename = new;
1076 }
1077 break;
1078 case ROTATE:
1079 /* Find the next empty slot, including a possible suffix */
1080 for (x = 0; ; x++) {
1081 found = 0;
1082 for (which = 0; which < ARRAY_LEN(suffixes); which++) {
1083 snprintf(new, sizeof(new), "%s.%d%s", filename, x, suffixes[which]);
1084 fd = open(new, O_RDONLY);
1085 if (fd > -1) {
1086 close(fd);
1087 found = 1;
1088 break;
1089 }
1090 }
1091 if (!found) {
1092 break;
1093 }
1094 }
1095
1096 /* Found an empty slot */
1097 for (y = x; y > 0; y--) {
1098 for (which = 0; which < ARRAY_LEN(suffixes); which++) {
1099 snprintf(old, sizeof(old), "%s.%d%s", filename, y - 1, suffixes[which]);
1100 fd = open(old, O_RDONLY);
1101 if (fd > -1) {
1102 /* Found the right suffix */
1103 close(fd);
1104 snprintf(new, sizeof(new), "%s.%d%s", filename, y, suffixes[which]);
1105 if (rename(old, new)) {
1106 fprintf(stderr, "Unable to rename file '%s' to '%s'\n", old, new);
1107 res = -1;
1108 }
1109 break;
1110 }
1111 }
1112 }
1113
1114 /* Finally, rename the current file */
1115 snprintf(new, sizeof(new), "%s.0", filename);
1116 if (rename(filename, new)) {
1117 fprintf(stderr, "Unable to rename file '%s' to '%s'\n", filename, new);
1118 res = -1;
1119 } else {
1120 filename = new;
1121 }
1122 }
1123
1126 char buf[512];
1127
1128 pbx_builtin_setvar_helper(c, "filename", filename);
1130 if (c) {
1132 }
1133 if (ast_safe_system(buf) == -1) {
1134 ast_log(LOG_WARNING, "error executing '%s'\n", buf);
1135 }
1136 }
1137 return res;
1138}
#define ast_channel_unref(c)
Decrease channel reference count.
Definition: channel.h:3008
#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:829
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 2922 of file logger.c.

2923{
2924 return 0;
2925}

◆ update_logchannels()

static void update_logchannels ( void  )
static

Definition at line 2685 of file logger.c.

2686{
2687 struct logchannel *cur;
2688
2689 global_logmask = 0;
2690
2692 make_components(cur);
2693 global_logmask |= cur->logmask;
2694 }
2695}

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

2611{
2612 struct verb_console *console = v_console;
2613
2616}

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 = "This paragraph is copyright (c) 2006 by Digium, Inc. \In order for your module to load, it must return this \key via a function called \"key\". Any code which \includes this paragraph must be licensed under the GNU \General Public License version 2 or later (at your \option). In addition to Digium's general reservations \of rights, Digium expressly reserves the right to \allow other parties to license this paragraph under \different terms. Any use of Digium, Inc. trademarks or \logos (including \"Asterisk\" or \"Digium\") without \express written permission of Digium, Inc. is prohibited.\n" , .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 2940 of file logger.c.

◆ ast_module_info

const struct ast_module_info* ast_module_info = &__mod_info
static

Definition at line 2940 of file logger.c.

◆ callid_filtering

int callid_filtering = 0
static

◆ callid_group_name

struct ast_threadstorage callid_group_name = { .once = PTHREAD_ONCE_INIT , .key_init = __init_callid_group_name , .custom_init = NULL , }
static

Definition at line 1648 of file logger.c.

Referenced by callid_set_chanloggroup(), and get_callid_group().

◆ chan_group_lock_list

struct chan_group_lock_list chan_group_lock_list = { .first = NULL, .last = NULL, .lock = { PTHREAD_RWLOCK_INITIALIZER , NULL, {1, 0} } , }

◆ cli_logger

struct ast_cli_entry cli_logger[]
static

Definition at line 1876 of file logger.c.

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.

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:1889

Definition at line 1895 of file logger.c.

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.

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_buf

struct ast_threadstorage log_buf = { .once = PTHREAD_ONCE_INIT , .key_init = __init_log_buf , .custom_init = NULL , }
static

Definition at line 270 of file logger.c.

Referenced by format_log_message_ap().

◆ 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:1776

Definition at line 1786 of file logger.c.

Referenced by close_logger(), and init_logger().

◆ logchannels

struct logchannels logchannels = { .first = NULL, .last = NULL, .lock = { PTHREAD_RWLOCK_INITIALIZER , NULL, {1, 0} } , }
static

◆ 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 { ... } 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.

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.

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.

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

struct logmsgs logmsgs = { .first = NULL, .last = NULL, .lock = { PTHREAD_RECURSIVE_MUTEX_INITIALIZER_NP , NULL, {1, 0} } , }
static

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

◆ my_verb_console

struct ast_threadstorage my_verb_console = { .once = PTHREAD_ONCE_INIT , .key_init = __init_my_verb_console , .custom_init = NULL , }
static

◆ 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

◆ unique_callid

struct ast_threadstorage unique_callid = { .once = PTHREAD_ONCE_INIT , .key_init = __init_unique_callid , .custom_init = NULL , }
static

◆ verb_consoles

struct verb_consoles verb_consoles = { .first = NULL, .last = NULL, .lock = { PTHREAD_RWLOCK_INITIALIZER , NULL, {1, 0} } , }
static

◆ verb_update_lock

ast_mutex_t verb_update_lock = { PTHREAD_RECURSIVE_MUTEX_INITIALIZER_NP , NULL, {1, 0} }
static

ast_verb_update() reentrancy protection lock.

Definition at line 2557 of file logger.c.

Referenced by ast_verb_update().

◆ verbose_buf

struct ast_threadstorage verbose_buf = { .once = PTHREAD_ONCE_INIT , .key_init = __init_verbose_buf , .custom_init = NULL , }
static

Definition at line 266 of file logger.c.

Referenced by logger_add_verbose_magic().

◆ verbose_build_buf

struct ast_threadstorage verbose_build_buf = { .once = PTHREAD_ONCE_INIT , .key_init = __init_verbose_build_buf , .custom_init = NULL , }
static

Definition at line 267 of file logger.c.