Asterisk - The Open Source Telephony Project  GIT-master-a24979a
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  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_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...
 
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 char * handle_logger_add_channel (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 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 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 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 273 of file logger.c.

◆ LOGMSG_SIZE

#define LOGMSG_SIZE   MAX(BUFSIZ, 8192)

Definition at line 103 of file logger.c.

◆ VERBOSE_BUF_INIT_SIZE

#define VERBOSE_BUF_INIT_SIZE   256

Definition at line 270 of file logger.c.

Enumeration Type Documentation

◆ logmsgtypes

Enumerator
LOGMSG_NORMAL 
LOGMSG_VERBOSE 

Definition at line 167 of file logger.c.

167  {
168  LOGMSG_NORMAL = 0,
170 };
@ LOGMSG_NORMAL
Definition: logger.c:168
@ LOGMSG_VERBOSE
Definition: logger.c:169

◆ logtypes

enum logtypes
Enumerator
LOGTYPE_SYSLOG 
LOGTYPE_FILE 
LOGTYPE_CONSOLE 

Definition at line 132 of file logger.c.

132  {
134  LOGTYPE_FILE,
136 };
@ LOGTYPE_CONSOLE
Definition: logger.c:135
@ LOGTYPE_FILE
Definition: logger.c:134
@ LOGTYPE_SYSLOG
Definition: logger.c:133

◆ rotatestrategy

Enumerator
NONE 
SEQUENTIAL 
ROTATE 
TIMESTAMP 

Definition at line 105 of file logger.c.

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

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_4 are defined.

Version
11 added level parameter

Definition at line 2284 of file logger.c.

2285 {
2286  ast_callid callid;
2287  va_list ap;
2288 
2289  callid = ast_read_threadstorage_callid();
2290 
2291  va_start(ap, fmt);
2292  __ast_verbose_ap(file, line, func, level, callid, fmt, ap);
2293  va_end(ap);
2294 }
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:2279
ast_callid ast_read_threadstorage_callid(void)
extracts the callerid from the thread
Definition: logger.c:2048

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

2280 {
2281  ast_log_full(__LOG_VERBOSE, level, file, line, func, callid, fmt, ap);
2282 }
#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:2139

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

2297 {
2298  va_list ap;
2299  va_start(ap, fmt);
2300  __ast_verbose_ap(file, line, func, level, callid, fmt, ap);
2301  va_end(ap);
2302 }

References __ast_verbose_ap(), and make_ari_stubs::file.

◆ __init_log_buf()

static void __init_log_buf ( void  )
static

Definition at line 272 of file logger.c.

276 {

◆ __init_my_verb_console()

static void __init_my_verb_console ( void  )
static

Thread specific console verbosity level node.

Definition at line 2378 of file logger.c.

2381 {

◆ __init_unique_callid()

static void __init_unique_callid ( void  )
static

Definition at line 93 of file logger.c.

105 {

◆ __init_verbose_buf()

static void __init_verbose_buf ( void  )
static

Definition at line 268 of file logger.c.

276 {

◆ __init_verbose_build_buf()

static void __init_verbose_build_buf ( void  )
static

Definition at line 269 of file logger.c.

276 {

◆ __reg_module()

static void __reg_module ( void  )
static

Definition at line 2699 of file logger.c.

◆ __unreg_module()

static void __unreg_module ( void  )
static

Definition at line 2699 of file logger.c.

◆ _handle_SIGXFSZ()

static void _handle_SIGXFSZ ( int  sig)
static

Definition at line 1658 of file logger.c.

1659 {
1660  /* Indicate need to reload */
1662 }
static int filesize_reload_needed
Definition: logger.c:86

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

2039 {
2040  snprintf(buffer, buffer_size, "[C-%08x]", callid);
2041 }

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

2071 {
2072  ast_callid *pointing;
2073 
2074  pointing = ast_threadstorage_get(&unique_callid, sizeof(*pointing));
2075  if (!pointing) {
2076  return -1;
2077  }
2078 
2079  if (*pointing) {
2080  ast_log(LOG_ERROR, "ast_callid_threadassoc_add(C-%08x) on thread "
2081  "already associated with callid [C-%08x].\n", callid, *pointing);
2082  return 1;
2083  }
2084 
2085  *pointing = callid;
2086  return 0;
2087 }
#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:2187
static struct ast_threadstorage unique_callid
Definition: logger.c:93
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_callid_threadstorage_auto(), ast_dial_run(), attended_transfer_monitor_thread(), bridge_channel_control_thread(), bridge_channel_depart_thread(), bridge_channel_ind_thread(), handle_request_do(), 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 2057 of file logger.c.

2058 {
2059  ast_callid *id = ast_threadstorage_get(&unique_callid, sizeof(*id));
2060 
2061  if (!id) {
2062  return -1;
2063  }
2064 
2065  *id = callid;
2066 
2067  return 0;
2068 }

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

2090 {
2091  ast_callid *pointing;
2092 
2093  pointing = ast_threadstorage_get(&unique_callid, sizeof(*pointing));
2094  if (!pointing) {
2095  return -1;
2096  }
2097 
2098  if (*pointing) {
2099  *pointing = 0;
2100  return 0;
2101  }
2102 
2103  return -1;
2104 }

References ast_threadstorage_get(), and unique_callid.

Referenced by ast_callid_threadstorage_auto_clean(), attended_transfer_monitor_thread(), handle_request_do(), 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 2106 of file logger.c.

2107 {
2108  ast_callid tmp;
2109 
2110  /* Start by trying to see if a callid is available from thread storage */
2112  if (tmp) {
2113  *callid = tmp;
2114  return 0;
2115  }
2116 
2117  /* If that failed, try to create a new one and bind it. */
2118  *callid = ast_create_callid();
2119  if (*callid) {
2120  ast_callid_threadassoc_add(*callid);
2121  return 1;
2122  }
2123 
2124  /* If neither worked, then something must have gone wrong. */
2125  return -1;
2126 }
static int tmp()
Definition: bt_open.c:389
int ast_callid_threadassoc_add(ast_callid callid)
Adds a known callid to thread storage of the calling thread.
Definition: logger.c:2070
ast_callid ast_create_callid(void)
factory function to create a new uniquely identifying callid.
Definition: logger.c:2043

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

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

2129 {
2130  if (callid && callid_created) {
2131  /* If the callid was created rather than simply grabbed from the thread storage, we need to unbind here. */
2133  }
2134 }
int ast_callid_threadassoc_remove(void)
Removes callid from thread storage of the calling thread.
Definition: logger.c:2089

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

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

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

2044 {
2046 }
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:755
static volatile int next_unique_callid
Definition: logger.c:90

References ast_atomic_fetchadd_int(), and next_unique_callid.

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

◆ ast_init_logger_for_socket_console()

void ast_init_logger_for_socket_console ( void  )

load logger.conf configuration for console socket connections

Definition at line 700 of file logger.c.

701 {
702  struct ast_config *cfg;
703  const char *s;
704  struct ast_flags config_flags = { 0 };
705 
706  if (!(cfg = ast_config_load2("logger.conf", "logger", config_flags)) || cfg == CONFIG_STATUS_FILEINVALID) {
707  return;
708  }
709 
710  if ((s = ast_variable_retrieve(cfg, "general", "dateformat"))) {
712  }
713 
714  ast_config_destroy(cfg);
715 }
#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:768
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:3220
static char dateformat[256]
Definition: logger.c:81
void ast_copy_string(char *dst, const char *src, size_t size)
Size-limited null-terminating string copy.
Definition: strings.h:406
Structure used to handle boolean flags.
Definition: utils.h:199

References ast_config_destroy(), ast_config_load2(), ast_copy_string(), ast_variable_retrieve(), CONFIG_STATUS_FILEINVALID, and dateformat.

Referenced by ast_remotecontrol().

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

1930 {
1931  return logger_initialized;
1932 }
static int logger_initialized
Definition: logger.c:89

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

2188 {
2189  va_list ap;
2190 
2191  va_start(ap, fmt);
2192  ast_log_ap(level, file, line, function, fmt, ap);
2193  va_end(ap);
2194 }
void ast_log_ap(int level, const char *file, int line, const char *function, const char *fmt, va_list ap)
Definition: logger.c:2196

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

Referenced by ast_callid_threadassoc_add(), ast_log_backtrace(), init_logger(), 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 2196 of file logger.c.

2197 {
2198  ast_callid callid;
2199 
2200  callid = ast_read_threadstorage_callid();
2201 
2202  if (level == __LOG_VERBOSE) {
2203  __ast_verbose_ap(file, line, function, 0, callid, fmt, ap);
2204  } else {
2205  ast_log_full(level, -1, file, line, function, callid, fmt, ap);
2206  }
2207 }

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

2245 {
2246 #ifdef HAVE_BKTR
2247  struct ast_bt *bt;
2248  int i = 0;
2249  struct ast_vector_string *strings;
2250 
2251  if (!(bt = ast_bt_create())) {
2252  ast_log(LOG_WARNING, "Unable to allocate space for backtrace structure\n");
2253  return;
2254  }
2255 
2256  if ((strings = ast_bt_get_symbols(bt->addresses, bt->num_frames))) {
2257  int count = AST_VECTOR_SIZE(strings);
2258  struct ast_str *buf = ast_str_create(bt->num_frames * 64);
2259 
2260  if (buf) {
2261  ast_str_append(&buf, 0, "Got %d backtrace record%c\n", count - 3, count - 3 != 1 ? 's' : ' ');
2262  for (i = 3; i < AST_VECTOR_SIZE(strings); i++) {
2263  ast_str_append(&buf, 0, "#%2d: %s\n", i - 3, AST_VECTOR_GET(strings, i));
2264  }
2266  ast_free(buf);
2267  }
2268 
2269  ast_bt_free_symbols(strings);
2270  } else {
2271  ast_log(LOG_ERROR, "Could not allocate memory for backtrace\n");
2272  }
2273  ast_bt_destroy(bt);
2274 #else
2275  ast_log(LOG_WARNING, "Must run configure with '--with-execinfo' for stack backtraces.\n");
2276 #endif /* defined(HAVE_BKTR) */
2277 }
#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:2209
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:1117
char * ast_str_buffer(const struct ast_str *buf)
Returns the string buffer within the ast_str buf.
Definition: strings.h:739
#define ast_str_create(init_len)
Create a malloc'ed dynamic length string.
Definition: strings.h:640
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:604
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 2235 of file logger.c.

2236 {
2237  va_list ap;
2238  va_start(ap, fmt);
2239  ast_log_full(level, -1, file, line, function, callid, fmt, ap);
2240  va_end(ap);
2241 }

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

2142 {
2143  struct logmsg *logmsg = NULL;
2144 
2146  return;
2147  }
2148 
2153  logmsg = format_log_message(__LOG_WARNING, 0, "logger", 0, "***", 0,
2154  "Log queue threshold (%d) exceeded. Discarding new messages.\n", logger_queue_limit);
2156  high_water_alert = 1;
2158  }
2160  return;
2161  }
2163 
2164  logmsg = format_log_message_ap(level, sublevel, file, line, function, callid, fmt, ap);
2165  if (!logmsg) {
2166  return;
2167  }
2168 
2169  /* If the logger thread is active, append it to the tail end of the list - otherwise skip that step */
2170  if (logthread != AST_PTHREADT_NULL) {
2172  if (close_logger_thread) {
2173  /* Logger is either closing or closed. We cannot log this message. */
2175  } else {
2179  }
2181  } else {
2184  }
2185 }
#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:66
#define ast_cond_signal(cond)
Definition: lock.h:201
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:1836
static int close_logger_thread
Definition: logger.c:198
static pthread_t logthread
Definition: logger.c:196
static int logger_queue_limit
Definition: logger.c:96
static int logger_queue_size
Definition: logger.c:93
static unsigned int high_water_alert
Definition: logger.c:98
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:1772
static ast_cond_t logcond
Definition: logger.c:197
static void logger_print_normal(struct logmsg *logmsg)
Print a normal log message to the channels.
Definition: logger.c:1670
static int logger_messages_discarded
Definition: logger.c:97
static void logmsg_free(struct logmsg *msg)
Definition: logger.c:189
#define ast_opt_remote
Definition: options.h:112
#define ast_opt_exec
Definition: options.h:113
Definition: logger.c:172
struct logmsg::@399 list
int line
Definition: logger.c:176
ast_callid callid
Definition: logger.c:178
int sublevel
Definition: logger.c:175
int level
Definition: logger.c:174

References __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, close_logger_thread, make_ari_stubs::file, format_log_message(), format_log_message_ap(), 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 2209 of file logger.c.

2210 {
2211  va_list ap;
2212  void *recursed = ast_threadstorage_get_ptr(&in_safe_log);
2213  ast_callid callid;
2214 
2215  if (recursed) {
2216  return;
2217  }
2218 
2219  if (ast_threadstorage_set_ptr(&in_safe_log, &(int) { 1 })) {
2220  /* We've failed to set the flag that protects against
2221  * recursion, so bail. */
2222  return;
2223  }
2224 
2225  callid = ast_read_threadstorage_callid();
2226 
2227  va_start(ap, fmt);
2228  ast_log_full(level, -1, file, line, function, callid, fmt, ap);
2229  va_end(ap);
2230 
2231  /* Clear flag so the next allocation failure can be logged. */
2232  ast_threadstorage_set_ptr(&in_safe_log, NULL);
2233 }
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::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 1508 of file logger.c.

1509 {
1510  struct logchannel *chan;
1511 
1512  if (ast_strlen_zero(components)) {
1513  return AST_LOGGER_DECLINE;
1514  }
1515 
1517 
1518  chan = find_logchannel(log_channel);
1519  if (chan) {
1521  return AST_LOGGER_FAILURE;
1522  }
1523 
1524  chan = make_logchannel(log_channel, components, 0, 1);
1525  if (!chan) {
1527  return AST_LOGGER_ALLOC_ERROR;
1528  }
1529 
1531  global_logmask |= chan->logmask;
1532 
1534 
1535  return AST_LOGGER_SUCCESS;
1536 }
@ 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:87
static struct logchannel * make_logchannel(const char *channel, const char *components, int lineno, int dynamic)
Definition: logger.c:633
static struct logchannel * find_logchannel(const char *channel)
Find a particular logger channel by name.
Definition: logger.c:617
static force_inline int attribute_pure ast_strlen_zero(const char *s)
Definition: strings.h:65
struct logchannel::@398 list
unsigned int logmask
Definition: logger.c:142
char components[0]
Definition: logger.c:162

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

1398 {
1399  struct logchannel *chan;
1400  struct ast_str *configs = ast_str_create(64);
1401  int res = AST_LOGGER_SUCCESS;
1402 
1403  if (!configs) {
1404  return AST_LOGGER_ALLOC_ERROR;
1405  }
1406 
1408  AST_RWLIST_TRAVERSE(&logchannels, chan, list) {
1409  unsigned int level;
1410 
1412 
1413  for (level = 0; level < ARRAY_LEN(levels); level++) {
1414  if ((chan->logmask & (1 << level)) && levels[level]) {
1415  ast_str_append(&configs, 0, "%s ", levels[level]);
1416  }
1417  }
1418 
1419  res = logentry(chan->filename, chan->type == LOGTYPE_CONSOLE ? "Console" :
1420  (chan->type == LOGTYPE_SYSLOG ? "Syslog" : "File"), chan->disabled ?
1421  "Disabled" : "Enabled", ast_str_buffer(configs), data);
1422 
1423  if (res) {
1425  ast_free(configs);
1426  configs = NULL;
1427  return AST_LOGGER_FAILURE;
1428  }
1429  }
1431 
1432  ast_free(configs);
1433  configs = NULL;
1434 
1435  return AST_LOGGER_SUCCESS;
1436 }
#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:213
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:674
enum logtypes type
Definition: logger.c:150
char filename[PATH_MAX]
Definition: logger.c:154
int disabled
Definition: logger.c:144
#define ARRAY_LEN(a)
Definition: utils.h:661

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

2662 {
2663  return dateformat;
2664 }

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

2615 {
2616  int level = -1;
2617 
2619 
2620  level = logger_get_dynamic_level(name);
2621 
2623 
2624  return level;
2625 }
static const char name[]
Definition: format_mp3.c:68
static int logger_get_dynamic_level(const char *name)
Definition: logger.c:2596

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

2672 {
2673  return logger_queue_limit;
2674 }

References logger_queue_limit.

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

2586 {
2587  int available = 0;
2588 
2592 
2593  return available;
2594 }
static int available(struct dahdi_pvt **pvt, int is_specific_channel)
Definition: chan_dahdi.c:13095
static int logger_register_level(const char *name)
Definition: logger.c:2548

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

Referenced by handle_cli_dynamic_level_test(), handle_cli_performance_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 1574 of file logger.c.

1575 {
1576  struct logchannel *chan;
1577 
1579 
1580  chan = find_logchannel(log_channel);
1581  if (chan && chan->dynamic) {
1583  } else {
1585  return AST_LOGGER_FAILURE;
1586  }
1588 
1589  if (chan->fileptr) {
1590  fclose(chan->fileptr);
1591  chan->fileptr = NULL;
1592  }
1593  ast_free(chan);
1594  chan = NULL;
1595 
1596  return AST_LOGGER_SUCCESS;
1597 }
#define AST_RWLIST_REMOVE
Definition: linkedlists.h:885
int dynamic
Definition: logger.c:160
FILE * fileptr
Definition: logger.c:152

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

◆ ast_logger_rotate()

int ast_logger_rotate ( void  )

Reload logger while rotating log files.

Definition at line 1314 of file logger.c.

1315 {
1316  return reload_logger(1, NULL);
1317 }
static int reload_logger(int rotate, const char *altconf)
Definition: logger.c:1199

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

1320 {
1321  struct logchannel *f;
1322  int success = AST_LOGGER_FAILURE;
1323  char filename[PATH_MAX];
1324 
1325  make_filename(log_channel, filename, sizeof(filename));
1326 
1328 
1330 
1332  if (f->disabled) {
1333  f->disabled = 0; /* Re-enable logging at reload */
1334  manager_event(EVENT_FLAG_SYSTEM, "LogChannel", "Channel: %s\r\nEnabled: Yes\r\n",
1335  f->filename);
1336  }
1337  if (f->fileptr && (f->fileptr != stdout) && (f->fileptr != stderr)) {
1338  fclose(f->fileptr); /* Close file */
1339  f->fileptr = NULL;
1340  if (strcmp(filename, f->filename) == 0) {
1341  rotate_file(f->filename);
1342  success = AST_LOGGER_SUCCESS;
1343  }
1344  }
1345  }
1346 
1348 
1350 
1351  return success;
1352 }
#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:576
static int init_logger_chain(const char *altconf)
Read config, setup channels.
Definition: logger.c:746
static int rotate_file(const char *filename)
Definition: logger.c:1032
#define manager_event(category, event, contents,...)
External routines may send asterisk manager events this way.
Definition: manager.h:253
#define EVENT_FLAG_SYSTEM
Definition: manager.h:75
const char * ast_config_AST_LOG_DIR
Definition: options.c:159
int ast_mkdir(const char *path, int mode)
Recursively create directory path.
Definition: main/utils.c:2377

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

2667 {
2668  logger_queue_limit = queue_limit;
2669 }

References logger_queue_limit.

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

2644 {
2645  int x;
2646 
2649 
2650  if (x) {
2652  }
2653 
2655 
2656  if (x) {
2657  ast_debug(1, "Unregistered dynamic logger level '%s' with index %u.\n", name, x);
2658  }
2659 }
#define ast_debug(level,...)
Log a DEBUG message.
static void update_logchannels(void)
Definition: logger.c:2444
static int logger_unregister_level(const char *name)
Definition: logger.c:2627

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

◆ AST_MODULE_SELF_SYM()

struct ast_module* AST_MODULE_SELF_SYM ( void  )

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

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

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

2049 {
2050  ast_callid *callid;
2051 
2052  callid = ast_threadstorage_get(&unique_callid, sizeof(*callid));
2053 
2054  return callid ? *callid : 0;
2055 }

References ast_threadstorage_get(), and unique_callid.

Referenced by __ast_verbose(), ast_callid_threadstorage_auto(), ast_log_ap(), ast_log_safe(), bridge_channel_internal_join(), bridge_impart_internal(), common_recall_channel_setup(), iax2_request(), jingle_alloc(), launch_monitor_thread(), local_request_with_stream_topology(), media_request_helper(), sip_request_call(), 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 2407 of file logger.c.

2408 {
2409  struct verb_console *console;
2410  int verb_level;
2411 
2414  if (!console) {
2415  verb_level = 0;
2416  } else if (console->level) {
2417  verb_level = *console->level;
2418  } else {
2419  verb_level = option_verbose;
2420  }
2422  return verb_level;
2423 }
int option_verbose
Definition: options.c:67
static struct ast_threadstorage my_verb_console
Definition: logger.c:2378

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

2381 {
2382  struct verb_console *console;
2383 
2385  if (!console || !level) {
2386  return;
2387  }
2388  console->level = level;
2389 
2393  ast_verb_update();
2394 }
void ast_verb_update(void)
Re-evaluate the system max verbosity level (ast_verb_sys_level).
Definition: logger.c:2318
Definition: test_heap.c:38
int * level
Definition: logger.c:2309

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

2426 {
2427  struct verb_console *console;
2428 
2430  if (!console) {
2431  return;
2432  }
2433 
2435  if (console->level) {
2436  *console->level = verb_level;
2437  } else {
2438  option_verbose = verb_level;
2439  }
2441  ast_verb_update();
2442 }

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

2397 {
2398  struct verb_console *console;
2399 
2401  if (!console) {
2402  return;
2403  }
2405 }
static void verb_console_unregister(struct verb_console *console)
Definition: logger.c:2359

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

2319 {
2320  struct logchannel *log;
2321  struct verb_console *console;
2322  int verb_level;
2323 
2325 
2327 
2328  /* Default to the root console verbosity. */
2329  verb_level = option_verbose;
2330 
2331  /* Determine max remote console level. */
2333  if (verb_level < *console->level) {
2334  verb_level = *console->level;
2335  }
2336  }
2338 
2339  /* Determine max logger channel level. */
2341  AST_RWLIST_TRAVERSE(&logchannels, log, list) {
2342  if (verb_level < log->verbosity) {
2343  verb_level = log->verbosity;
2344  }
2345  }
2347 
2348  ast_verb_sys_level = verb_level;
2349 
2351 }
int ast_verb_sys_level
Definition: options.c:64
#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:188
#define ast_mutex_lock(a)
Definition: lock.h:187
static ast_mutex_t verb_update_lock
Definition: logger.c:2316
int verbosity
Definition: logger.c:148

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

◆ close_logger()

void close_logger ( void  )

Provided by logger.c

Definition at line 1998 of file logger.c.

1999 {
2000  struct logchannel *f = NULL;
2001 
2003 
2005 
2006  logger_initialized = 0;
2007 
2008  /* Stop logger thread */
2010  close_logger_thread = 1;
2013 
2014  if (logthread != AST_PTHREADT_NULL) {
2015  pthread_join(logthread, NULL);
2016  }
2017 
2019 
2020  if (qlog) {
2021  fclose(qlog);
2022  qlog = NULL;
2023  }
2024 
2025  while ((f = AST_LIST_REMOVE_HEAD(&logchannels, list))) {
2026  if (f->fileptr && (f->fileptr != stdout) && (f->fileptr != stderr)) {
2027  fclose(f->fileptr);
2028  f->fileptr = NULL;
2029  }
2030  ast_free(f);
2031  }
2032 
2033  closelog(); /* syslog */
2034 
2036 }
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 struct ast_cli_entry cli_logger[]
Definition: logger.c:1648
int ast_logger_category_unload(void)
Unload system wide logger category functionality.

References ARRAY_LEN, ast_cli_unregister_multiple(), ast_cond_signal, 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, cli_logger, close_logger_thread, logchannel::fileptr, logchannel::list, 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 726 of file logger.c.

727 {
728  int i;
729  for (i = 0; i < len; i++) {
730  if (!strcmp(levels[i], level)) {
731  return 1;
732  }
733  }
734  return 0;
735 }
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 617 of file logger.c.

618 {
619  char filename[PATH_MAX];
620  struct logchannel *chan;
621 
622  make_filename(channel, filename, sizeof(filename));
623 
625  if (!strcmp(chan->filename, filename)) {
626  return chan;
627  }
628  }
629 
630  return NULL;
631 }

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

382 {
383  char call_identifier_str[13];
384 
385  if (msg->callid) {
386  snprintf(call_identifier_str, sizeof(call_identifier_str), "[C-%08x]", msg->callid);
387  } else {
388  call_identifier_str[0] = '\0';
389  }
390 
391  switch (chan->type) {
392  case LOGTYPE_SYSLOG:
393  snprintf(buf, size, "%s[%d]%s: %s:%d in %s: %s",
394  levels[msg->level], msg->lwp, call_identifier_str, msg->file,
395  msg->line, msg->function, msg->message);
396  term_strip(buf, buf, size);
397  break;
398  case LOGTYPE_FILE:
399  snprintf(buf, size, "[%s] %s[%d]%s %s: %s",
400  msg->date, msg->level_name, msg->lwp, call_identifier_str,
401  msg->file, msg->message);
402  term_strip(buf, buf, size);
403  break;
404  case LOGTYPE_CONSOLE:
405  {
406  char linestr[32];
407  int has_file = !ast_strlen_zero(msg->file);
408  int has_line = (msg->line > 0);
409  int has_func = !ast_strlen_zero(msg->function);
410 
411  /*
412  * Verbose messages are interpreted by console channels in their own
413  * special way
414  */
415  if (msg->level == __LOG_VERBOSE) {
416  return logger_add_verbose_magic(msg, buf, size);
417  }
418 
419  /* Turn the numerical line number into a string */
420  snprintf(linestr, sizeof(linestr), "%d", msg->line);
421  /* Build string to print out */
422  snprintf(buf, size, "[%s] " COLORIZE_FMT "[%d]%s: " COLORIZE_FMT "%s" COLORIZE_FMT " " COLORIZE_FMT "%s %s",
423  msg->date,
424  COLORIZE(colors[msg->level], 0, msg->level_name),
425  msg->lwp,
426  call_identifier_str,
427  COLORIZE(COLOR_BRWHITE, 0, has_file ? msg->file : ""),
428  has_file ? ":" : "",
429  COLORIZE(COLOR_BRWHITE, 0, has_line ? linestr : ""),
430  COLORIZE(COLOR_BRWHITE, 0, has_func ? msg->function : ""),
431  has_func ? ":" : "",
432  msg->message);
433  }
434  break;
435  }
436 
437  return 0;
438 }
static int logger_add_verbose_magic(struct logmsg *logmsg, char *buf, size_t size)
Definition: logger.c:335
static const int colors[NUMLOGLEVELS]
Colors used in the console for logging.
Definition: logger.c:233
const ast_string_field level_name
Definition: logger.c:185
int lwp
Definition: logger.c:177
const ast_string_field message
Definition: logger.c:185
const ast_string_field file
Definition: logger.c:185
const ast_string_field function
Definition: logger.c:185
const ast_string_field date
Definition: logger.c:185
char * term_strip(char *outbuf, const char *inbuf, int maxout)
Remove colorings from a specified string.
Definition: term.c:362
#define COLOR_BRWHITE
Definition: term.h:65
#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 275 of file logger.c.

276 {
277  struct ast_json *json;
278  char *str;
279  char call_identifier_str[13];
280  size_t json_str_len;
281 
282  if (msg->callid) {
283  snprintf(call_identifier_str, sizeof(call_identifier_str), "[C-%08x]", msg->callid);
284  } else {
285  call_identifier_str[0] = '\0';
286  }
287 
288  json = ast_json_pack("{s: s, s: s, "
289  "s: {s: i, s: s} "
290  "s: {s: {s: s, s: s, s: i}, "
291  "s: s, s: s} }",
292  "hostname", ast_config_AST_SYSTEM_NAME,
293  "timestamp", msg->date,
294  "identifiers",
295  "lwp", msg->lwp,
296  "callid", S_OR(call_identifier_str, ""),
297  "logmsg",
298  "location",
299  "filename", msg->file,
300  "function", msg->function,
301  "line", msg->line,
302  "level", msg->level_name,
303  "message", msg->message);
304  if (!json) {
305  return -1;
306  }
307 
308  str = ast_json_dump_string(json);
309  if (!str) {
310  ast_json_unref(json);
311  return -1;
312  }
313 
314  ast_copy_string(buf, str, size);
315  json_str_len = strlen(str);
316  if (json_str_len > size - 1) {
317  json_str_len = size - 1;
318  }
319  buf[json_str_len] = '\n';
320  buf[json_str_len + 1] = '\0';
321 
322  term_strip(buf, buf, size);
323 
325  ast_json_unref(json);
326 
327  return 0;
328 }
const char * str
Definition: app_jack.c:147
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:783
struct ast_json * ast_json_pack(char const *format,...)
Helper for creating complex JSON values.
Definition: json.c:591
const char * ast_config_AST_SYSTEM_NAME
Definition: options.c:170
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 1836 of file logger.c.

1839 {
1840  struct logmsg *logmsg;
1841  va_list ap;
1842 
1843  va_start(ap, fmt);
1844  logmsg = format_log_message_ap(level, sublevel, file, line, function, callid, fmt, ap);
1845  va_end(ap);
1846 
1847  return logmsg;
1848 }

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

1775 {
1776  struct logmsg *logmsg = NULL;
1777  struct ast_str *buf = NULL;
1778  struct ast_tm tm;
1779  struct timeval now = ast_tvnow();
1780  int res = 0;
1781  char datestring[256];
1782 
1784  return NULL;
1785  }
1786 
1787  /* Build string */
1788  res = ast_str_set_va(&buf, LOGMSG_SIZE, fmt, ap);
1789 
1790  /* If the build failed, then abort and free this structure */
1791  if (res == AST_DYNSTR_BUILD_FAILED) {
1792  return NULL;
1793  }
1794 
1795  /* Automatically add a newline to format strings that don't have one */
1796  if (!ast_ends_with(ast_str_buffer(buf), "\n")) {
1797  ast_str_append(&buf, 0, "\n");
1798  }
1799 
1800  /* Create a new logging message */
1801  if (!(logmsg = ast_calloc_with_stringfields(1, struct logmsg, res + 128))) {
1802  return NULL;
1803  }
1804 
1805  /* Copy string over */
1807 
1808  /* Set type */
1809  if (level == __LOG_VERBOSE) {
1811  } else {
1813  }
1814 
1815  if (display_callids && callid) {
1816  logmsg->callid = callid;
1817  }
1818 
1819  /* Create our date/time */
1820  ast_localtime(&now, &tm, NULL);
1821  ast_strftime(datestring, sizeof(datestring), dateformat, &tm);
1822  ast_string_field_set(logmsg, date, datestring);
1823 
1824  /* Copy over data */
1825  logmsg->level = level;
1826  logmsg->sublevel = sublevel;
1827  logmsg->line = line;
1828  ast_string_field_set(logmsg, level_name, levels[level]);
1830  ast_string_field_set(logmsg, function, function);
1831  logmsg->lwp = ast_get_tid();
1832 
1833  return logmsg;
1834 }
static int display_callids
Definition: logger.c:91
#define LOG_BUF_INIT_SIZE
Definition: logger.c:273
#define LOGMSG_SIZE
Definition: logger.c:103
static struct ast_threadstorage log_buf
Definition: logger.c:272
#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:1008
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:921
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:887
enum logmsgtypes type
Definition: logger.c:173
int ast_get_tid(void)
Get current thread ID.
Definition: main/utils.c:2650

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

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

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.

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

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

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

Definition at line 1276 of file logger.c.

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

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

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

◆ handle_logger_rotate()

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

Definition at line 1295 of file logger.c.

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

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

1355 {
1356  int x;
1357  int state;
1358  int level = -1;
1359 
1360  switch (cmd) {
1361  case CLI_INIT:
1362  e->command = "logger set level {DEBUG|TRACE|NOTICE|WARNING|ERROR|VERBOSE|DTMF} {on|off}";
1363  e->usage =
1364  "Usage: logger set level {DEBUG|TRACE|NOTICE|WARNING|ERROR|VERBOSE|DTMF} {on|off}\n"
1365  " Set a specific log level to enabled/disabled for this console.\n";
1366  return NULL;
1367  case CLI_GENERATE:
1368  return NULL;
1369  }
1370 
1371  if (a->argc < 5)
1372  return CLI_SHOWUSAGE;
1373 
1375 
1376  for (x = 0; x < ARRAY_LEN(levels); x++) {
1377  if (levels[x] && !strcasecmp(a->argv[3], levels[x])) {
1378  level = x;
1379  break;
1380  }
1381  }
1382 
1384 
1385  state = ast_true(a->argv[4]) ? 1 : 0;
1386 
1387  if (level != -1) {
1388  ast_console_toggle_loglevel(a->fd, level, state);
1389  ast_cli(a->fd, "Logger status for '%s' has been set to '%s'.\n", levels[level], state ? "on" : "off");
1390  } else
1391  return CLI_SHOWUSAGE;
1392 
1393  return CLI_SUCCESS;
1394 }
enum sip_cc_notify_state state
Definition: chan_sip.c:966
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:1245
int attribute_pure ast_true(const char *val)
Make sure something is true. Determine if a string containing a boolean value is "true"....
Definition: main/utils.c:2097

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

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

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

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

1957 {
1958  int res;
1959  /* auto rotate if sig SIGXFSZ comes a-knockin */
1960  sigaction(SIGXFSZ, &handle_SIGXFSZ, NULL);
1961 
1962  /* Re-initialize the logmsgs mutex. The recursive mutex can be accessed prior
1963  * to Asterisk being forked into the background, which can cause the thread
1964  * ID tracked by the underlying pthread mutex to be different than the ID of
1965  * the thread that unlocks the mutex. Since init_logger is called after the
1966  * fork, it is safe to initialize the mutex here for future accesses.
1967  */
1971 
1972  /* start logger thread */
1975  return -1;
1976  }
1977 
1978  /* register the logger cli commands */
1980 
1982 
1983  /* create log channels */
1985  res = init_logger_chain(NULL);
1987  ast_verb_update();
1988  logger_initialized = 1;
1989  if (res) {
1990  ast_log(LOG_ERROR, "Errors detected in logger.conf. Default console logging is being used.\n");
1991  }
1992 
1994 
1995  return 0;
1996 }
#define ast_cli_register_multiple(e, len)
Register multiple commands.
Definition: cli.h:265
#define ast_cond_destroy(cond)
Definition: lock.h:200
#define ast_cond_init(cond, attr)
Definition: lock.h:199
#define ast_mutex_init(pmutex)
Definition: lock.h:184
#define ast_mutex_destroy(a)
Definition: lock.h:186
static struct sigaction handle_SIGXFSZ
Definition: logger.c:1664
static void * logger_thread(void *data)
Actual logging thread.
Definition: logger.c:1851
int ast_logger_category_load(void)
Load/Initialize system wide logger category functionality.
ast_mutex_t lock
Definition: logger.c:195
#define ast_pthread_create(a, b, c, d)
Definition: utils.h:579

References ARRAY_LEN, ast_cli_register_multiple, ast_cond_destroy, ast_cond_init, ast_config_AST_LOG_DIR, 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, 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 746 of file logger.c.

747 {
748  struct logchannel *chan;
749  struct ast_config *cfg;
750  struct ast_variable *var;
751  const char *s;
752  struct ast_flags config_flags = { 0 };
753 
754  if (!(cfg = ast_config_load2(S_OR(altconf, "logger.conf"), "logger", config_flags)) || cfg == CONFIG_STATUS_FILEINVALID) {
755  cfg = NULL;
756  }
757 
758  /* Set defaults */
759  hostname[0] = '\0';
760  display_callids = 1;
761  memset(&logfiles, 0, sizeof(logfiles));
762  logfiles.queue_log = 1;
763  ast_copy_string(dateformat, "%b %e %T", sizeof(dateformat));
765  exec_after_rotate[0] = '\0';
767 
768  /* delete our list of log channels */
769  while ((chan = AST_RWLIST_REMOVE_HEAD(&logchannels, list))) {
770  ast_free(chan);
771  }
772  global_logmask = 0;
773 
774  errno = 0;
775  /* close syslog */
776  closelog();
777 
778  /* If no config file, we're fine, set default options. */
779  if (!cfg) {
780  chan = make_logchannel("console", "error,warning,notice,verbose", 0, 0);
781  if (!chan) {
782  fprintf(stderr, "ERROR: Failed to initialize default logging\n");
783  return -1;
784  }
785 
786  AST_RWLIST_INSERT_HEAD(&logchannels, chan, list);
787  global_logmask |= chan->logmask;
788 
789  return -1;
790  }
791 
792  if ((s = ast_variable_retrieve(cfg, "general", "appendhostname"))) {
793  if (ast_true(s)) {
794  if (gethostname(hostname, sizeof(hostname) - 1)) {
795  ast_copy_string(hostname, "unknown", sizeof(hostname));
796  fprintf(stderr, "What box has no hostname???\n");
797  }
798  }
799  }
800  if ((s = ast_variable_retrieve(cfg, "general", "display_callids"))) {
802  }
803  if ((s = ast_variable_retrieve(cfg, "general", "dateformat"))) {
805  }
806  if ((s = ast_variable_retrieve(cfg, "general", "queue_log"))) {
807  logfiles.queue_log = ast_true(s);
808  }
809  if ((s = ast_variable_retrieve(cfg, "general", "queue_log_to_file"))) {
810  logfiles.queue_log_to_file = ast_true(s);
811  }
812  if ((s = ast_variable_retrieve(cfg, "general", "queue_log_name"))) {
814  }
815  if ((s = ast_variable_retrieve(cfg, "general", "queue_log_realtime_use_gmt"))) {
816  logfiles.queue_log_realtime_use_gmt = ast_true(s);
817  }
818  if ((s = ast_variable_retrieve(cfg, "general", "exec_after_rotate"))) {
820  }
821  if ((s = ast_variable_retrieve(cfg, "general", "rotatestrategy"))) {
822  if (strcasecmp(s, "timestamp") == 0) {
824  } else if (strcasecmp(s, "rotate") == 0) {
826  } else if (strcasecmp(s, "sequential") == 0) {
828  } else if (strcasecmp(s, "none") == 0) {
830  } else {
831  fprintf(stderr, "Unknown rotatestrategy: %s\n", s);
832  }
833  } else {
834  if ((s = ast_variable_retrieve(cfg, "general", "rotatetimestamp"))) {
836  fprintf(stderr, "rotatetimestamp option has been deprecated. Please use rotatestrategy instead.\n");
837  }
838  }
839  if ((s = ast_variable_retrieve(cfg, "general", "logger_queue_limit"))) {
840  if (sscanf(s, "%30d", &logger_queue_limit) != 1) {
841  fprintf(stderr, "logger_queue_limit has an invalid value. Leaving at default of %d.\n",
843  }
844  if (logger_queue_limit < 10) {
845  fprintf(stderr, "logger_queue_limit must be >= 10. Setting to 10.\n");
846  logger_queue_limit = 10;
847  }
848  }
849 
850  /* Custom dynamic logging levels defined by user */
851  if ((s = ast_variable_retrieve(cfg, "general", "custom_levels"))) {
852  char *customlogs = ast_strdupa(s);
853  char *logfile;
854  char *new_custom_levels[16] = { };
855  unsigned int level, new_level = 0;
856 
857  /* get the custom levels we need to register or reload */
858  while ((logfile = strsep(&customlogs, ","))) {
859  new_custom_levels[new_level++] = logfile;
860  }
861 
862  /* unregister existing custom levels, if they're not still
863  specified in customlogs, to make room for new levels */
864  for (level = 16; level < ARRAY_LEN(levels); level++) {
865  if (levels[level] && custom_dynamic_levels[level] &&
866  !custom_level_still_exists(new_custom_levels, levels[level], ARRAY_LEN(new_custom_levels))) {
868  custom_dynamic_levels[level] = 0;
869  }
870  }
871 
872  new_level = 0;
873  while ((logfile = new_custom_levels[new_level++])) {
874  /* Lock already held, so directly register the level,
875  unless it's already registered (as during reload) */
876  if (logger_get_dynamic_level(logfile) == -1) {
877  int custom_level = logger_register_level(logfile);
878  custom_dynamic_levels[custom_level] = logfile;
879  }
880  }
881  }
882 
883  var = ast_variable_browse(cfg, "logfiles");
884  for (; var; var = var->next) {
885  chan = make_logchannel(var->name, var->value, var->lineno, 0);
886  if (!chan) {
887  /* Print error message directly to the consoles since the lock is held
888  * and we don't want to unlock with the list partially built */
889  ast_console_puts_mutable("ERROR: Unable to create log channel '", __LOG_ERROR);
892  continue;
893  }
894  AST_RWLIST_INSERT_HEAD(&logchannels, chan, list);
895  global_logmask |= chan->logmask;
896  }
897 
898  if (qlog) {
899  fclose(qlog);
900  qlog = NULL;
901  }
902 
903  ast_config_destroy(cfg);
904 
905  return 0;
906 }
#define var
Definition: ast_expr2f.c:614
#define ast_strdupa(s)
duplicate a string in memory from the stack
Definition: astmm.h:298
char * strsep(char **str, const char *delims)
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:1310
#define QUEUELOG
#define AST_RWLIST_REMOVE_HEAD
Definition: linkedlists.h:844
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:726
static char * custom_dynamic_levels[NUMLOGLEVELS]
Custom dynamic logging levels added by the user.
Definition: logger.c:230
static char exec_after_rotate[256]
Definition: logger.c:84
static char queue_log_name[256]
Definition: logger.c:83
static char hostname[MAXHOSTNAMELEN]
Definition: logger.c:119
int errno
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 2686 of file logger.c.

2687 {
2688  return AST_MODULE_LOAD_SUCCESS;
2689 }
@ AST_MODULE_LOAD_SUCCESS
Definition: module.h:70

◆ logger_add_verbose_magic()

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

Definition at line 335 of file logger.c.

336 {
337  const char *p;
338  const char *fmt;
339  struct ast_str *prefixed;
340  signed char magic = logmsg->sublevel > 9 ? -10 : -logmsg->sublevel - 1; /* 0 => -1, 1 => -2, etc. Can't pass NUL, as it is EOS-delimiter */
341 
342  /* For compatibility with modules still calling ast_verbose() directly instead of using ast_verb() */
343  if (logmsg->sublevel < 0) {
344  if (!strncmp(logmsg->message, VERBOSE_PREFIX_4, strlen(VERBOSE_PREFIX_4))) {
345  magic = -5;
346  } else if (!strncmp(logmsg->message, VERBOSE_PREFIX_3, strlen(VERBOSE_PREFIX_3))) {
347  magic = -4;
348  } else if (!strncmp(logmsg->message, VERBOSE_PREFIX_2, strlen(VERBOSE_PREFIX_2))) {
349  magic = -3;
350  } else if (!strncmp(logmsg->message, VERBOSE_PREFIX_1, strlen(VERBOSE_PREFIX_1))) {
351  magic = -2;
352  } else {
353  magic = -1;
354  }
355  }
356 
358  return -1;
359  }
360 
361  ast_str_reset(prefixed);
362 
363  /* for every newline found in the buffer add verbose prefix data */
364  fmt = logmsg->message;
365  do {
366  if (!(p = strchr(fmt, '\n'))) {
367  p = strchr(fmt, '\0') - 1;
368  }
369  ++p;
370 
371  ast_str_append(&prefixed, 0, "%c", (char)magic);
372  ast_str_append_substr(&prefixed, 0, fmt, p - fmt);
373  fmt = p;
374  } while (p && *p);
375 
376  snprintf(buf, size, "%s", ast_str_buffer(prefixed));
377 
378  return 0;
379 }
#define VERBOSE_PREFIX_3
#define VERBOSE_PREFIX_2
#define VERBOSE_PREFIX_4
#define VERBOSE_PREFIX_1
static struct ast_threadstorage verbose_buf
Definition: logger.c:268
#define VERBOSE_BUF_INIT_SIZE
Definition: logger.c:270
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:1040

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_2, VERBOSE_PREFIX_3, and VERBOSE_PREFIX_4.

Referenced by format_log_default().

◆ logger_get_dynamic_level()

static int logger_get_dynamic_level ( const char *  name)
static

Definition at line 2596 of file logger.c.

2597 {
2598  int level = -1;
2599  unsigned int x;
2600 
2601  for (x = 16; x < ARRAY_LEN(levels); x++) {
2602  if (!levels[x]) {
2603  continue;
2604  }
2605  if (!strcasecmp(levels[x], name)) {
2606  level = x;
2607  break;
2608  }
2609  }
2610 
2611  return level;
2612 }

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

1671 {
1672  struct logchannel *chan = NULL;
1673  char buf[LOGMSG_SIZE];
1674  int level = 0;
1675 
1677  if (!AST_RWLIST_EMPTY(&logchannels)) {
1679 
1680  /* If the channel is disabled, then move on to the next one */
1681  if (chan->disabled) {
1682  continue;
1683  }
1684  if (logmsg->level == __LOG_VERBOSE
1685  && (((chan->verbosity < 0) ? option_verbose : chan->verbosity)) < level) {
1686  continue;
1687  }
1688 
1689  if (!(chan->logmask & (1 << logmsg->level))) {
1690  continue;
1691  }
1692 
1693  switch (chan->type) {
1694  case LOGTYPE_SYSLOG:
1695  {
1696  int syslog_level = ast_syslog_priority_from_loglevel(logmsg->level);
1697 
1698  if (syslog_level < 0) {
1699  /* we are locked here, so cannot ast_log() */
1700  fprintf(stderr, "ast_log_vsyslog called with bogus level: %d\n", logmsg->level);
1701  continue;
1702  }
1703 
1704  /* Don't use LOG_MAKEPRI because it's broken in glibc<2.17 */
1705  syslog_level = chan->facility | syslog_level; /* LOG_MAKEPRI(chan->facility, syslog_level); */
1706  if (!chan->formatter.format_log(chan, logmsg, buf, sizeof(buf))) {
1707  syslog(syslog_level, "%s", buf);
1708  }
1709  }
1710  break;
1711  case LOGTYPE_CONSOLE:
1712  if (!chan->formatter.format_log(chan, logmsg, buf, sizeof(buf))) {
1714  }
1715  break;
1716  case LOGTYPE_FILE:
1717  {
1718  int res = 0;
1719 
1720  if (!chan->fileptr) {
1721  continue;
1722  }
1723 
1724  if (chan->formatter.format_log(chan, logmsg, buf, sizeof(buf))) {
1725  continue;
1726  }
1727 
1728  /* Print out to the file */
1729  res = fprintf(chan->fileptr, "%s", buf);
1730  if (res > 0) {
1731  fflush(chan->fileptr);
1732  } else if (res <= 0 && !ast_strlen_zero(logmsg->message)) {
1733  fprintf(stderr, "**** Asterisk Logging Error: ***********\n");
1734  if (errno == ENOMEM || errno == ENOSPC) {
1735  fprintf(stderr, "Asterisk logging error: Out of disk space, can't log to log file %s\n", chan->filename);
1736  } else {
1737  fprintf(stderr, "Logger Warning: Unable to write to log file '%s': %s (disabled)\n", chan->filename, strerror(errno));
1738  }
1739 
1740  /*** DOCUMENTATION
1741  <managerEventInstance>
1742  <synopsis>Raised when a logging channel is disabled.</synopsis>
1743  <syntax>
1744  <parameter name="Channel">
1745  <para>The name of the logging channel.</para>
1746  </parameter>
1747  </syntax>
1748  </managerEventInstance>
1749  ***/
1750  manager_event(EVENT_FLAG_SYSTEM, "LogChannel", "Channel: %s\r\nEnabled: No\r\nReason: %d - %s\r\n", chan->filename, errno, strerror(errno));
1751  chan->disabled = 1;
1752  }
1753  }
1754  break;
1755  }
1756  }
1757  } else if (logmsg->level != __LOG_VERBOSE || option_verbose >= logmsg->sublevel) {
1758  fputs(logmsg->message, stdout);
1759  }
1760 
1762 
1763  /* If we need to reload because of the file size, then do so */
1764  if (filesize_reload_needed) {
1765  reload_logger(-1, NULL);
1766  ast_verb(1, "Rotated Logs Per SIGXFSZ (Exceeded file size limit)\n");
1767  }
1768 
1769  return;
1770 }
#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:1317
#define AST_RWLIST_EMPTY
Definition: linkedlists.h:452
int facility
Definition: logger.c:146
int(*const format_log)(struct logchannel *channel, struct logmsg *msg, char *buf, size_t size)
Definition: logger.c:129
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::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 1905 of file logger.c.

1906 {
1907  ast_unload_realtime("queue_log");
1908  if (logfiles.queue_log) {
1909  char qfname[PATH_MAX];
1910 
1911  if (logger_queue_rt_start()) {
1912  return;
1913  }
1914 
1915  /* Open the log file. */
1916  snprintf(qfname, sizeof(qfname), "%s/%s", ast_config_AST_LOG_DIR,
1917  queue_log_name);
1918  if (qlog) {
1919  /* Just in case it was already open. */
1920  fclose(qlog);
1921  }
1922  qlog = fopen(qfname, "a");
1923  if (!qlog) {
1924  ast_log(LOG_ERROR, "Unable to create queue log: %s\n", strerror(errno));
1925  }
1926  }
1927 }
int ast_unload_realtime(const char *family)
Release any resources cached for a realtime family.
Definition: main/config.c:3475
static int logger_queue_rt_start(void)
Definition: logger.c:1136

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

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

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

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

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

1941 {
1942  /* Must not be called before the logger is initialized. */
1944 
1946  if (!queuelog_init) {
1948  queuelog_init = 1;
1950  ast_queue_log("NONE", "NONE", "NONE", "QUEUESTART", "%s", "");
1951  } else {
1953  }
1954 }
void ast_queue_log(const char *queuename, const char *callid, const char *agent, const char *event, const char *fmt,...)
Definition: logger.c:952
static void logger_queue_init(void)
Definition: logger.c:1905
#define ast_assert(a)
Definition: utils.h:734

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

2549 {
2550  unsigned int level;
2551  unsigned int available = 0;
2552 
2553  for (level = 0; level < ARRAY_LEN(levels); level++) {
2554  if ((level >= 16) && !available && !levels[level]) {
2555  available = level;
2556  continue;
2557  }
2558 
2559  if (levels[level] && !strcasecmp(levels[level], name)) {
2561  "Unable to register dynamic logger level '%s': a standard logger level uses that name.\n",
2562  name);
2563 
2564  return -1;
2565  }
2566  }
2567 
2568  if (!available) {
2570  "Unable to register dynamic logger level '%s'; maximum number of levels registered.\n",
2571  name);
2572 
2573  return -1;
2574  }
2575 
2577 
2578  ast_debug(1, "Registered dynamic logger level '%s' with index %u.\n", name, available);
2579 
2581 
2582  return available;
2583 }

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

1852 {
1853  struct logmsg *next = NULL, *msg = NULL;
1854 
1855  for (;;) {
1856  /* We lock the message list, and see if any message exists... if not we wait on the condition to be signalled */
1858  if (AST_LIST_EMPTY(&logmsgs)) {
1859  if (close_logger_thread) {
1861  break;
1862  } else {
1864  }
1865  }
1866 
1867  if (high_water_alert) {
1868  msg = format_log_message(__LOG_WARNING, 0, "logger", 0, "***", 0,
1869  "Logging resumed. %d message%s discarded.\n",
1871  if (msg) {
1873  }
1874  high_water_alert = 0;
1876  }
1877 
1880  logger_queue_size = 0;
1882 
1883  /* Otherwise go through and process each message in the order added */
1884  while ((msg = next)) {
1885  /* Get the next entry now so that we can free our current structure later */
1886  next = AST_LIST_NEXT(msg, list);
1887 
1888  /* Depending on the type, send it to the proper function */
1889  logger_print_normal(msg);
1890 
1891  /* Free the data since we are done */
1892  logmsg_free(msg);
1893  }
1894  }
1895 
1896  return NULL;
1897 }
#define AST_LIST_HEAD_INIT_NOLOCK(head)
Initializes a list head structure.
Definition: linkedlists.h:681
#define AST_LIST_EMPTY(head)
Checks whether the specified list contains any entries.
Definition: linkedlists.h:450
#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:203
struct logmsg * next
Definition: logger.c:186

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

2627  {
2628  unsigned int x;
2629 
2631  if (x == -1) {
2632  return 0;
2633  }
2634  /* take this level out of the global_logmask, to ensure that no new log messages
2635  * will be queued for it
2636  */
2637  global_logmask &= ~(1 << x);
2638  ast_free(levels[x]);
2639  levels[x] = NULL;
2640  return x;
2641 }

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

190 {
192  ast_free(msg);
193 }
#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 495 of file logger.c.

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

577 {
578  const char *log_dir_prefix = "";
579  const char *log_dir_separator = "";
580 
581  *filename = '\0';
582 
583  if (!strcasecmp(channel, "console")) {
584  return;
585  }
586 
587  if (!strncasecmp(channel, "syslog", 6)) {
588  ast_copy_string(filename, channel, size);
589  return;
590  }
591 
592  /* It's a filename */
593 
594  if (channel[0] != '/') {
595  log_dir_prefix = ast_config_AST_LOG_DIR;
596  log_dir_separator = "/";
597  }
598 
599  if (!ast_strlen_zero(hostname)) {
600  snprintf(filename, size, "%s%s%s.%s",
601  log_dir_prefix, log_dir_separator, channel, hostname);
602  } else {
603  snprintf(filename, size, "%s%s%s",
604  log_dir_prefix, log_dir_separator, channel);
605  }
606 }

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

634 {
635  struct logchannel *chan;
636  char *facility;
637  struct ast_tm tm;
638  struct timeval now = ast_tvnow();
639  char datestring[256];
640 
641  if (ast_strlen_zero(channel) || !(chan = ast_calloc(1, sizeof(*chan) + strlen(components) + 1)))
642  return NULL;
643 
644  strcpy(chan->components, components);
645  chan->lineno = lineno;
646  chan->dynamic = dynamic;
647 
648  make_filename(channel, chan->filename, sizeof(chan->filename));
649 
650  if (!strcasecmp(channel, "console")) {
651  chan->type = LOGTYPE_CONSOLE;
652  } else if (!strncasecmp(channel, "syslog", 6)) {
653  /*
654  * syntax is:
655  * syslog.facility => level,level,level
656  */
657  facility = strchr(channel, '.');
658  if (!facility++ || !facility) {
659  facility = "local0";
660  }
661 
662  chan->facility = ast_syslog_facility(facility);
663 
664  if (chan->facility < 0) {
665  fprintf(stderr, "Logger Warning: bad syslog facility in logger.conf\n");
666  ast_free(chan);
667  return NULL;
668  }
669 
670  chan->type = LOGTYPE_SYSLOG;
671  openlog("asterisk", LOG_PID, chan->facility);
672  } else {
673  if (!(chan->fileptr = fopen(chan->filename, "a"))) {
674  /* Can't do real logging here since we're called with a lock
675  * so log to any attached consoles */
676  ast_console_puts_mutable("ERROR: Unable to open log file '", __LOG_ERROR);
681  ast_free(chan);
682  return NULL;
683  } else {
684  /* Create our date/time */
685  ast_localtime(&now, &tm, NULL);
686  ast_strftime(datestring, sizeof(datestring), dateformat, &tm);
687 
688  fprintf(chan->fileptr, "[%s] Asterisk %s built by %s @ %s on a %s running %s on %s\n",
691  fflush(chan->fileptr);
692  }
693  chan->type = LOGTYPE_FILE;
694  }
695  make_components(chan);
696 
697  return chan;
698 }
const char * ast_get_version(void)
Retrieve the Asterisk version string.
#define ast_calloc(num, len)
A wrapper for calloc()
Definition: astmm.h:202
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:495
int lineno
Definition: logger.c:158
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 1199 of file logger.c.

1200 {
1201  int queue_rotate = rotate;
1202  struct logchannel *f;
1203  int res = 0;
1204 
1206 
1207  if (qlog) {
1208  if (rotate < 0) {
1209  /* Check filesize - this one typically doesn't need an auto-rotate */
1210  if (ftello(qlog) > 0x40000000) { /* Arbitrarily, 1 GB */
1211  fclose(qlog);
1212  qlog = NULL;
1213  } else {
1214  queue_rotate = 0;
1215  }
1216  } else {
1217  fclose(qlog);
1218  qlog = NULL;
1219  }
1220  } else {
1221  queue_rotate = 0;
1222  }
1223 
1225 
1227  if (f->disabled) {
1228  f->disabled = 0; /* Re-enable logging at reload */
1229  /*** DOCUMENTATION
1230  <managerEvent language="en_US" name="LogChannel">
1231  <managerEventInstance class="EVENT_FLAG_SYSTEM">
1232  <synopsis>Raised when a logging channel is re-enabled after a reload operation.</synopsis>
1233  <syntax>
1234  <parameter name="Channel">
1235  <para>The name of the logging channel.</para>
1236  </parameter>
1237  </syntax>
1238  </managerEventInstance>
1239  </managerEvent>
1240  ***/
1241  manager_event(EVENT_FLAG_SYSTEM, "LogChannel", "Channel: %s\r\nEnabled: Yes\r\n", f->filename);
1242  }
1243  if (f->fileptr && (f->fileptr != stdout) && (f->fileptr != stderr)) {
1244  int rotate_this = 0;
1245  if (rotatestrategy != NONE && ftello(f->fileptr) > 0x40000000) { /* Arbitrarily, 1 GB */
1246  /* Be more proactive about rotating massive log files */
1247  rotate_this = 1;
1248  }
1249  fclose(f->fileptr); /* Close file */
1250  f->fileptr = NULL;
1251  if (rotate || rotate_this) {
1252  rotate_file(f->filename);
1253  }
1254  }
1255  }
1256 
1258 
1259  init_logger_chain(altconf);
1260 
1261  ast_unload_realtime("queue_log");
1262  if (logfiles.queue_log) {
1263  res = logger_queue_restart(queue_rotate);
1265  ast_verb_update();
1266  ast_queue_log("NONE", "NONE", "NONE", "CONFIGRELOAD", "%s", "");
1267  ast_verb(1, "Asterisk Queue Logger restarted\n");
1268  } else {
1270  ast_verb_update();
1271  }
1272 
1273  return res;
1274 }
static int logger_queue_restart(int queue_rotate)
Definition: logger.c:1171

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

2677 {
2678  return reload_logger(0, NULL);
2679 }

References NULL, and reload_logger().

◆ rotate_file()

static int rotate_file ( const char *  filename)
static

Definition at line 1032 of file logger.c.

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

2682 {
2683  return 0;
2684 }

◆ update_logchannels()

static void update_logchannels ( void  )
static

Definition at line 2444 of file logger.c.

2445 {
2446  struct logchannel *cur;
2447 
2448  global_logmask = 0;
2449 
2451  make_components(cur);
2452  global_logmask |= cur->logmask;
2453  }
2454 }

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

2370 {
2371  struct verb_console *console = v_console;
2372 
2374  ast_free(console);
2375 }

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

◆ ast_module_info

const struct ast_module_info* ast_module_info = &__mod_info
static

Definition at line 2699 of file logger.c.

◆ cli_logger

struct ast_cli_entry cli_logger[]
static

Definition at line 1599 of file logger.c.

Referenced by close_logger(), and init_logger().

◆ close_logger_thread

int close_logger_thread = 0
static

Definition at line 198 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 233 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 230 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 91 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 84 of file logger.c.

Referenced by init_logger_chain(), and rotate_file().

◆ filesize_reload_needed

int filesize_reload_needed
static

Definition at line 86 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:1658

Definition at line 1658 of file logger.c.

Referenced by init_logger().

◆ high_water_alert

unsigned int high_water_alert
static

Definition at line 98 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 213 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 272 of file logger.c.

Referenced by format_log_message_ap().

◆ 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 197 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:381

Definition at line 381 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:275

Definition at line 275 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:445

Definition at line 445 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 97 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 95 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 196 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 90 of file logger.c.

Referenced by ast_create_callid().

◆ qlog

FILE* qlog
static

◆ queue_adaptive_realtime

unsigned int queue_adaptive_realtime

Definition at line 115 of file logger.c.

◆ queue_log

unsigned int queue_log

Definition at line 113 of file logger.c.

◆ queue_log_name

char queue_log_name[256] = QUEUELOG
static

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

◆ queue_log_to_file

unsigned int queue_log_to_file

Definition at line 114 of file logger.c.

◆ queuelog_init

int queuelog_init
static

Definition at line 88 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 2316 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 268 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 269 of file logger.c.