Asterisk - The Open Source Telephony Project  GIT-master-09303e8
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"

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 LOG_BUF_INIT_SIZE   256
 
#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_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 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...
 
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 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 void * logger_thread (void *data)
 Actual logging thread. More...
 
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 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 "

◆ LOG_BUF_INIT_SIZE

#define LOG_BUF_INIT_SIZE   256

Definition at line 255 of file logger.c.

Referenced by format_log_message_ap().

◆ VERBOSE_BUF_INIT_SIZE

#define VERBOSE_BUF_INIT_SIZE   256

Definition at line 252 of file logger.c.

Referenced by logger_add_verbose_magic().

Enumeration Type Documentation

◆ logmsgtypes

Enumerator
LOGMSG_NORMAL 
LOGMSG_VERBOSE 

Definition at line 158 of file logger.c.

158  {
159  LOGMSG_NORMAL = 0,
161 };

◆ logtypes

enum logtypes
Enumerator
LOGTYPE_SYSLOG 
LOGTYPE_FILE 
LOGTYPE_CONSOLE 

Definition at line 123 of file logger.c.

123  {
125  LOGTYPE_FILE,
127 };

◆ rotatestrategy

Enumerator
NONE 
SEQUENTIAL 
ROTATE 
TIMESTAMP 

Definition at line 96 of file logger.c.

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

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

References __ast_verbose_ap(), and ast_read_threadstorage_callid().

2186 {
2187  ast_callid callid;
2188  va_list ap;
2189 
2190  callid = ast_read_threadstorage_callid();
2191 
2192  va_start(ap, fmt);
2193  __ast_verbose_ap(file, line, func, level, callid, fmt, ap);
2194  va_end(ap);
2195 }
unsigned int ast_callid
Definition: logger.h:87
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:2180
ast_callid ast_read_threadstorage_callid(void)
extracts the callerid from the thread
Definition: logger.c:1949

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

References __LOG_VERBOSE, and ast_log_full().

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

2181 {
2182  ast_log_full(__LOG_VERBOSE, level, file, line, func, callid, fmt, ap);
2183 }
#define __LOG_VERBOSE
Definition: logger.h:295
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:2040

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

References __ast_verbose_ap().

2198 {
2199  va_list ap;
2200  va_start(ap, fmt);
2201  __ast_verbose_ap(file, line, func, level, callid, fmt, ap);
2202  va_end(ap);
2203 }
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:2180

◆ __init_log_buf()

static void __init_log_buf ( void  )
static

Definition at line 254 of file logger.c.

258 {

◆ __init_my_verb_console()

static void __init_my_verb_console ( void  )
static

Thread specific console verbosity level node.

Definition at line 2281 of file logger.c.

2284 {

◆ __init_unique_callid()

static void __init_unique_callid ( void  )
static

Definition at line 89 of file logger.c.

96 {

◆ __init_verbose_buf()

static void __init_verbose_buf ( void  )
static

Definition at line 250 of file logger.c.

258 {

◆ __init_verbose_build_buf()

static void __init_verbose_build_buf ( void  )
static

Definition at line 251 of file logger.c.

258 {

◆ __reg_module()

static void __reg_module ( void  )
static

Definition at line 2575 of file logger.c.

◆ __unreg_module()

static void __unreg_module ( void  )
static

Definition at line 2575 of file logger.c.

◆ _handle_SIGXFSZ()

static void _handle_SIGXFSZ ( int  sig)
static

Definition at line 1555 of file logger.c.

References filesize_reload_needed.

1556 {
1557  /* Indicate need to reload */
1559 }
static int filesize_reload_needed
Definition: logger.c:82

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

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

1940 {
1941  snprintf(buffer, buffer_size, "[C-%08x]", callid);
1942 }

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

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

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

1972 {
1973  ast_callid *pointing;
1974 
1975  pointing = ast_threadstorage_get(&unique_callid, sizeof(*pointing));
1976  if (!pointing) {
1977  return -1;
1978  }
1979 
1980  if (*pointing) {
1981  ast_log(LOG_ERROR, "ast_callid_threadassoc_add(C-%08x) on thread "
1982  "already associated with callid [C-%08x].\n", callid, *pointing);
1983  return 1;
1984  }
1985 
1986  *pointing = callid;
1987  return 0;
1988 }
void * ast_threadstorage_get(struct ast_threadstorage *ts, size_t init_size)
Retrieve thread storage.
unsigned int ast_callid
Definition: logger.h:87
static struct ast_threadstorage unique_callid
Definition: logger.c:89
#define LOG_ERROR
Definition: logger.h:285
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:2088

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

References ast_threadstorage_get(), and unique_callid.

Referenced by autoservice_run(), and bridge_manager_service().

1959 {
1960  ast_callid *id = ast_threadstorage_get(&unique_callid, sizeof(*id));
1961 
1962  if (!id) {
1963  return -1;
1964  }
1965 
1966  *id = callid;
1967 
1968  return 0;
1969 }
void * ast_threadstorage_get(struct ast_threadstorage *ts, size_t init_size)
Retrieve thread storage.
unsigned int ast_callid
Definition: logger.h:87
static struct ast_threadstorage unique_callid
Definition: logger.c:89

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

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

1991 {
1992  ast_callid *pointing;
1993 
1994  pointing = ast_threadstorage_get(&unique_callid, sizeof(*pointing));
1995  if (!pointing) {
1996  return -1;
1997  }
1998 
1999  if (*pointing) {
2000  *pointing = 0;
2001  return 0;
2002  }
2003 
2004  return -1;
2005 }
void * ast_threadstorage_get(struct ast_threadstorage *ts, size_t init_size)
Retrieve thread storage.
unsigned int ast_callid
Definition: logger.h:87
static struct ast_threadstorage unique_callid
Definition: logger.c:89

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

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_clear_alarms(), handle_init_event(), mwi_thread(), my_new_analog_ast_channel(), and my_on_hook().

2008 {
2009  ast_callid tmp;
2010 
2011  /* Start by trying to see if a callid is available from thread storage */
2013  if (tmp) {
2014  *callid = tmp;
2015  return 0;
2016  }
2017 
2018  /* If that failed, try to create a new one and bind it. */
2019  *callid = ast_create_callid();
2020  if (*callid) {
2021  ast_callid_threadassoc_add(*callid);
2022  return 1;
2023  }
2024 
2025  /* If neither worked, then something must have gone wrong. */
2026  return -1;
2027 }
static int tmp()
Definition: bt_open.c:389
unsigned int ast_callid
Definition: logger.h:87
ast_callid ast_read_threadstorage_callid(void)
extracts the callerid from the thread
Definition: logger.c:1949
int ast_callid_threadassoc_add(ast_callid callid)
Adds a known callid to thread storage of the calling thread.
Definition: logger.c:1971
ast_callid ast_create_callid(void)
factory function to create a new uniquely identifying callid.
Definition: logger.c:1944

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

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_clear_alarms(), handle_init_event(), and mwi_thread().

2030 {
2031  if (callid && callid_created) {
2032  /* If the callid was created rather than simply grabbed from the thread storage, we need to unbind here. */
2034  }
2035 }
int ast_callid_threadassoc_remove(void)
Removes callid from thread storage of the calling thread.
Definition: logger.c:1990

◆ ast_child_verbose()

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

Definition at line 837 of file logger.c.

References ast_free, ast_malloc, and NULL.

Referenced by launch_script().

838 {
839  char *msg = NULL, *emsg = NULL, *sptr, *eptr;
840  va_list ap, aq;
841  int size;
842 
843  va_start(ap, fmt);
844  va_copy(aq, ap);
845  if ((size = vsnprintf(msg, 0, fmt, ap)) < 0) {
846  va_end(ap);
847  va_end(aq);
848  return;
849  }
850  va_end(ap);
851 
852  if (!(msg = ast_malloc(size + 1))) {
853  va_end(aq);
854  return;
855  }
856 
857  vsnprintf(msg, size + 1, fmt, aq);
858  va_end(aq);
859 
860  if (!(emsg = ast_malloc(size * 2 + 1))) {
861  ast_free(msg);
862  return;
863  }
864 
865  for (sptr = msg, eptr = emsg; ; sptr++) {
866  if (*sptr == '"') {
867  *eptr++ = '\\';
868  }
869  *eptr++ = *sptr;
870  if (*sptr == '\0') {
871  break;
872  }
873  }
874  ast_free(msg);
875 
876  fprintf(stdout, "verbose \"%s\" %d\n", emsg, level);
877  fflush(stdout);
878  ast_free(emsg);
879 }
#define NULL
Definition: resample.c:96
#define ast_malloc(len)
A wrapper for malloc()
Definition: astmm.h:193
#define ast_free(a)
Definition: astmm.h:182

◆ ast_create_callid()

ast_callid ast_create_callid ( void  )

factory function to create a new uniquely identifying callid.

Return values
Thecall id

Definition at line 1944 of file logger.c.

References ast_atomic_fetchadd_int(), and next_unique_callid.

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

1945 {
1947 }
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:86

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

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

Referenced by ast_remotecontrol().

683 {
684  struct ast_config *cfg;
685  const char *s;
686  struct ast_flags config_flags = { 0 };
687 
688  if (!(cfg = ast_config_load2("logger.conf", "logger", config_flags)) || cfg == CONFIG_STATUS_FILEINVALID) {
689  return;
690  }
691 
692  if ((s = ast_variable_retrieve(cfg, "general", "dateformat"))) {
694  }
695 
696  ast_config_destroy(cfg);
697 }
#define CONFIG_STATUS_FILEINVALID
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:3154
void ast_config_destroy(struct ast_config *config)
Destroys a config.
Definition: extconf.c:1290
Structure used to handle boolean flags.
Definition: utils.h:199
const char * ast_variable_retrieve(struct ast_config *config, const char *category, const char *variable)
Definition: main/config.c:694
static char dateformat[256]
Definition: logger.c:77
void ast_copy_string(char *dst, const char *src, size_t size)
Size-limited null-terminating string copy.
Definition: strings.h:401

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

References logger_initialized.

Referenced by check_init().

1829 {
1830  return logger_initialized;
1831 }
static int logger_initialized
Definition: logger.c:85

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

References ast_log_ap().

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

2089 {
2090  va_list ap;
2091 
2092  va_start(ap, fmt);
2093  ast_log_ap(level, file, line, function, fmt, ap);
2094  va_end(ap);
2095 }
void ast_log_ap(int level, const char *file, int line, const char *function, const char *fmt, va_list ap)
Definition: logger.c:2097

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

References __ast_verbose_ap(), __LOG_VERBOSE, ast_log_full(), ast_read_threadstorage_callid(), and logmsg::callid.

Referenced by ast_log(), and module_load_error().

2098 {
2099  ast_callid callid;
2100 
2101  callid = ast_read_threadstorage_callid();
2102 
2103  if (level == __LOG_VERBOSE) {
2104  __ast_verbose_ap(file, line, function, 0, callid, fmt, ap);
2105  } else {
2106  ast_log_full(level, -1, file, line, function, callid, fmt, ap);
2107  }
2108 }
unsigned int ast_callid
Definition: logger.h:87
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:2180
ast_callid ast_read_threadstorage_callid(void)
extracts the callerid from the thread
Definition: logger.c:1949
#define __LOG_VERBOSE
Definition: logger.h:295
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:2040

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

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

2146 {
2147 #ifdef HAVE_BKTR
2148  struct ast_bt *bt;
2149  int i = 0;
2150  struct ast_vector_string *strings;
2151 
2152  if (!(bt = ast_bt_create())) {
2153  ast_log(LOG_WARNING, "Unable to allocate space for backtrace structure\n");
2154  return;
2155  }
2156 
2157  if ((strings = ast_bt_get_symbols(bt->addresses, bt->num_frames))) {
2158  int count = AST_VECTOR_SIZE(strings);
2159  struct ast_str *buf = ast_str_create(bt->num_frames * 64);
2160 
2161  if (buf) {
2162  ast_str_append(&buf, 0, "Got %d backtrace record%c\n", count - 3, count - 3 != 1 ? 's' : ' ');
2163  for (i = 3; i < AST_VECTOR_SIZE(strings); i++) {
2164  ast_str_append(&buf, 0, "#%2d: %s\n", i - 3, AST_VECTOR_GET(strings, i));
2165  }
2166  ast_log_safe(__LOG_ERROR, NULL, 0, NULL, "%s\n", ast_str_buffer(buf));
2167  ast_free(buf);
2168  }
2169 
2170  ast_bt_free_symbols(strings);
2171  } else {
2172  ast_log(LOG_ERROR, "Could not allocate memory for backtrace\n");
2173  }
2174  ast_bt_destroy(bt);
2175 #else
2176  ast_log(LOG_WARNING, "Must run configure with '--with-execinfo' for stack backtraces.\n");
2177 #endif /* defined(HAVE_BKTR) */
2178 }
#define ast_bt_free_symbols(string_vector)
Definition: backtrace.h:42
char buf[BUFSIZE]
Definition: eagi_proxy.c:66
#define LOG_WARNING
Definition: logger.h:274
char * ast_str_buffer(const struct ast_str *buf)
Returns the string buffer within the ast_str buf.
Definition: strings.h:714
#define ast_bt_get_symbols(addresses, num_frames)
Definition: backtrace.h:41
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:1091
#define ast_bt_destroy(bt)
Definition: backtrace.h:40
#define __LOG_ERROR
Definition: logger.h:284
#define NULL
Definition: resample.c:96
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:2110
#define LOG_ERROR
Definition: logger.h:285
The descriptor of a dynamic string XXX storage will be optimized later if needed We use the ts field ...
Definition: strings.h:584
#define ast_bt_create()
Definition: backtrace.h:39
#define ast_free(a)
Definition: astmm.h:182
void * addresses[AST_MAX_BT_FRAMES]
Definition: backtrace.h:52
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:2088
#define AST_VECTOR_GET(vec, idx)
Get an element from a vector.
Definition: vector.h:682
int num_frames
Definition: backtrace.h:54
#define AST_VECTOR_SIZE(vec)
Get the number of elements in a vector.
Definition: vector.h:611
#define ast_str_create(init_len)
Create a malloc&#39;ed dynamic length string.
Definition: strings.h:620

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

References ast_log_full().

Referenced by ast_channel_destructor(), and dahdi_cc_callback().

2137 {
2138  va_list ap;
2139  va_start(ap, fmt);
2140  ast_log_full(level, -1, file, line, function, callid, fmt, ap);
2141  va_end(ap);
2142 }
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:2040

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

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, format_log_message(), format_log_message_ap(), high_water_alert, logmsg::list, logger_messages_discarded, logger_print_normal(), logger_queue_limit, logger_queue_size, logmsg_free(), and NULL.

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

2043 {
2044  struct logmsg *logmsg = NULL;
2045 
2047  return;
2048  }
2049 
2054  logmsg = format_log_message(__LOG_WARNING, 0, "logger", 0, "***", 0,
2055  "Log queue threshold (%d) exceeded. Discarding new messages.\n", logger_queue_limit);
2056  AST_LIST_INSERT_TAIL(&logmsgs, logmsg, list);
2057  high_water_alert = 1;
2059  }
2061  return;
2062  }
2064 
2065  logmsg = format_log_message_ap(level, sublevel, file, line, function, callid, fmt, ap);
2066  if (!logmsg) {
2067  return;
2068  }
2069 
2070  /* If the logger thread is active, append it to the tail end of the list - otherwise skip that step */
2071  if (logthread != AST_PTHREADT_NULL) {
2073  if (close_logger_thread) {
2074  /* Logger is either closing or closed. We cannot log this message. */
2075  logmsg_free(logmsg);
2076  } else {
2077  AST_LIST_INSERT_TAIL(&logmsgs, logmsg, list);
2080  }
2082  } else {
2083  logger_print_normal(logmsg);
2084  logmsg_free(logmsg);
2085  }
2086 }
static void logger_print_normal(struct logmsg *logmsg)
Print a normal log message to the channels.
Definition: logger.c:1567
int line
Definition: logger.c:167
#define AST_LIST_LOCK(head)
Locks a list.
Definition: linkedlists.h:39
static pthread_t logthread
Definition: logger.c:187
static void logmsg_free(struct logmsg *msg)
Definition: logger.c:180
ast_callid callid
Definition: logger.c:169
#define AST_LIST_UNLOCK(head)
Attempts to unlock a list.
Definition: linkedlists.h:139
struct logmsg::@399 list
#define __LOG_WARNING
Definition: logger.h:273
#define NULL
Definition: resample.c:96
#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:1733
Definition: logger.c:163
static unsigned int high_water_alert
Definition: logger.c:94
#define AST_PTHREADT_NULL
Definition: lock.h:66
int level
Definition: logger.c:165
#define AST_LIST_INSERT_TAIL(head, elm, field)
Appends a list entry to the tail of a list.
Definition: linkedlists.h:730
#define ast_opt_remote
Definition: options.h:112
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:1669
#define ast_opt_exec
Definition: options.h:113
#define __LOG_VERBOSE
Definition: logger.h:295
static int logger_queue_size
Definition: logger.c:89
static int close_logger_thread
Definition: logger.c:189
static int logger_queue_limit
Definition: logger.c:92
static int logger_messages_discarded
Definition: logger.c:93
static ast_cond_t logcond
Definition: logger.c:188
int sublevel
Definition: logger.c:166

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

References ast_log_full(), ast_read_threadstorage_callid(), ast_threadstorage_get_ptr(), ast_threadstorage_set_ptr(), logmsg::callid, and NULL.

Referenced by __ast_str_helper(), and ast_log_backtrace().

2111 {
2112  va_list ap;
2113  void *recursed = ast_threadstorage_get_ptr(&in_safe_log);
2115 
2116  if (recursed) {
2117  return;
2118  }
2119 
2120  if (ast_threadstorage_set_ptr(&in_safe_log, (void*)1)) {
2121  /* We've failed to set the flag that protects against
2122  * recursion, so bail. */
2123  return;
2124  }
2125 
2126  callid = ast_read_threadstorage_callid();
2127 
2128  va_start(ap, fmt);
2129  ast_log_full(level, -1, file, line, function, callid, fmt, ap);
2130  va_end(ap);
2131 
2132  /* Clear flag so the next allocation failure can be logged. */
2133  ast_threadstorage_set_ptr(&in_safe_log, NULL);
2134 }
int line
Definition: logger.c:167
ast_callid callid
Definition: logger.c:169
unsigned int ast_callid
Definition: logger.h:87
#define NULL
Definition: resample.c:96
int ast_threadstorage_set_ptr(struct ast_threadstorage *ts, void *ptr)
Set a raw pointer from threadstorage.
int level
Definition: logger.c:165
ast_callid ast_read_threadstorage_callid(void)
extracts the callerid from the thread
Definition: logger.c:1949
void * ast_threadstorage_get_ptr(struct ast_threadstorage *ts)
Retrieve a raw pointer from threadstorage.
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:2040

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

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, find_logchannel(), global_logmask, logchannel::list, logchannel::logmask, and make_logchannel().

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

1407 {
1408  struct logchannel *chan;
1409 
1410  if (ast_strlen_zero(components)) {
1411  return AST_LOGGER_DECLINE;
1412  }
1413 
1415 
1416  chan = find_logchannel(log_channel);
1417  if (chan) {
1419  return AST_LOGGER_FAILURE;
1420  }
1421 
1422  chan = make_logchannel(log_channel, components, 0, 1);
1423  if (!chan) {
1425  return AST_LOGGER_ALLOC_ERROR;
1426  }
1427 
1429  global_logmask |= chan->logmask;
1430 
1432 
1433  return AST_LOGGER_SUCCESS;
1434 }
static unsigned int global_logmask
Definition: logger.c:83
#define AST_RWLIST_WRLOCK(head)
Write locks a list.
Definition: linkedlists.h:51
char components[0]
Definition: logger.c:153
#define AST_RWLIST_UNLOCK(head)
Attempts to unlock a read/write based list.
Definition: linkedlists.h:150
#define AST_RWLIST_INSERT_HEAD
Definition: linkedlists.h:717
unsigned int logmask
Definition: logger.c:133
static struct logchannel * make_logchannel(const char *channel, const char *components, int lineno, int dynamic)
Definition: logger.c:615
static struct logchannel * find_logchannel(const char *channel)
Find a particular logger channel by name.
Definition: logger.c:599
#define ast_strlen_zero(a)
Definition: muted.c:73
struct logchannel::@398 list

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

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, logchannel::logmask, LOGTYPE_CONSOLE, LOGTYPE_SYSLOG, NULL, and logchannel::type.

Referenced by ast_ari_asterisk_list_log_channels().

1325 {
1326  struct logchannel *chan;
1327  struct ast_str *configs = ast_str_create(64);
1328  int res = AST_LOGGER_SUCCESS;
1329 
1330  if (!configs) {
1331  return AST_LOGGER_ALLOC_ERROR;
1332  }
1333 
1335  AST_RWLIST_TRAVERSE(&logchannels, chan, list) {
1336  unsigned int level;
1337 
1338  ast_str_reset(configs);
1339 
1340  for (level = 0; level < ARRAY_LEN(levels); level++) {
1341  if ((chan->logmask & (1 << level)) && levels[level]) {
1342  ast_str_append(&configs, 0, "%s ", levels[level]);
1343  }
1344  }
1345 
1346  res = logentry(chan->filename, chan->type == LOGTYPE_CONSOLE ? "Console" :
1347  (chan->type == LOGTYPE_SYSLOG ? "Syslog" : "File"), chan->disabled ?
1348  "Disabled" : "Enabled", ast_str_buffer(configs), data);
1349 
1350  if (res) {
1352  ast_free(configs);
1353  configs = NULL;
1354  return AST_LOGGER_FAILURE;
1355  }
1356  }
1358 
1359  ast_free(configs);
1360  configs = NULL;
1361 
1362  return AST_LOGGER_SUCCESS;
1363 }
#define ARRAY_LEN(a)
Definition: isdn_lib.c:42
char * ast_str_buffer(const struct ast_str *buf)
Returns the string buffer within the ast_str buf.
Definition: strings.h:714
#define AST_RWLIST_UNLOCK(head)
Attempts to unlock a read/write based list.
Definition: linkedlists.h:150
static char * levels[NUMLOGLEVELS]
Logging channels used in the Asterisk logging system.
Definition: logger.c:204
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:1091
#define NULL
Definition: resample.c:96
#define AST_RWLIST_RDLOCK(head)
Read locks a list.
Definition: linkedlists.h:77
unsigned int logmask
Definition: logger.c:133
#define AST_RWLIST_TRAVERSE
Definition: linkedlists.h:493
int disabled
Definition: logger.c:135
The descriptor of a dynamic string XXX storage will be optimized later if needed We use the ts field ...
Definition: strings.h:584
enum logtypes type
Definition: logger.c:141
#define ast_free(a)
Definition: astmm.h:182
char filename[PATH_MAX]
Definition: logger.c:145
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:653
#define ast_str_create(init_len)
Create a malloc&#39;ed dynamic length string.
Definition: strings.h:620

◆ ast_logger_get_dateformat()

const char* ast_logger_get_dateformat ( void  )

Get the logger configured date format.

Return values
Thedate format string
Since
13.0.0

Definition at line 2537 of file logger.c.

References dateformat.

Referenced by set_header().

2538 {
2539  return dateformat;
2540 }
static char dateformat[256]
Definition: logger.c:77

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

References logger_queue_limit.

Referenced by handle_cli_queue_test().

2548 {
2549  return logger_queue_limit;
2550 }
static int logger_queue_limit
Definition: logger.c:92

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

References ARRAY_LEN, ast_debug, ast_log(), AST_RWLIST_UNLOCK, AST_RWLIST_WRLOCK, ast_strdup, available(), LOG_WARNING, and update_logchannels().

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

2456 {
2457  unsigned int level;
2458  unsigned int available = 0;
2459 
2461 
2462  for (level = 0; level < ARRAY_LEN(levels); level++) {
2463  if ((level >= 16) && !available && !levels[level]) {
2464  available = level;
2465  continue;
2466  }
2467 
2468  if (levels[level] && !strcasecmp(levels[level], name)) {
2470  "Unable to register dynamic logger level '%s': a standard logger level uses that name.\n",
2471  name);
2473 
2474  return -1;
2475  }
2476  }
2477 
2478  if (!available) {
2480  "Unable to register dynamic logger level '%s'; maximum number of levels registered.\n",
2481  name);
2483 
2484  return -1;
2485  }
2486 
2488 
2490 
2491  ast_debug(1, "Registered dynamic logger level '%s' with index %u.\n", name, available);
2492 
2494 
2495  return available;
2496 }
#define ARRAY_LEN(a)
Definition: isdn_lib.c:42
#define AST_RWLIST_WRLOCK(head)
Write locks a list.
Definition: linkedlists.h:51
#define LOG_WARNING
Definition: logger.h:274
#define AST_RWLIST_UNLOCK(head)
Attempts to unlock a read/write based list.
Definition: linkedlists.h:150
static char * levels[NUMLOGLEVELS]
Logging channels used in the Asterisk logging system.
Definition: logger.c:204
#define ast_strdup(str)
A wrapper for strdup()
Definition: astmm.h:243
static void update_logchannels(void)
Definition: logger.c:2347
#define ast_debug(level,...)
Log a DEBUG message.
Definition: logger.h:444
static const char name[]
Definition: cdr_mysql.c:74
static int available(struct dahdi_pvt **pvt, int is_specific_channel)
Definition: chan_dahdi.c:13058
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:2088

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

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

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

1473 {
1474  struct logchannel *chan;
1475 
1477 
1478  chan = find_logchannel(log_channel);
1479  if (chan && chan->dynamic) {
1481  } else {
1483  return AST_LOGGER_FAILURE;
1484  }
1486 
1487  if (chan->fileptr) {
1488  fclose(chan->fileptr);
1489  chan->fileptr = NULL;
1490  }
1491  ast_free(chan);
1492  chan = NULL;
1493 
1494  return AST_LOGGER_SUCCESS;
1495 }
#define AST_RWLIST_WRLOCK(head)
Write locks a list.
Definition: linkedlists.h:51
#define AST_RWLIST_UNLOCK(head)
Attempts to unlock a read/write based list.
Definition: linkedlists.h:150
#define NULL
Definition: resample.c:96
int dynamic
Definition: logger.c:151
static struct logchannel * find_logchannel(const char *channel)
Find a particular logger channel by name.
Definition: logger.c:599
#define ast_free(a)
Definition: astmm.h:182
FILE * fileptr
Definition: logger.c:143
#define AST_RWLIST_REMOVE
Definition: linkedlists.h:884
struct logchannel::@398 list

◆ ast_logger_rotate()

int ast_logger_rotate ( void  )

Reload logger while rotating log files.

Definition at line 1241 of file logger.c.

References NULL, and reload_logger().

Referenced by action_loggerrotate().

1242 {
1243  return reload_logger(1, NULL);
1244 }
#define NULL
Definition: resample.c:96
static int reload_logger(int rotate, const char *altconf)
Definition: logger.c:1128

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

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

1247 {
1248  struct logchannel *f;
1249  int success = AST_LOGGER_FAILURE;
1250  char filename[PATH_MAX];
1251 
1252  make_filename(log_channel, filename, sizeof(filename));
1253 
1255 
1257 
1259  if (f->disabled) {
1260  f->disabled = 0; /* Re-enable logging at reload */
1261  manager_event(EVENT_FLAG_SYSTEM, "LogChannel", "Channel: %s\r\nEnabled: Yes\r\n",
1262  f->filename);
1263  }
1264  if (f->fileptr && (f->fileptr != stdout) && (f->fileptr != stderr)) {
1265  fclose(f->fileptr); /* Close file */
1266  f->fileptr = NULL;
1267  if (strcmp(filename, f->filename) == 0) {
1268  rotate_file(f->filename);
1269  success = AST_LOGGER_SUCCESS;
1270  }
1271  }
1272  }
1273 
1275 
1277 
1278  return success;
1279 }
static int init_logger_chain(const char *altconf)
Read config, setup channels.
Definition: logger.c:708
static int rotate_file(const char *filename)
Definition: logger.c:961
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:558
#define AST_RWLIST_WRLOCK(head)
Write locks a list.
Definition: linkedlists.h:51
#define AST_RWLIST_UNLOCK(head)
Attempts to unlock a read/write based list.
Definition: linkedlists.h:150
#define NULL
Definition: resample.c:96
#define EVENT_FLAG_SYSTEM
Definition: manager.h:71
#define AST_RWLIST_TRAVERSE
Definition: linkedlists.h:493
int disabled
Definition: logger.c:135
const char * ast_config_AST_LOG_DIR
Definition: options.c:159
FILE * fileptr
Definition: logger.c:143
char filename[PATH_MAX]
Definition: logger.c:145
#define PATH_MAX
Definition: asterisk.h:40
struct logchannel::@398 list
#define manager_event(category, event, contents,...)
External routines may send asterisk manager events this way.
Definition: manager.h:248
int ast_mkdir(const char *path, int mode)
Recursively create directory path.
Definition: main/utils.c:2102

◆ 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
Returns
Nothing

Definition at line 2542 of file logger.c.

References logger_queue_limit.

Referenced by handle_cli_queue_test().

2543 {
2544  logger_queue_limit = queue_limit;
2545 }
static int logger_queue_limit
Definition: logger.c:92

◆ 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
Returns
nothing
Since
1.8

Definition at line 2498 of file logger.c.

References ARRAY_LEN, ast_debug, ast_free, AST_RWLIST_UNLOCK, AST_RWLIST_WRLOCK, global_logmask, NULL, and update_logchannels().

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

2499 {
2500  unsigned int found = 0;
2501  unsigned int x;
2502 
2504 
2505  for (x = 16; x < ARRAY_LEN(levels); x++) {
2506  if (!levels[x]) {
2507  continue;
2508  }
2509 
2510  if (strcasecmp(levels[x], name)) {
2511  continue;
2512  }
2513 
2514  found = 1;
2515  break;
2516  }
2517 
2518  if (found) {
2519  /* take this level out of the global_logmask, to ensure that no new log messages
2520  * will be queued for it
2521  */
2522 
2523  global_logmask &= ~(1 << x);
2524 
2525  ast_free(levels[x]);
2526  levels[x] = NULL;
2528 
2529  ast_debug(1, "Unregistered dynamic logger level '%s' with index %u.\n", name, x);
2530 
2532  } else {
2534  }
2535 }
#define ARRAY_LEN(a)
Definition: isdn_lib.c:42
static unsigned int global_logmask
Definition: logger.c:83
#define AST_RWLIST_WRLOCK(head)
Write locks a list.
Definition: linkedlists.h:51
#define AST_RWLIST_UNLOCK(head)
Attempts to unlock a read/write based list.
Definition: linkedlists.h:150
static char * levels[NUMLOGLEVELS]
Logging channels used in the Asterisk logging system.
Definition: logger.c:204
#define NULL
Definition: resample.c:96
static void update_logchannels(void)
Definition: logger.c:2347
#define ast_debug(level,...)
Log a DEBUG message.
Definition: logger.h:444
static const char name[]
Definition: cdr_mysql.c:74
#define ast_free(a)
Definition: astmm.h:182

◆ AST_MODULE_SELF_SYM()

struct ast_module* AST_MODULE_SELF_SYM ( void  )

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

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, queuelog_init, RQ_CHAR, S_OR, and SENTINEL.

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

882 {
883  va_list ap;
884  struct timeval tv;
885  struct ast_tm tm;
886  char qlog_msg[8192];
887  int qlog_len;
888  char time_str[30];
889 
890  if (!logger_initialized) {
891  /* You are too early. We are not open yet! */
892  return;
893  }
894  if (!queuelog_init) {
895  /* We must initialize now since someone is trying to log something. */
897  }
898 
899  if (ast_check_realtime("queue_log")) {
900  tv = ast_tvnow();
901  ast_localtime(&tv, &tm, logfiles.queue_log_realtime_use_gmt ? "GMT" : NULL);
902  ast_strftime(time_str, sizeof(time_str), "%F %T.%6q", &tm);
903  va_start(ap, fmt);
904  vsnprintf(qlog_msg, sizeof(qlog_msg), fmt, ap);
905  va_end(ap);
906  if (logfiles.queue_adaptive_realtime) {
908  AST_APP_ARG(data)[5];
909  );
910  AST_NONSTANDARD_APP_ARGS(args, qlog_msg, '|');
911  /* Ensure fields are large enough to receive data */
912  ast_realtime_require_field("queue_log",
913  "data1", RQ_CHAR, strlen(S_OR(args.data[0], "")),
914  "data2", RQ_CHAR, strlen(S_OR(args.data[1], "")),
915  "data3", RQ_CHAR, strlen(S_OR(args.data[2], "")),
916  "data4", RQ_CHAR, strlen(S_OR(args.data[3], "")),
917  "data5", RQ_CHAR, strlen(S_OR(args.data[4], "")),
918  SENTINEL);
919 
920  /* Store the log */
921  ast_store_realtime("queue_log", "time", time_str,
922  "callid", callid,
923  "queuename", queuename,
924  "agent", agent,
925  "event", event,
926  "data1", S_OR(args.data[0], ""),
927  "data2", S_OR(args.data[1], ""),
928  "data3", S_OR(args.data[2], ""),
929  "data4", S_OR(args.data[3], ""),
930  "data5", S_OR(args.data[4], ""),
931  SENTINEL);
932  } else {
933  ast_store_realtime("queue_log", "time", time_str,
934  "callid", callid,
935  "queuename", queuename,
936  "agent", agent,
937  "event", event,
938  "data", qlog_msg,
939  SENTINEL);
940  }
941 
942  if (!logfiles.queue_log_to_file) {
943  return;
944  }
945  }
946 
947  if (qlog) {
948  va_start(ap, fmt);
949  qlog_len = snprintf(qlog_msg, sizeof(qlog_msg), "%ld|%s|%s|%s|%s|", (long)time(NULL), callid, queuename, agent, event);
950  vsnprintf(qlog_msg + qlog_len, sizeof(qlog_msg) - qlog_len, fmt, ap);
951  va_end(ap);
953  if (qlog) {
954  fprintf(qlog, "%s\n", qlog_msg);
955  fflush(qlog);
956  }
958  }
959 }
static int queuelog_init
Definition: logger.c:84
static struct @397 logfiles
#define AST_RWLIST_UNLOCK(head)
Attempts to unlock a read/write based list.
Definition: linkedlists.h:150
struct ast_tm * ast_localtime(const struct timeval *timep, struct ast_tm *p_tm, const char *zone)
Timezone-independent version of localtime_r(3).
Definition: localtime.c:1739
int ast_check_realtime(const char *family)
Check if realtime engine is configured for family.
Definition: main/config.c:3363
Definition: astman.c:222
void logger_queue_start(void)
Start the ast_queue_log() logger.
Definition: logger.c:1841
struct timeval ast_tvnow(void)
Returns current timeval. Meant to replace calls to gettimeofday().
Definition: time.h:150
const char * args
#define NULL
Definition: resample.c:96
static FILE * qlog
Definition: logger.c:191
static int logger_initialized
Definition: logger.c:85
#define AST_RWLIST_RDLOCK(head)
Read locks a list.
Definition: linkedlists.h:77
#define SENTINEL
Definition: compiler.h:87
int ast_store_realtime(const char *family,...) attribute_sentinel
Create realtime configuration.
Definition: main/config.c:3570
int ast_realtime_require_field(const char *family,...) attribute_sentinel
Inform realtime what fields that may be stored.
Definition: main/config.c:3382
#define AST_NONSTANDARD_APP_ARGS(args, parse, sep)
Performs the &#39;nonstandard&#39; argument separation process for an application.
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
#define S_OR(a, b)
returns the equivalent of logic or for strings: first one if not empty, otherwise second one...
Definition: strings.h:79
#define AST_DECLARE_APP_ARGS(name, arglist)
Declare a structure to hold an application&#39;s arguments.
#define AST_APP_ARG(name)
Define an application argument.

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

References ast_threadstorage_get(), and unique_callid.

Referenced by __ast_pbx_run(), __ast_verbose(), ast_callid_threadstorage_auto(), ast_dial_run(), ast_log_ap(), ast_log_safe(), bridge_channel_internal_join(), bridge_impart_internal(), 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().

1950 {
1951  ast_callid *callid;
1952 
1953  callid = ast_threadstorage_get(&unique_callid, sizeof(*callid));
1954 
1955  return callid ? *callid : 0;
1956 }
void * ast_threadstorage_get(struct ast_threadstorage *ts, size_t init_size)
Retrieve thread storage.
unsigned int ast_callid
Definition: logger.h:87
static struct ast_threadstorage unique_callid
Definition: logger.c:89

◆ AST_THREADSTORAGE_RAW()

AST_THREADSTORAGE_RAW ( in_safe_log  )

Referenced by update_logchannels().

◆ ast_verb_console_get()

int ast_verb_console_get ( void  )

Get this thread's console verbosity level.

Return values
verbositylevel of the console.

Definition at line 2310 of file logger.c.

References AST_RWLIST_RDLOCK, AST_RWLIST_UNLOCK, ast_threadstorage_get(), verb_console::level, my_verb_console, and option_verbose.

Referenced by handle_show_settings(), and handle_verbose().

2311 {
2312  struct verb_console *console;
2313  int verb_level;
2314 
2315  console = ast_threadstorage_get(&my_verb_console, sizeof(*console));
2317  if (!console) {
2318  verb_level = 0;
2319  } else if (console->level) {
2320  verb_level = *console->level;
2321  } else {
2322  verb_level = option_verbose;
2323  }
2325  return verb_level;
2326 }
static struct ast_threadstorage my_verb_console
Definition: logger.c:2281
void * ast_threadstorage_get(struct ast_threadstorage *ts, size_t init_size)
Retrieve thread storage.
#define AST_RWLIST_UNLOCK(head)
Attempts to unlock a read/write based list.
Definition: linkedlists.h:150
int option_verbose
Definition: options.c:67
#define AST_RWLIST_RDLOCK(head)
Read locks a list.
Definition: linkedlists.h:77
int * level
Definition: logger.c:2210

◆ 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.
Returns
Nothing

Definition at line 2283 of file logger.c.

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

2284 {
2285  struct verb_console *console;
2286 
2287  console = ast_threadstorage_get(&my_verb_console, sizeof(*console));
2288  if (!console || !level) {
2289  return;
2290  }
2291  console->level = level;
2292 
2296  ast_verb_update();
2297 }
Definition: test_heap.c:38
static struct ast_threadstorage my_verb_console
Definition: logger.c:2281
void * ast_threadstorage_get(struct ast_threadstorage *ts, size_t init_size)
Retrieve thread storage.
void ast_verb_update(void)
Re-evaluate the system max verbosity level (ast_verb_sys_level).
Definition: logger.c:2219
#define AST_RWLIST_WRLOCK(head)
Write locks a list.
Definition: linkedlists.h:51
#define AST_RWLIST_UNLOCK(head)
Attempts to unlock a read/write based list.
Definition: linkedlists.h:150
#define AST_RWLIST_INSERT_HEAD
Definition: linkedlists.h:717
int * level
Definition: logger.c:2210

◆ 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.
Returns
Nothing

Definition at line 2328 of file logger.c.

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

Referenced by handle_verbose().

2329 {
2330  struct verb_console *console;
2331 
2332  console = ast_threadstorage_get(&my_verb_console, sizeof(*console));
2333  if (!console) {
2334  return;
2335  }
2336 
2338  if (console->level) {
2339  *console->level = verb_level;
2340  } else {
2341  option_verbose = verb_level;
2342  }
2344  ast_verb_update();
2345 }
static struct ast_threadstorage my_verb_console
Definition: logger.c:2281
void * ast_threadstorage_get(struct ast_threadstorage *ts, size_t init_size)
Retrieve thread storage.
void ast_verb_update(void)
Re-evaluate the system max verbosity level (ast_verb_sys_level).
Definition: logger.c:2219
#define AST_RWLIST_WRLOCK(head)
Write locks a list.
Definition: linkedlists.h:51
#define AST_RWLIST_UNLOCK(head)
Attempts to unlock a read/write based list.
Definition: linkedlists.h:150
int option_verbose
Definition: options.c:67
int * level
Definition: logger.c:2210

◆ ast_verb_console_unregister()

void ast_verb_console_unregister ( void  )

Unregister this thread's console verbosity level.

Returns
Nothing

Definition at line 2299 of file logger.c.

References ast_threadstorage_get(), my_verb_console, and verb_console_unregister().

Referenced by netconsole().

2300 {
2301  struct verb_console *console;
2302 
2303  console = ast_threadstorage_get(&my_verb_console, sizeof(*console));
2304  if (!console) {
2305  return;
2306  }
2307  verb_console_unregister(console);
2308 }
static struct ast_threadstorage my_verb_console
Definition: logger.c:2281
void * ast_threadstorage_get(struct ast_threadstorage *ts, size_t init_size)
Retrieve thread storage.
static void verb_console_unregister(struct verb_console *console)
Definition: logger.c:2262

◆ ast_verb_update()

void ast_verb_update ( void  )

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

Returns
Nothing

Definition at line 2219 of file logger.c.

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

2220 {
2221  struct logchannel *log;
2222  struct verb_console *console;
2223  int verb_level;
2224 
2226 
2228 
2229  /* Default to the root console verbosity. */
2230  verb_level = option_verbose;
2231 
2232  /* Determine max remote console level. */
2233  AST_LIST_TRAVERSE(&verb_consoles, console, node) {
2234  if (verb_level < *console->level) {
2235  verb_level = *console->level;
2236  }
2237  }
2239 
2240  /* Determine max logger channel level. */
2242  AST_RWLIST_TRAVERSE(&logchannels, log, list) {
2243  if (verb_level < log->verbosity) {
2244  verb_level = log->verbosity;
2245  }
2246  }
2248 
2249  ast_verb_sys_level = verb_level;
2250 
2252 }
Definition: test_heap.c:38
static ast_mutex_t verb_update_lock
Definition: logger.c:2217
#define AST_RWLIST_UNLOCK(head)
Attempts to unlock a read/write based list.
Definition: linkedlists.h:150
int option_verbose
Definition: options.c:67
#define ast_mutex_lock(a)
Definition: lock.h:187
int verbosity
Definition: logger.c:139
#define AST_RWLIST_RDLOCK(head)
Read locks a list.
Definition: linkedlists.h:77
#define AST_RWLIST_TRAVERSE
Definition: linkedlists.h:493
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:490
int * level
Definition: logger.c:2210
#define ast_mutex_unlock(a)
Definition: lock.h:188

◆ close_logger()

void close_logger ( void  )

Provided by logger.c

Definition at line 1899 of file logger.c.

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, logchannel::fileptr, logchannel::list, logger_initialized, and NULL.

Referenced by really_quit().

1900 {
1901  struct logchannel *f = NULL;
1902 
1904 
1906 
1907  logger_initialized = 0;
1908 
1909  /* Stop logger thread */
1911  close_logger_thread = 1;
1914 
1915  if (logthread != AST_PTHREADT_NULL) {
1916  pthread_join(logthread, NULL);
1917  }
1918 
1920 
1921  if (qlog) {
1922  fclose(qlog);
1923  qlog = NULL;
1924  }
1925 
1926  while ((f = AST_LIST_REMOVE_HEAD(&logchannels, list))) {
1927  if (f->fileptr && (f->fileptr != stdout) && (f->fileptr != stderr)) {
1928  fclose(f->fileptr);
1929  f->fileptr = NULL;
1930  }
1931  ast_free(f);
1932  }
1933 
1934  closelog(); /* syslog */
1935 
1937 }
static struct ast_cli_entry cli_logger[]
Definition: logger.c:1546
#define AST_LIST_LOCK(head)
Locks a list.
Definition: linkedlists.h:39
#define ARRAY_LEN(a)
Definition: isdn_lib.c:42
int ast_cli_unregister_multiple(struct ast_cli_entry *e, int len)
Unregister multiple commands.
Definition: clicompat.c:30
static pthread_t logthread
Definition: logger.c:187
#define AST_RWLIST_WRLOCK(head)
Write locks a list.
Definition: linkedlists.h:51
#define AST_LIST_UNLOCK(head)
Attempts to unlock a list.
Definition: linkedlists.h:139
#define AST_RWLIST_UNLOCK(head)
Attempts to unlock a read/write based list.
Definition: linkedlists.h:150
int ast_logger_category_unload(void)
Unload system wide logger category functionality.
#define NULL
Definition: resample.c:96
#define ast_cond_signal(cond)
Definition: lock.h:201
static FILE * qlog
Definition: logger.c:191
static int logger_initialized
Definition: logger.c:85
#define AST_PTHREADT_NULL
Definition: lock.h:66
#define AST_LIST_REMOVE_HEAD(head, field)
Removes and returns the head entry from a list.
Definition: linkedlists.h:832
#define ast_free(a)
Definition: astmm.h:182
FILE * fileptr
Definition: logger.c:143
struct logchannel::@398 list
static int close_logger_thread
Definition: logger.c:189
static ast_cond_t logcond
Definition: logger.c:188

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

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

600 {
601  char filename[PATH_MAX];
602  struct logchannel *chan;
603 
604  make_filename(channel, filename, sizeof(filename));
605 
607  if (!strcmp(chan->filename, filename)) {
608  return chan;
609  }
610  }
611 
612  return NULL;
613 }
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:558
Definition: muted.c:95
#define NULL
Definition: resample.c:96
#define AST_RWLIST_TRAVERSE
Definition: linkedlists.h:493
char filename[PATH_MAX]
Definition: logger.c:145
#define PATH_MAX
Definition: asterisk.h:40
struct logchannel::@398 list

◆ format_log_default()

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

Definition at line 363 of file logger.c.

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

364 {
365  char call_identifier_str[13];
366 
367  if (msg->callid) {
368  snprintf(call_identifier_str, sizeof(call_identifier_str), "[C-%08x]", msg->callid);
369  } else {
370  call_identifier_str[0] = '\0';
371  }
372 
373  switch (chan->type) {
374  case LOGTYPE_SYSLOG:
375  snprintf(buf, size, "%s[%d]%s: %s:%d in %s: %s",
376  levels[msg->level], msg->lwp, call_identifier_str, msg->file,
377  msg->line, msg->function, msg->message);
378  term_strip(buf, buf, size);
379  break;
380  case LOGTYPE_FILE:
381  snprintf(buf, size, "[%s] %s[%d]%s %s: %s",
382  msg->date, msg->level_name, msg->lwp, call_identifier_str,
383  msg->file, msg->message);
384  term_strip(buf, buf, size);
385  break;
386  case LOGTYPE_CONSOLE:
387  {
388  char linestr[32];
389  int has_file = !ast_strlen_zero(msg->file);
390  int has_line = (msg->line > 0);
391  int has_func = !ast_strlen_zero(msg->function);
392 
393  /*
394  * Verbose messages are interpreted by console channels in their own
395  * special way
396  */
397  if (msg->level == __LOG_VERBOSE) {
398  return logger_add_verbose_magic(msg, buf, size);
399  }
400 
401  /* Turn the numerical line number into a string */
402  snprintf(linestr, sizeof(linestr), "%d", msg->line);
403  /* Build string to print out */
404  snprintf(buf, size, "[%s] " COLORIZE_FMT "[%d]%s: " COLORIZE_FMT "%s" COLORIZE_FMT " " COLORIZE_FMT "%s %s",
405  msg->date,
406  COLORIZE(colors[msg->level], 0, msg->level_name),
407  msg->lwp,
408  call_identifier_str,
409  COLORIZE(COLOR_BRWHITE, 0, has_file ? msg->file : ""),
410  has_file ? ":" : "",
411  COLORIZE(COLOR_BRWHITE, 0, has_line ? linestr : ""),
412  COLORIZE(COLOR_BRWHITE, 0, has_func ? msg->function : ""),
413  has_func ? ":" : "",
414  msg->message);
415  }
416  break;
417  }
418 
419  return 0;
420 }
int line
Definition: logger.c:167
static int logger_add_verbose_magic(struct logmsg *logmsg, char *buf, size_t size)
Definition: logger.c:317
static const int colors[NUMLOGLEVELS]
Colors used in the console for logging.
Definition: logger.c:215
char buf[BUFSIZE]
Definition: eagi_proxy.c:66
ast_callid callid
Definition: logger.c:169
char * term_strip(char *outbuf, const char *inbuf, int maxout)
Remove colorings from a specified string.
Definition: term.c:311
static char * levels[NUMLOGLEVELS]
Logging channels used in the Asterisk logging system.
Definition: logger.c:204
#define COLOR_BRWHITE
Definition: term.h:62
#define COLORIZE(fg, bg, str)
Definition: term.h:68
#define COLORIZE_FMT
Shortcut macros for coloring a set of text.
Definition: term.h:67
const ast_string_field function
Definition: logger.c:176
int level
Definition: logger.c:165
const ast_string_field date
Definition: logger.c:176
enum logtypes type
Definition: logger.c:141
#define ast_strlen_zero(a)
Definition: muted.c:73
int lwp
Definition: logger.c:168
const ast_string_field level_name
Definition: logger.c:176
#define __LOG_VERBOSE
Definition: logger.h:295
const ast_string_field message
Definition: logger.c:176
const ast_string_field file
Definition: logger.c:176

◆ format_log_json()

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

Definition at line 257 of file logger.c.

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

258 {
259  struct ast_json *json;
260  char *str;
261  char call_identifier_str[13];
262  size_t json_str_len;
263 
264  if (msg->callid) {
265  snprintf(call_identifier_str, sizeof(call_identifier_str), "[C-%08x]", msg->callid);
266  } else {
267  call_identifier_str[0] = '\0';
268  }
269 
270  json = ast_json_pack("{s: s, s: s, "
271  "s: {s: i, s: s} "
272  "s: {s: {s: s, s: s, s: i}, "
273  "s: s, s: s} }",
274  "hostname", ast_config_AST_SYSTEM_NAME,
275  "timestamp", msg->date,
276  "identifiers",
277  "lwp", msg->lwp,
278  "callid", S_OR(call_identifier_str, ""),
279  "logmsg",
280  "location",
281  "filename", msg->file,
282  "function", msg->function,
283  "line", msg->line,
284  "level", msg->level_name,
285  "message", msg->message);
286  if (!json) {
287  return -1;
288  }
289 
290  str = ast_json_dump_string(json);
291  if (!str) {
292  ast_json_unref(json);
293  return -1;
294  }
295 
296  ast_copy_string(buf, str, size);
297  json_str_len = strlen(str);
298  if (json_str_len > size - 1) {
299  json_str_len = size - 1;
300  }
301  buf[json_str_len] = '\n';
302  buf[json_str_len + 1] = '\0';
303 
304  term_strip(buf, buf, size);
305 
306  ast_json_free(str);
307  ast_json_unref(json);
308 
309  return 0;
310 }
int line
Definition: logger.c:167
struct ast_json * ast_json_pack(char const *format,...)
Helper for creating complex JSON values.
Definition: json.c:591
void ast_json_unref(struct ast_json *value)
Decrease refcount on value. If refcount reaches zero, value is freed.
Definition: json.c:73
char buf[BUFSIZE]
Definition: eagi_proxy.c:66
ast_callid callid
Definition: logger.c:169
void ast_json_free(void *p)
Asterisk&#39;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:763
char * term_strip(char *outbuf, const char *inbuf, int maxout)
Remove colorings from a specified string.
Definition: term.c:311
const char * str
Definition: app_jack.c:147
const char * ast_config_AST_SYSTEM_NAME
Definition: options.c:170
const ast_string_field function
Definition: logger.c:176
const ast_string_field date
Definition: logger.c:176
int lwp
Definition: logger.c:168
const ast_string_field level_name
Definition: logger.c:176
void ast_copy_string(char *dst, const char *src, size_t size)
Size-limited null-terminating string copy.
Definition: strings.h:401
#define S_OR(a, b)
returns the equivalent of logic or for strings: first one if not empty, otherwise second one...
Definition: strings.h:79
const ast_string_field message
Definition: logger.c:176
Abstract JSON element (object, array, string, int, ...).
const ast_string_field file
Definition: logger.c:176

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

References format_log_message_ap().

Referenced by ast_log_full(), and logger_thread().

1736 {
1737  struct logmsg *logmsg;
1738  va_list ap;
1739 
1740  va_start(ap, fmt);
1741  logmsg = format_log_message_ap(level, sublevel, file, line, function, callid, fmt, ap);
1742  va_end(ap);
1743 
1744  return logmsg;
1745 }
int line
Definition: logger.c:167
ast_callid callid
Definition: logger.c:169
Definition: logger.c:163
int level
Definition: logger.c:165
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:1669
int sublevel
Definition: logger.c:166

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

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

Referenced by ast_log_full(), and format_log_message().

1672 {
1673  struct logmsg *logmsg = NULL;
1674  struct ast_str *buf = NULL;
1675  struct ast_tm tm;
1676  struct timeval now = ast_tvnow();
1677  int res = 0;
1678  char datestring[256];
1679 
1680  if (!(buf = ast_str_thread_get(&log_buf, LOG_BUF_INIT_SIZE))) {
1681  return NULL;
1682  }
1683 
1684  /* Build string */
1685  res = ast_str_set_va(&buf, BUFSIZ, fmt, ap);
1686 
1687  /* If the build failed, then abort and free this structure */
1688  if (res == AST_DYNSTR_BUILD_FAILED) {
1689  return NULL;
1690  }
1691 
1692  /* Automatically add a newline to format strings that don't have one */
1693  if (!ast_ends_with(ast_str_buffer(buf), "\n")) {
1694  ast_str_append(&buf, 0, "\n");
1695  }
1696 
1697  /* Create a new logging message */
1698  if (!(logmsg = ast_calloc_with_stringfields(1, struct logmsg, res + 128))) {
1699  return NULL;
1700  }
1701 
1702  /* Copy string over */
1704 
1705  /* Set type */
1706  if (level == __LOG_VERBOSE) {
1707  logmsg->type = LOGMSG_VERBOSE;
1708  } else {
1709  logmsg->type = LOGMSG_NORMAL;
1710  }
1711 
1712  if (display_callids && callid) {
1713  logmsg->callid = callid;
1714  }
1715 
1716  /* Create our date/time */
1717  ast_localtime(&now, &tm, NULL);
1718  ast_strftime(datestring, sizeof(datestring), dateformat, &tm);
1719  ast_string_field_set(logmsg, date, datestring);
1720 
1721  /* Copy over data */
1722  logmsg->level = level;
1723  logmsg->sublevel = sublevel;
1724  logmsg->line = line;
1725  ast_string_field_set(logmsg, level_name, levels[level]);
1726  ast_string_field_set(logmsg, file, file);
1727  ast_string_field_set(logmsg, function, function);
1728  logmsg->lwp = ast_get_tid();
1729 
1730  return logmsg;
1731 }
int line
Definition: logger.c:167
static int force_inline attribute_pure ast_ends_with(const char *str, const char *suffix)
Definition: strings.h:112
char buf[BUFSIZE]
Definition: eagi_proxy.c:66
ast_callid callid
Definition: logger.c:169
char * ast_str_buffer(const struct ast_str *buf)
Returns the string buffer within the ast_str buf.
Definition: strings.h:714
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
#define LOG_BUF_INIT_SIZE
Definition: logger.c:255
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:982
#define ast_calloc_with_stringfields(n, type, size)
Allocate a structure with embedded stringfields in a single allocation.
Definition: stringfields.h:426
static char * levels[NUMLOGLEVELS]
Logging channels used in the Asterisk logging system.
Definition: logger.c:204
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:1091
struct timeval ast_tvnow(void)
Returns current timeval. Meant to replace calls to gettimeofday().
Definition: time.h:150
#define NULL
Definition: resample.c:96
static struct ast_threadstorage log_buf
Definition: logger.c:254
Definition: logger.c:163
int ast_get_tid(void)
Get current thread ID.
Definition: main/utils.c:2375
int level
Definition: logger.c:165
The descriptor of a dynamic string XXX storage will be optimized later if needed We use the ts field ...
Definition: strings.h:584
int lwp
Definition: logger.c:168
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
enum logmsgtypes type
Definition: logger.c:164
static char dateformat[256]
Definition: logger.c:77
static int display_callids
Definition: logger.c:87
#define __LOG_VERBOSE
Definition: logger.h:295
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:861
int sublevel
Definition: logger.c:166
#define ast_string_field_set(x, field, data)
Set a field to a simple string value.
Definition: stringfields.h:514

◆ format_log_plain()

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

Definition at line 427 of file logger.c.

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

428 {
429  char call_identifier_str[13];
430  char linestr[32];
431  int has_file = !ast_strlen_zero(msg->file);
432  int has_line = (msg->line > 0);
433  int has_func = !ast_strlen_zero(msg->function);
434 
435  if (msg->callid) {
436  snprintf(call_identifier_str, sizeof(call_identifier_str), "[C-%08x]", msg->callid);
437  } else {
438  call_identifier_str[0] = '\0';
439  }
440 
441  switch (chan->type) {
442  case LOGTYPE_SYSLOG:
443  snprintf(buf, size, "%s[%d]%s: %s:%d in %s: %s",
444  levels[msg->level], msg->lwp, call_identifier_str, msg->file,
445  msg->line, msg->function, msg->message);
446  term_strip(buf, buf, size);
447  break;
448  case LOGTYPE_FILE:
449  case LOGTYPE_CONSOLE:
450  /* Turn the numerical line number into a string */
451  snprintf(linestr, sizeof(linestr), "%d", msg->line);
452  /* Build string to print out */
453  snprintf(buf, size, "[%s] %s[%d]%s: %s%s%s%s%s%s%s",
454  msg->date,
455  msg->level_name,
456  msg->lwp,
457  call_identifier_str,
458  has_file ? msg->file : "",
459  has_file ? ":" : "",
460  has_line ? linestr : "",
461  has_line ? " " : "",
462  has_func ? msg->function : "",
463  has_func ? ": " : "",
464  msg->message);
465  term_strip(buf, buf, size);
466  break;
467  }
468 
469  return 0;
470 }
int line
Definition: logger.c:167
char buf[BUFSIZE]
Definition: eagi_proxy.c:66
ast_callid callid
Definition: logger.c:169
char * term_strip(char *outbuf, const char *inbuf, int maxout)
Remove colorings from a specified string.
Definition: term.c:311
static char * levels[NUMLOGLEVELS]
Logging channels used in the Asterisk logging system.
Definition: logger.c:204
const ast_string_field function
Definition: logger.c:176
int level
Definition: logger.c:165
const ast_string_field date
Definition: logger.c:176
enum logtypes type
Definition: logger.c:141
#define ast_strlen_zero(a)
Definition: muted.c:73
int lwp
Definition: logger.c:168
const ast_string_field level_name
Definition: logger.c:176
const ast_string_field message
Definition: logger.c:176
const ast_string_field file
Definition: logger.c:176

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

References ast_cli_args::argc, ast_cli_args::argv, 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, ast_cli_args::fd, NULL, and ast_cli_entry::usage.

1437 {
1438  switch (cmd) {
1439  case CLI_INIT:
1440  e->command = "logger add channel";
1441  e->usage =
1442  "Usage: logger add channel <name> <levels>\n"
1443  " Adds a temporary logger channel. This logger channel\n"
1444  " will exist until removed or until Asterisk is restarted.\n"
1445  " <levels> is a comma-separated list of desired logger\n"
1446  " levels such as: verbose,warning,error\n"
1447  " An optional formatter may be specified with the levels;\n"
1448  " valid values are '[json]' and '[default]'.\n";
1449  return NULL;
1450  case CLI_GENERATE:
1451  return NULL;
1452  }
1453 
1454  if (a->argc < 5) {
1455  return CLI_SHOWUSAGE;
1456  }
1457 
1458  switch (ast_logger_create_channel(a->argv[3], a->argv[4])) {
1459  case AST_LOGGER_SUCCESS:
1460  return CLI_SUCCESS;
1461  case AST_LOGGER_FAILURE:
1462  ast_cli(a->fd, "Logger channel '%s' already exists\n", a->argv[3]);
1463  return CLI_SUCCESS;
1464  case AST_LOGGER_DECLINE:
1466  default:
1467  ast_cli(a->fd, "ERROR: Unable to create log channel '%s'\n", a->argv[3]);
1468  return CLI_FAILURE;
1469  }
1470 }
const int argc
Definition: cli.h:160
Definition: cli.h:152
#define NULL
Definition: resample.c:96
void ast_cli(int fd, const char *fmt,...)
Definition: clicompat.c:6
const int fd
Definition: cli.h:159
const char *const * argv
Definition: cli.h:161
#define CLI_SHOWUSAGE
Definition: cli.h:45
int ast_logger_create_channel(const char *log_channel, const char *components)
Create a log channel.
Definition: logger.c:1406
#define CLI_FAILURE
Definition: cli.h:46
char * command
Definition: cli.h:186
const char * usage
Definition: cli.h:177
#define CLI_SUCCESS
Definition: cli.h:44

◆ handle_logger_reload()

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

Definition at line 1203 of file logger.c.

References ast_cli_args::argc, ast_cli_args::argv, ast_cli(), CLI_FAILURE, CLI_GENERATE, CLI_INIT, CLI_SUCCESS, ast_cli_entry::command, ast_cli_args::fd, NULL, reload_logger(), and ast_cli_entry::usage.

1204 {
1205  switch (cmd) {
1206  case CLI_INIT:
1207  e->command = "logger reload";
1208  e->usage =
1209  "Usage: logger reload [<alt-conf>]\n"
1210  " Reloads the logger subsystem state. Use after restarting syslogd(8) if you are using syslog logging.\n";
1211  return NULL;
1212  case CLI_GENERATE:
1213  return NULL;
1214  }
1215  if (reload_logger(0, a->argc == 3 ? a->argv[2] : NULL)) {
1216  ast_cli(a->fd, "Failed to reload the logger\n");
1217  return CLI_FAILURE;
1218  }
1219  return CLI_SUCCESS;
1220 }
const int argc
Definition: cli.h:160
Definition: cli.h:152
#define NULL
Definition: resample.c:96
static int reload_logger(int rotate, const char *altconf)
Definition: logger.c:1128
void ast_cli(int fd, const char *fmt,...)
Definition: clicompat.c:6
const int fd
Definition: cli.h:159
const char *const * argv
Definition: cli.h:161
#define CLI_FAILURE
Definition: cli.h:46
char * command
Definition: cli.h:186
const char * usage
Definition: cli.h:177
#define CLI_SUCCESS
Definition: cli.h:44

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

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

1498 {
1499  struct logchannel *chan;
1500  int gen_count = 0;
1501  char *gen_ret = NULL;
1502 
1503  switch (cmd) {
1504  case CLI_INIT:
1505  e->command = "logger remove channel";
1506  e->usage =
1507  "Usage: logger remove channel <name>\n"
1508  " Removes a temporary logger channel.\n";
1509  return NULL;
1510  case CLI_GENERATE:
1511  if (a->argc > 4 || (a->argc == 4 && a->pos > 3)) {
1512  return NULL;
1513  }
1516  if (chan->dynamic && (ast_strlen_zero(a->argv[3])
1517  || !strncmp(a->argv[3], chan->filename, strlen(a->argv[3])))) {
1518  if (gen_count == a->n) {
1519  gen_ret = ast_strdup(chan->filename);
1520  break;
1521  }
1522  gen_count++;
1523  }
1524  }
1526  return gen_ret;
1527  }
1528 
1529  if (a->argc < 4) {
1530  return CLI_SHOWUSAGE;
1531  }
1532 
1533  switch (ast_logger_remove_channel(a->argv[3])) {
1534  case AST_LOGGER_SUCCESS:
1535  ast_cli(a->fd, "Removed dynamic logger channel '%s'\n", a->argv[3]);
1536  return CLI_SUCCESS;
1537  case AST_LOGGER_FAILURE:
1538  ast_cli(a->fd, "Unable to find dynamic logger channel '%s'\n", a->argv[3]);
1539  return CLI_SUCCESS;
1540  default:
1541  ast_cli(a->fd, "Internal failure attempting to delete dynamic logger channel '%s'\n", a->argv[3]);
1542  return CLI_FAILURE;
1543  }
1544 }
int ast_logger_remove_channel(const char *log_channel)
Delete the specified log channel.
Definition: logger.c:1472
const int argc
Definition: cli.h:160
#define AST_RWLIST_UNLOCK(head)
Attempts to unlock a read/write based list.
Definition: linkedlists.h:150
Definition: cli.h:152
#define ast_strdup(str)
A wrapper for strdup()
Definition: astmm.h:243
#define NULL
Definition: resample.c:96
void ast_cli(int fd, const char *fmt,...)
Definition: clicompat.c:6
#define AST_RWLIST_RDLOCK(head)
Read locks a list.
Definition: linkedlists.h:77
const int fd
Definition: cli.h:159
int dynamic
Definition: logger.c:151
const int n
Definition: cli.h:165
#define AST_RWLIST_TRAVERSE
Definition: linkedlists.h:493
const char *const * argv
Definition: cli.h:161
#define CLI_SHOWUSAGE
Definition: cli.h:45
#define ast_strlen_zero(a)
Definition: muted.c:73
#define CLI_FAILURE
Definition: cli.h:46
char * command
Definition: cli.h:186
const char * usage
Definition: cli.h:177
char filename[PATH_MAX]
Definition: logger.c:145
#define CLI_SUCCESS
Definition: cli.h:44
const int pos
Definition: cli.h:164
struct logchannel::@398 list

◆ handle_logger_rotate()

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

Definition at line 1222 of file logger.c.

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

1223 {
1224  switch (cmd) {
1225  case CLI_INIT:
1226  e->command = "logger rotate";
1227  e->usage =
1228  "Usage: logger rotate\n"
1229  " Rotates and Reopens the log files.\n";
1230  return NULL;
1231  case CLI_GENERATE:
1232  return NULL;
1233  }
1234  if (reload_logger(1, NULL)) {
1235  ast_cli(a->fd, "Failed to reload the logger and rotate log files\n");
1236  return CLI_FAILURE;
1237  }
1238  return CLI_SUCCESS;
1239 }
Definition: cli.h:152
#define NULL
Definition: resample.c:96
static int reload_logger(int rotate, const char *altconf)
Definition: logger.c:1128
void ast_cli(int fd, const char *fmt,...)
Definition: clicompat.c:6
const int fd
Definition: cli.h:159
#define CLI_FAILURE
Definition: cli.h:46
char * command
Definition: cli.h:186
const char * usage
Definition: cli.h:177
#define CLI_SUCCESS
Definition: cli.h:44

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

References ast_cli_args::argc, ast_cli_args::argv, 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, ast_cli_args::fd, NULL, state, and ast_cli_entry::usage.

1282 {
1283  int x;
1284  int state;
1285  int level = -1;
1286 
1287  switch (cmd) {
1288  case CLI_INIT:
1289  e->command = "logger set level {DEBUG|TRACE|NOTICE|WARNING|ERROR|VERBOSE|DTMF} {on|off}";
1290  e->usage =
1291  "Usage: logger set level {DEBUG|TRACE|NOTICE|WARNING|ERROR|VERBOSE|DTMF} {on|off}\n"
1292  " Set a specific log level to enabled/disabled for this console.\n";
1293  return NULL;
1294  case CLI_GENERATE:
1295  return NULL;
1296  }
1297 
1298  if (a->argc < 5)
1299  return CLI_SHOWUSAGE;
1300 
1302 
1303  for (x = 0; x < ARRAY_LEN(levels); x++) {
1304  if (levels[x] && !strcasecmp(a->argv[3], levels[x])) {
1305  level = x;
1306  break;
1307  }
1308  }
1309 
1311 
1312  state = ast_true(a->argv[4]) ? 1 : 0;
1313 
1314  if (level != -1) {
1315  ast_console_toggle_loglevel(a->fd, level, state);
1316  ast_cli(a->fd, "Logger status for '%s' has been set to '%s'.\n", levels[level], state ? "on" : "off");
1317  } else
1318  return CLI_SHOWUSAGE;
1319 
1320  return CLI_SUCCESS;
1321 }
enum sip_cc_notify_state state
Definition: chan_sip.c:960
#define ARRAY_LEN(a)
Definition: isdn_lib.c:42
#define AST_RWLIST_WRLOCK(head)
Write locks a list.
Definition: linkedlists.h:51
const int argc
Definition: cli.h:160
#define AST_RWLIST_UNLOCK(head)
Attempts to unlock a read/write based list.
Definition: linkedlists.h:150
Definition: cli.h:152
static char * levels[NUMLOGLEVELS]
Logging channels used in the Asterisk logging system.
Definition: logger.c:204
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:1209
#define NULL
Definition: resample.c:96
void ast_cli(int fd, const char *fmt,...)
Definition: clicompat.c:6
const int fd
Definition: cli.h:159
const char *const * argv
Definition: cli.h:161
int attribute_pure ast_true(const char *val)
Make sure something is true. Determine if a string containing a boolean value is "true". This function checks to see whether a string passed to it is an indication of an "true" value. It checks to see if the string is "yes", "true", "y", "t", "on" or "1".
Definition: main/utils.c:1822
#define CLI_SHOWUSAGE
Definition: cli.h:45
char * command
Definition: cli.h:186
const char * usage
Definition: cli.h:177
#define CLI_SUCCESS
Definition: cli.h:44

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

References 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, ast_cli_args::fd, logchannel::filename, FORMATL, logchannel::formatter, logchannel::list, logger_queue_limit, logchannel::logmask, LOGTYPE_CONSOLE, LOGTYPE_SYSLOG, logformatter::name, NULL, logchannel::type, and ast_cli_entry::usage.

1367 {
1368 #define FORMATL "%-35.35s %-8.8s %-10.10s %-9.9s "
1369  struct logchannel *chan;
1370  switch (cmd) {
1371  case CLI_INIT:
1372  e->command = "logger show channels";
1373  e->usage =
1374  "Usage: logger show channels\n"
1375  " List configured logger channels.\n";
1376  return NULL;
1377  case CLI_GENERATE:
1378  return NULL;
1379  }
1380  ast_cli(a->fd, "Logger queue limit: %d\n\n", logger_queue_limit);
1381  ast_cli(a->fd, FORMATL, "Channel", "Type", "Formatter", "Status");
1382  ast_cli(a->fd, "Configuration\n");
1383  ast_cli(a->fd, FORMATL, "-------", "----", "---------", "------");
1384  ast_cli(a->fd, "-------------\n");
1387  unsigned int level;
1388 
1389  ast_cli(a->fd, FORMATL, chan->filename, chan->type == LOGTYPE_CONSOLE ? "Console" : (chan->type == LOGTYPE_SYSLOG ? "Syslog" : "File"),
1390  chan->formatter.name,
1391  chan->disabled ? "Disabled" : "Enabled");
1392  ast_cli(a->fd, " - ");
1393  for (level = 0; level < ARRAY_LEN(levels); level++) {
1394  if ((chan->logmask & (1 << level)) && levels[level]) {
1395  ast_cli(a->fd, "%s ", levels[level]);
1396  }
1397  }
1398  ast_cli(a->fd, "\n");
1399  }
1401  ast_cli(a->fd, "\n");
1402 
1403  return CLI_SUCCESS;
1404 }
#define FORMATL
struct logformatter formatter
Definition: logger.c:131
#define ARRAY_LEN(a)
Definition: isdn_lib.c:42
#define AST_RWLIST_UNLOCK(head)
Attempts to unlock a read/write based list.
Definition: linkedlists.h:150
Definition: cli.h:152
static char * levels[NUMLOGLEVELS]
Logging channels used in the Asterisk logging system.
Definition: logger.c:204
#define NULL
Definition: resample.c:96
void ast_cli(int fd, const char *fmt,...)
Definition: clicompat.c:6
#define AST_RWLIST_RDLOCK(head)
Read locks a list.
Definition: linkedlists.h:77
const int fd
Definition: cli.h:159
unsigned int logmask
Definition: logger.c:133
#define AST_RWLIST_TRAVERSE
Definition: linkedlists.h:493
int disabled
Definition: logger.c:135
enum logtypes type
Definition: logger.c:141
char * command
Definition: cli.h:186
const char * name
Definition: logger.c:118
const char * usage
Definition: cli.h:177
char filename[PATH_MAX]
Definition: logger.c:145
#define CLI_SUCCESS
Definition: cli.h:44
struct logchannel::@398 list
static int logger_queue_limit
Definition: logger.c:92

◆ init_logger()

int init_logger ( void  )

Provided by logger.c

Definition at line 1857 of file logger.c.

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(), init_logger_chain(), logmsgs::lock, LOG_ERROR, logger_initialized, logger_thread(), and NULL.

Referenced by asterisk_daemon().

1858 {
1859  int res;
1860  /* auto rotate if sig SIGXFSZ comes a-knockin */
1861  sigaction(SIGXFSZ, &handle_SIGXFSZ, NULL);
1862 
1863  /* Re-initialize the logmsgs mutex. The recursive mutex can be accessed prior
1864  * to Asterisk being forked into the background, which can cause the thread
1865  * ID tracked by the underlying pthread mutex to be different than the ID of
1866  * the thread that unlocks the mutex. Since init_logger is called after the
1867  * fork, it is safe to initialize the mutex here for future accesses.
1868  */
1872 
1873  /* start logger thread */
1876  return -1;
1877  }
1878 
1879  /* register the logger cli commands */
1881 
1883 
1884  /* create log channels */
1886  res = init_logger_chain(NULL);
1888  ast_verb_update();
1889  logger_initialized = 1;
1890  if (res) {
1891  ast_log(LOG_ERROR, "Errors detected in logger.conf. Default console logging is being used.\n");
1892  }
1893 
1895 
1896  return 0;
1897 }
static struct ast_cli_entry cli_logger[]
Definition: logger.c:1546
static int init_logger_chain(const char *altconf)
Read config, setup channels.
Definition: logger.c:708
#define ARRAY_LEN(a)
Definition: isdn_lib.c:42
static struct sigaction handle_SIGXFSZ
Definition: logger.c:1561
static pthread_t logthread
Definition: logger.c:187
void ast_verb_update(void)
Re-evaluate the system max verbosity level (ast_verb_sys_level).
Definition: logger.c:2219
#define AST_RWLIST_WRLOCK(head)
Write locks a list.
Definition: linkedlists.h:51
#define AST_RWLIST_UNLOCK(head)
Attempts to unlock a read/write based list.
Definition: linkedlists.h:150
#define ast_cond_init(cond, attr)
Definition: lock.h:199
#define ast_cli_register_multiple(e, len)
Register multiple commands.
Definition: cli.h:265
#define NULL
Definition: resample.c:96
static int logger_initialized
Definition: logger.c:85
#define LOG_ERROR
Definition: logger.h:285
#define ast_cond_destroy(cond)
Definition: lock.h:200
const char * ast_config_AST_LOG_DIR
Definition: options.c:159
static void * logger_thread(void *data)
Actual logging thread.
Definition: logger.c:1748
#define ast_pthread_create(a, b, c, d)
Definition: utils.h:499
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:2088
#define ast_mutex_init(pmutex)
Definition: lock.h:184
#define ast_mutex_destroy(a)
Definition: lock.h:186
ast_mutex_t lock
Definition: logger.c:186
static ast_cond_t logcond
Definition: logger.c:188
int ast_mkdir(const char *path, int mode)
Recursively create directory path.
Definition: main/utils.c:2102
int ast_logger_category_load(void)
Load/Initialize system wide logger category functionality.

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

References __LOG_ERROR, ast_config_destroy(), ast_config_load2(), ast_console_puts_mutable(), ast_copy_string(), ast_free, AST_RWLIST_INSERT_HEAD, AST_RWLIST_REMOVE_HEAD, ast_true(), ast_variable_browse(), ast_variable_retrieve(), CONFIG_STATUS_FILEINVALID, dateformat, display_callids, errno, exec_after_rotate, global_logmask, hostname, ast_variable::lineno, logfiles, logger_queue_limit, logchannel::logmask, make_logchannel(), ast_variable::name, ast_variable::next, NONE, NULL, queue_log_name, QUEUELOG, ROTATE, S_OR, SEQUENTIAL, TIMESTAMP, ast_variable::value, and var.

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

709 {
710  struct logchannel *chan;
711  struct ast_config *cfg;
712  struct ast_variable *var;
713  const char *s;
714  struct ast_flags config_flags = { 0 };
715 
716  if (!(cfg = ast_config_load2(S_OR(altconf, "logger.conf"), "logger", config_flags)) || cfg == CONFIG_STATUS_FILEINVALID) {
717  cfg = NULL;
718  }
719 
720  /* Set defaults */
721  hostname[0] = '\0';
722  display_callids = 1;
723  memset(&logfiles, 0, sizeof(logfiles));
724  logfiles.queue_log = 1;
725  ast_copy_string(dateformat, "%b %e %T", sizeof(dateformat));
727  exec_after_rotate[0] = '\0';
729 
730  /* delete our list of log channels */
731  while ((chan = AST_RWLIST_REMOVE_HEAD(&logchannels, list))) {
732  ast_free(chan);
733  }
734  global_logmask = 0;
735 
736  errno = 0;
737  /* close syslog */
738  closelog();
739 
740  /* If no config file, we're fine, set default options. */
741  if (!cfg) {
742  chan = make_logchannel("console", "error,warning,notice,verbose", 0, 0);
743  if (!chan) {
744  fprintf(stderr, "ERROR: Failed to initialize default logging\n");
745  return -1;
746  }
747 
748  AST_RWLIST_INSERT_HEAD(&logchannels, chan, list);
749  global_logmask |= chan->logmask;
750 
751  return -1;
752  }
753 
754  if ((s = ast_variable_retrieve(cfg, "general", "appendhostname"))) {
755  if (ast_true(s)) {
756  if (gethostname(hostname, sizeof(hostname) - 1)) {
757  ast_copy_string(hostname, "unknown", sizeof(hostname));
758  fprintf(stderr, "What box has no hostname???\n");
759  }
760  }
761  }
762  if ((s = ast_variable_retrieve(cfg, "general", "display_callids"))) {
764  }
765  if ((s = ast_variable_retrieve(cfg, "general", "dateformat"))) {
767  }
768  if ((s = ast_variable_retrieve(cfg, "general", "queue_log"))) {
769  logfiles.queue_log = ast_true(s);
770  }
771  if ((s = ast_variable_retrieve(cfg, "general", "queue_log_to_file"))) {
772  logfiles.queue_log_to_file = ast_true(s);
773  }
774  if ((s = ast_variable_retrieve(cfg, "general", "queue_log_name"))) {
776  }
777  if ((s = ast_variable_retrieve(cfg, "general", "queue_log_realtime_use_gmt"))) {
778  logfiles.queue_log_realtime_use_gmt = ast_true(s);
779  }
780  if ((s = ast_variable_retrieve(cfg, "general", "exec_after_rotate"))) {
782  }
783  if ((s = ast_variable_retrieve(cfg, "general", "rotatestrategy"))) {
784  if (strcasecmp(s, "timestamp") == 0) {
786  } else if (strcasecmp(s, "rotate") == 0) {
788  } else if (strcasecmp(s, "sequential") == 0) {
790  } else if (strcasecmp(s, "none") == 0) {
792  } else {
793  fprintf(stderr, "Unknown rotatestrategy: %s\n", s);
794  }
795  } else {
796  if ((s = ast_variable_retrieve(cfg, "general", "rotatetimestamp"))) {
798  fprintf(stderr, "rotatetimestamp option has been deprecated. Please use rotatestrategy instead.\n");
799  }
800  }
801  if ((s = ast_variable_retrieve(cfg, "general", "logger_queue_limit"))) {
802  if (sscanf(s, "%30d", &logger_queue_limit) != 1) {
803  fprintf(stderr, "logger_queue_limit has an invalid value. Leaving at default of %d.\n",
805  }
806  if (logger_queue_limit < 10) {
807  fprintf(stderr, "logger_queue_limit must be >= 10. Setting to 10.\n");
808  logger_queue_limit = 10;
809  }
810  }
811 
812  var = ast_variable_browse(cfg, "logfiles");
813  for (; var; var = var->next) {
814  chan = make_logchannel(var->name, var->value, var->lineno, 0);
815  if (!chan) {
816  /* Print error message directly to the consoles since the lock is held
817  * and we don't want to unlock with the list partially built */
818  ast_console_puts_mutable("ERROR: Unable to create log channel '", __LOG_ERROR);
821  continue;
822  }
823  AST_RWLIST_INSERT_HEAD(&logchannels, chan, list);
824  global_logmask |= chan->logmask;
825  }
826 
827  if (qlog) {
828  fclose(qlog);
829  qlog = NULL;
830  }
831 
832  ast_config_destroy(cfg);
833 
834  return 0;
835 }
struct ast_variable * next
static struct @397 logfiles
static unsigned int global_logmask
Definition: logger.c:83
struct ast_variable * ast_variable_browse(const struct ast_config *config, const char *category_name)
Definition: extconf.c:1216
#define CONFIG_STATUS_FILEINVALID
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:3154
Structure for variables, used for configurations and for channel variables.
#define var
Definition: ast_expr2f.c:614
#define __LOG_ERROR
Definition: logger.h:284
#define NULL
Definition: resample.c:96
static FILE * qlog
Definition: logger.c:191
Definition: logger.c:99
#define AST_RWLIST_INSERT_HEAD
Definition: linkedlists.h:717
unsigned int logmask
Definition: logger.c:133
void ast_config_destroy(struct ast_config *config)
Destroys a config.
Definition: extconf.c:1290
static char queue_log_name[256]
Definition: logger.c:79
static char exec_after_rotate[256]
Definition: logger.c:80
int attribute_pure ast_true(const char *val)
Make sure something is true. Determine if a string containing a boolean value is "true". This function checks to see whether a string passed to it is an indication of an "true" value. It checks to see if the string is "yes", "true", "y", "t", "on" or "1".
Definition: main/utils.c:1822
int errno
static struct logchannel * make_logchannel(const char *channel, const char *components, int lineno, int dynamic)
Definition: logger.c:615
#define ast_free(a)
Definition: astmm.h:182
#define AST_RWLIST_REMOVE_HEAD
Definition: linkedlists.h:843
void ast_console_puts_mutable(const char *string, int level)
log the string to the console, and all attached console clients
Definition: asterisk.c:1274
Structure used to handle boolean flags.
Definition: utils.h:199
const char * ast_variable_retrieve(struct ast_config *config, const char *category, const char *variable)
Definition: main/config.c:694
static char dateformat[256]
Definition: logger.c:77
rotatestrategy
Definition: logger.c:96
static int display_callids
Definition: logger.c:87
void ast_copy_string(char *dst, const char *src, size_t size)
Size-limited null-terminating string copy.
Definition: strings.h:401
#define S_OR(a, b)
returns the equivalent of logic or for strings: first one if not empty, otherwise second one...
Definition: strings.h:79
Definition: logger.c:97
static int logger_queue_limit
Definition: logger.c:92
#define QUEUELOG
Definition: logger.h:35
static char hostname[MAXHOSTNAMELEN]
Definition: logger.c:110

◆ load_module()

static int load_module ( void  )
static

◆ logger_add_verbose_magic()

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

Definition at line 317 of file logger.c.

References ast_str_append(), ast_str_append_substr(), ast_str_buffer(), ast_str_reset(), ast_str_thread_get(), 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().

318 {
319  const char *p;
320  const char *fmt;
321  struct ast_str *prefixed;
322  signed char magic = logmsg->sublevel > 9 ? -10 : -logmsg->sublevel - 1; /* 0 => -1, 1 => -2, etc. Can't pass NUL, as it is EOS-delimiter */
323 
324  /* For compatibility with modules still calling ast_verbose() directly instead of using ast_verb() */
325  if (logmsg->sublevel < 0) {
326  if (!strncmp(logmsg->message, VERBOSE_PREFIX_4, strlen(VERBOSE_PREFIX_4))) {
327  magic = -5;
328  } else if (!strncmp(logmsg->message, VERBOSE_PREFIX_3, strlen(VERBOSE_PREFIX_3))) {
329  magic = -4;
330  } else if (!strncmp(logmsg->message, VERBOSE_PREFIX_2, strlen(VERBOSE_PREFIX_2))) {
331  magic = -3;
332  } else if (!strncmp(logmsg->message, VERBOSE_PREFIX_1, strlen(VERBOSE_PREFIX_1))) {
333  magic = -2;
334  } else {
335  magic = -1;
336  }
337  }
338 
340  return -1;
341  }
342 
343  ast_str_reset(prefixed);
344 
345  /* for every newline found in the buffer add verbose prefix data */
346  fmt = logmsg->message;
347  do {
348  if (!(p = strchr(fmt, '\n'))) {
349  p = strchr(fmt, '\0') - 1;
350  }
351  ++p;
352 
353  ast_str_append(&prefixed, 0, "%c", (char)magic);
354  ast_str_append_substr(&prefixed, 0, fmt, p - fmt);
355  fmt = p;
356  } while (p && *p);
357 
358  snprintf(buf, size, "%s", ast_str_buffer(prefixed));
359 
360  return 0;
361 }
#define VERBOSE_PREFIX_1
Definition: logger.h:41
char buf[BUFSIZE]
Definition: eagi_proxy.c:66
#define VERBOSE_PREFIX_3
Definition: logger.h:43
char * ast_str_buffer(const struct ast_str *buf)
Returns the string buffer within the ast_str buf.
Definition: strings.h:714
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:1091
#define VERBOSE_BUF_INIT_SIZE
Definition: logger.c:252
#define VERBOSE_PREFIX_4
Definition: logger.h:44
#define VERBOSE_PREFIX_2
Definition: logger.h:42
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:1014
The descriptor of a dynamic string XXX storage will be optimized later if needed We use the ts field ...
Definition: strings.h:584
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:653
const ast_string_field message
Definition: logger.c:176
static struct ast_threadstorage verbose_buf
Definition: logger.c:250
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:861
int sublevel
Definition: logger.c:166

◆ logger_print_normal()

static void logger_print_normal ( struct logmsg logmsg)
static

Print a normal log message to the channels.

Definition at line 1567 of file logger.c.

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

1568 {
1569  struct logchannel *chan = NULL;
1570  char buf[BUFSIZ];
1571  int level = 0;
1572 
1574  if (!AST_RWLIST_EMPTY(&logchannels)) {
1576 
1577  /* If the channel is disabled, then move on to the next one */
1578  if (chan->disabled) {
1579  continue;
1580  }
1581  if (logmsg->level == __LOG_VERBOSE
1582  && (((chan->verbosity < 0) ? option_verbose : chan->verbosity)) < level) {
1583  continue;
1584  }
1585 
1586  if (!(chan->logmask & (1 << logmsg->level))) {
1587  continue;
1588  }
1589 
1590  switch (chan->type) {
1591  case LOGTYPE_SYSLOG:
1592  {
1593  int syslog_level = ast_syslog_priority_from_loglevel(logmsg->level);
1594 
1595  if (syslog_level < 0) {
1596  /* we are locked here, so cannot ast_log() */
1597  fprintf(stderr, "ast_log_vsyslog called with bogus level: %d\n", logmsg->level);
1598  continue;
1599  }
1600 
1601  /* Don't use LOG_MAKEPRI because it's broken in glibc<2.17 */
1602  syslog_level = chan->facility | syslog_level; /* LOG_MAKEPRI(chan->facility, syslog_level); */
1603  if (!chan->formatter.format_log(chan, logmsg, buf, BUFSIZ)) {
1604  syslog(syslog_level, "%s", buf);
1605  }
1606  }
1607  break;
1608  case LOGTYPE_CONSOLE:
1609  if (!chan->formatter.format_log(chan, logmsg, buf, BUFSIZ)) {
1610  ast_console_puts_mutable_full(buf, logmsg->level, logmsg->sublevel);
1611  }
1612  break;
1613  case LOGTYPE_FILE:
1614  {
1615  int res = 0;
1616 
1617  if (!chan->fileptr) {
1618  continue;
1619  }
1620 
1621  if (chan->formatter.format_log(chan, logmsg, buf, BUFSIZ)) {
1622  continue;
1623  }
1624 
1625  /* Print out to the file */
1626  res = fprintf(chan->fileptr, "%s", buf);
1627  if (res > 0) {
1628  fflush(chan->fileptr);
1629  } else if (res <= 0 && !ast_strlen_zero(logmsg->message)) {
1630  fprintf(stderr, "**** Asterisk Logging Error: ***********\n");
1631  if (errno == ENOMEM || errno == ENOSPC) {
1632  fprintf(stderr, "Asterisk logging error: Out of disk space, can't log to log file %s\n", chan->filename);
1633  } else {
1634  fprintf(stderr, "Logger Warning: Unable to write to log file '%s': %s (disabled)\n", chan->filename, strerror(errno));
1635  }
1636 
1637  /*** DOCUMENTATION
1638  <managerEventInstance>
1639  <synopsis>Raised when a logging channel is disabled.</synopsis>
1640  <syntax>
1641  <parameter name="Channel">
1642  <para>The name of the logging channel.</para>
1643  </parameter>
1644  </syntax>
1645  </managerEventInstance>
1646  ***/
1647  manager_event(EVENT_FLAG_SYSTEM, "LogChannel", "Channel: %s\r\nEnabled: No\r\nReason: %d - %s\r\n", chan->filename, errno, strerror(errno));
1648  chan->disabled = 1;
1649  }
1650  }
1651  break;
1652  }
1653  }
1654  } else if (logmsg->level != __LOG_VERBOSE || option_verbose >= logmsg->sublevel) {
1655  fputs(logmsg->message, stdout);
1656  }
1657 
1659 
1660  /* If we need to reload because of the file size, then do so */
1661  if (filesize_reload_needed) {
1662  reload_logger(-1, NULL);
1663  ast_verb(1, "Rotated Logs Per SIGXFSZ (Exceeded file size limit)\n");
1664  }
1665 
1666  return;
1667 }
struct logformatter formatter
Definition: logger.c:131
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:1281
int facility
Definition: logger.c:137
char buf[BUFSIZE]
Definition: eagi_proxy.c:66
#define AST_RWLIST_UNLOCK(head)
Attempts to unlock a read/write based list.
Definition: linkedlists.h:150
int option_verbose
Definition: options.c:67
#define NULL
Definition: resample.c:96
static int reload_logger(int rotate, const char *altconf)
Definition: logger.c:1128
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
#define ast_verb(level,...)
Definition: logger.h:455
int verbosity
Definition: logger.c:139
static int filesize_reload_needed
Definition: logger.c:82
#define AST_RWLIST_RDLOCK(head)
Read locks a list.
Definition: linkedlists.h:77
#define EVENT_FLAG_SYSTEM
Definition: manager.h:71
unsigned int logmask
Definition: logger.c:133
#define AST_RWLIST_TRAVERSE
Definition: linkedlists.h:493
int level
Definition: logger.c:165
int(*const format_log)(struct logchannel *channel, struct logmsg *msg, char *buf, size_t size)
Definition: logger.c:120
int disabled
Definition: logger.c:135
#define AST_RWLIST_EMPTY
Definition: linkedlists.h:451
int errno
enum logtypes type
Definition: logger.c:141
#define ast_strlen_zero(a)
Definition: muted.c:73
FILE * fileptr
Definition: logger.c:143
char filename[PATH_MAX]
Definition: logger.c:145
#define __LOG_VERBOSE
Definition: logger.h:295
const ast_string_field message
Definition: logger.c:176
struct logchannel::@398 list
#define manager_event(category, event, contents,...)
External routines may send asterisk manager events this way.
Definition: manager.h:248
int sublevel
Definition: logger.c:166

◆ logger_queue_init()

static void logger_queue_init ( void  )
static

Definition at line 1804 of file logger.c.

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

Referenced by logger_queue_start().

1805 {
1806  ast_unload_realtime("queue_log");
1807  if (logfiles.queue_log) {
1808  char qfname[PATH_MAX];
1809 
1810  if (logger_queue_rt_start()) {
1811  return;
1812  }
1813 
1814  /* Open the log file. */
1815  snprintf(qfname, sizeof(qfname), "%s/%s", ast_config_AST_LOG_DIR,
1816  queue_log_name);
1817  if (qlog) {
1818  /* Just in case it was already open. */
1819  fclose(qlog);
1820  }
1821  qlog = fopen(qfname, "a");
1822  if (!qlog) {
1823  ast_log(LOG_ERROR, "Unable to create queue log: %s\n", strerror(errno));
1824  }
1825  }
1826 }
static struct @397 logfiles
int ast_unload_realtime(const char *family)
Release any resources cached for a realtime family.
Definition: main/config.c:3406
static FILE * qlog
Definition: logger.c:191
static int logger_queue_rt_start(void)
Definition: logger.c:1065
static char queue_log_name[256]
Definition: logger.c:79
#define LOG_ERROR
Definition: logger.h:285
int errno
const char * ast_config_AST_LOG_DIR
Definition: options.c:159
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:2088
#define PATH_MAX
Definition: asterisk.h:40

◆ logger_queue_restart()

static int logger_queue_restart ( int  queue_rotate)
static

Definition at line 1100 of file logger.c.

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

Referenced by reload_logger().

1101 {
1102  int res = 0;
1103  char qfname[PATH_MAX];
1104 
1105  if (logger_queue_rt_start()) {
1106  return res;
1107  }
1108 
1109  snprintf(qfname, sizeof(qfname), "%s/%s", ast_config_AST_LOG_DIR, queue_log_name);
1110  if (qlog) {
1111  /* Just in case it was still open. */
1112  fclose(qlog);
1113  qlog = NULL;
1114  }
1115  if (queue_rotate) {
1116  rotate_file(qfname);
1117  }
1118 
1119  /* Open the log file. */
1120  qlog = fopen(qfname, "a");
1121  if (!qlog) {
1122  ast_log(LOG_ERROR, "Unable to create queue log: %s\n", strerror(errno));
1123  res = -1;
1124  }
1125  return res;
1126 }
static int rotate_file(const char *filename)
Definition: logger.c:961
#define NULL
Definition: resample.c:96
static FILE * qlog
Definition: logger.c:191
static int logger_queue_rt_start(void)
Definition: logger.c:1065
static char queue_log_name[256]
Definition: logger.c:79
#define LOG_ERROR
Definition: logger.h:285
int errno
const char * ast_config_AST_LOG_DIR
Definition: options.c:159
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:2088
#define PATH_MAX
Definition: asterisk.h:40

◆ logger_queue_rt_start()

static int logger_queue_rt_start ( void  )
static

Definition at line 1065 of file logger.c.

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

Referenced by logger_queue_init(), and logger_queue_restart().

1066 {
1067  if (ast_check_realtime("queue_log")) {
1068  if (!ast_realtime_require_field("queue_log",
1069  "time", RQ_DATETIME, 26,
1070  "data1", RQ_CHAR, 20,
1071  "data2", RQ_CHAR, 20,
1072  "data3", RQ_CHAR, 20,
1073  "data4", RQ_CHAR, 20,
1074  "data5", RQ_CHAR, 20,
1075  SENTINEL)) {
1076  logfiles.queue_adaptive_realtime = 1;
1077  } else {
1078  logfiles.queue_adaptive_realtime = 0;
1079  }
1080 
1081  if (!logfiles.queue_log_to_file) {
1082  /* Don't open the log file. */
1083  return 1;
1084  }
1085  }
1086  return 0;
1087 }
static struct @397 logfiles
int ast_check_realtime(const char *family)
Check if realtime engine is configured for family.
Definition: main/config.c:3363
#define SENTINEL
Definition: compiler.h:87
int ast_realtime_require_field(const char *family,...) attribute_sentinel
Inform realtime what fields that may be stored.
Definition: main/config.c:3382

◆ 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.
Returns
Nothing

Definition at line 1841 of file logger.c.

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

1842 {
1843  /* Must not be called before the logger is initialized. */
1845 
1847  if (!queuelog_init) {
1849  queuelog_init = 1;
1851  ast_queue_log("NONE", "NONE", "NONE", "QUEUESTART", "%s", "");
1852  } else {
1854  }
1855 }
static int queuelog_init
Definition: logger.c:84
#define AST_RWLIST_WRLOCK(head)
Write locks a list.
Definition: linkedlists.h:51
#define AST_RWLIST_UNLOCK(head)
Attempts to unlock a read/write based list.
Definition: linkedlists.h:150
#define ast_assert(a)
Definition: utils.h:650
void ast_queue_log(const char *queuename, const char *callid, const char *agent, const char *event, const char *fmt,...)
Definition: logger.c:881
static int logger_initialized
Definition: logger.c:85
static void logger_queue_init(void)
Definition: logger.c:1804

◆ logger_thread()

static void* logger_thread ( void *  data)
static

Actual logging thread.

Definition at line 1748 of file logger.c.

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, format_log_message(), high_water_alert, logmsg::list, logmsgs::lock, logger_messages_discarded, logger_print_normal(), logger_queue_size, logmsg_free(), logmsg::next, and NULL.

Referenced by init_logger().

1749 {
1750  struct logmsg *next = NULL, *msg = NULL;
1751 
1752  for (;;) {
1753  /* We lock the message list, and see if any message exists... if not we wait on the condition to be signalled */
1755  if (AST_LIST_EMPTY(&logmsgs)) {
1756  if (close_logger_thread) {
1758  break;
1759  } else {
1761  }
1762  }
1763 
1764  if (high_water_alert) {
1765  msg = format_log_message(__LOG_WARNING, 0, "logger", 0, "***", 0,
1766  "Logging resumed. %d message%s discarded.\n",
1768  if (msg) {
1770  }
1771  high_water_alert = 0;
1773  }
1774 
1775  next = AST_LIST_FIRST(&logmsgs);
1777  logger_queue_size = 0;
1779 
1780  /* Otherwise go through and process each message in the order added */
1781  while ((msg = next)) {
1782  /* Get the next entry now so that we can free our current structure later */
1783  next = AST_LIST_NEXT(msg, list);
1784 
1785  /* Depending on the type, send it to the proper function */
1786  logger_print_normal(msg);
1787 
1788  /* Free the data since we are done */
1789  logmsg_free(msg);
1790  }
1791  }
1792 
1793  return NULL;
1794 }
static void logger_print_normal(struct logmsg *logmsg)
Print a normal log message to the channels.
Definition: logger.c:1567
#define AST_LIST_LOCK(head)
Locks a list.
Definition: linkedlists.h:39
#define AST_LIST_FIRST(head)
Returns the first entry contained in a list.
Definition: linkedlists.h:420
static void logmsg_free(struct logmsg *msg)
Definition: logger.c:180
#define AST_LIST_UNLOCK(head)
Attempts to unlock a list.
Definition: linkedlists.h:139
#define AST_LIST_NEXT(elm, field)
Returns the next entry in the list after the given entry.
Definition: linkedlists.h:438
struct logmsg * next
Definition: logger.c:177
#define ast_cond_wait(cond, mutex)
Definition: lock.h:203
struct logmsg::@399 list
#define __LOG_WARNING
Definition: logger.h:273
#define AST_LIST_EMPTY(head)
Checks whether the specified list contains any entries.
Definition: linkedlists.h:449
#define NULL
Definition: resample.c:96
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:1733
Definition: logger.c:163
static unsigned int high_water_alert
Definition: logger.c:94
#define AST_LIST_INSERT_TAIL(head, elm, field)
Appends a list entry to the tail of a list.
Definition: linkedlists.h:730
#define AST_LIST_HEAD_INIT_NOLOCK(head)
Initializes a list head structure.
Definition: linkedlists.h:680
static int logger_queue_size
Definition: logger.c:89
static int close_logger_thread
Definition: logger.c:189
ast_mutex_t lock
Definition: logger.c:186
static int logger_messages_discarded
Definition: logger.c:93
static ast_cond_t logcond
Definition: logger.c:188

◆ logmsg_free()

static void logmsg_free ( struct logmsg msg)
static

Definition at line 180 of file logger.c.

References ast_free, and ast_string_field_free_memory.

Referenced by ast_log_full(), and logger_thread().

181 {
183  ast_free(msg);
184 }
#define ast_free(a)
Definition: astmm.h:182
#define ast_string_field_free_memory(x)
free all memory - to be called before destroying the object
Definition: stringfields.h:368

◆ make_components()

static void make_components ( struct logchannel chan)
static

Definition at line 477 of file logger.c.

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

Referenced by make_logchannel(), and update_logchannels().

478 {
479  char *w;
480  unsigned int logmask = 0;
481  char *stringp = ast_strdupa(chan->components);
482  unsigned int x;
483  unsigned int verb_level;
484 
485  /* Default to using option_verbose as the verbosity level of the logging channel. */
486  verb_level = -1;
487 
488  w = strchr(stringp, '[');
489  if (w) {
490  char *end = strchr(w + 1, ']');
491  if (!end) {
492  fprintf(stderr, "Logger Warning: bad formatter definition for %s in logger.conf\n", chan->filename);
493  } else {
494  char *formatter_name = w + 1;
495 
496  *end = '\0';
497  stringp = end + 1;
498 
499  if (!strcasecmp(formatter_name, "json")) {
500  memcpy(&chan->formatter, &logformatter_json, sizeof(chan->formatter));
501  } else if (!strcasecmp(formatter_name, "default")) {
502  memcpy(&chan->formatter, &logformatter_default, sizeof(chan->formatter));
503  } else if (!strcasecmp(formatter_name, "plain")) {
504  memcpy(&chan->formatter, &logformatter_plain, sizeof(chan->formatter));
505  } else {
506  fprintf(stderr, "Logger Warning: Unknown formatter definition %s for %s in logger.conf; using 'default'\n",
507  formatter_name, chan->filename);
508  memcpy(&chan->formatter, &logformatter_default, sizeof(chan->formatter));
509  }
510  }
511  }
512 
513  if (!chan->formatter.name) {
514  memcpy(&chan->formatter, &logformatter_default, sizeof(chan->formatter));
515  }
516 
517  while ((w = strsep(&stringp, ","))) {
518  w = ast_strip(w);
519  if (ast_strlen_zero(w)) {
520  continue;
521  }
522  if (!strcmp(w, "*")) {
523  logmask = 0xFFFFFFFF;
524  } else if (!strncasecmp(w, "verbose(", 8)) {
525  if (levels[__LOG_VERBOSE] && sscanf(w + 8, "%30u)", &verb_level) == 1) {
526  logmask |= (1 << __LOG_VERBOSE);
527  }
528  } else {
529  for (x = 0; x < ARRAY_LEN(levels); ++x) {
530  if (levels[x] && !strcasecmp(w, levels[x])) {
531  logmask |= (1 << x);
532  break;
533  }
534  }
535  }
536  }
537  if (chan->type == LOGTYPE_CONSOLE) {
538  /*
539  * Force to use the root console verbose level so if the
540  * user specified any verbose level then it does not interfere
541  * with calculating the ast_verb_sys_level value.
542  */
543  chan->verbosity = -1;
544  logmask |= (1 << __LOG_VERBOSE);
545  } else {
546  chan->verbosity = verb_level;
547  }
548  chan->logmask = logmask;
549 }
struct logformatter formatter
Definition: logger.c:131
#define ARRAY_LEN(a)
Definition: isdn_lib.c:42
char components[0]
Definition: logger.c:153
static char * levels[NUMLOGLEVELS]
Logging channels used in the Asterisk logging system.
Definition: logger.c:204
char * end
Definition: eagi_proxy.c:73
int verbosity
Definition: logger.c:139
static struct logformatter logformatter_json
Definition: logger.c:312
static struct logformatter logformatter_plain
Definition: logger.c:472
unsigned int logmask
Definition: logger.c:133
char * ast_strip(char *s)
Strip leading/trailing whitespace from a string.
Definition: strings.h:219
#define ast_strdupa(s)
duplicate a string in memory from the stack
Definition: astmm.h:300
enum logtypes type
Definition: logger.c:141
#define ast_strlen_zero(a)
Definition: muted.c:73
static struct logformatter logformatter_default
Definition: logger.c:422
const char * name
Definition: logger.c:118
char filename[PATH_MAX]
Definition: logger.c:145
char * strsep(char **str, const char *delims)
#define __LOG_VERBOSE
Definition: logger.h:295

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

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

559 {
560  const char *log_dir_prefix = "";
561  const char *log_dir_separator = "";
562 
563  *filename = '\0';
564 
565  if (!strcasecmp(channel, "console")) {
566  return;
567  }
568 
569  if (!strncasecmp(channel, "syslog", 6)) {
570  ast_copy_string(filename, channel, size);
571  return;
572  }
573 
574  /* It's a filename */
575 
576  if (channel[0] != '/') {
577  log_dir_prefix = ast_config_AST_LOG_DIR;
578  log_dir_separator = "/";
579  }
580 
581  if (!ast_strlen_zero(hostname)) {
582  snprintf(filename, size, "%s%s%s.%s",
583  log_dir_prefix, log_dir_separator, channel, hostname);
584  } else {
585  snprintf(filename, size, "%s%s%s",
586  log_dir_prefix, log_dir_separator, channel);
587  }
588 }
Definition: muted.c:95
const char * ast_config_AST_LOG_DIR
Definition: options.c:159
#define ast_strlen_zero(a)
Definition: muted.c:73
void ast_copy_string(char *dst, const char *src, size_t size)
Size-limited null-terminating string copy.
Definition: strings.h:401
static char hostname[MAXHOSTNAMELEN]
Definition: logger.c:110

◆ make_logchannel()

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

Definition at line 615 of file logger.c.

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

616 {
617  struct logchannel *chan;
618  char *facility;
619  struct ast_tm tm;
620  struct timeval now = ast_tvnow();
621  char datestring[256];
622 
623  if (ast_strlen_zero(channel) || !(chan = ast_calloc(1, sizeof(*chan) + strlen(components) + 1)))
624  return NULL;
625 
626  strcpy(chan->components, components);
627  chan->lineno = lineno;
628  chan->dynamic = dynamic;
629 
630  make_filename(channel, chan->filename, sizeof(chan->filename));
631 
632  if (!strcasecmp(channel, "console")) {
633  chan->type = LOGTYPE_CONSOLE;
634  } else if (!strncasecmp(channel, "syslog", 6)) {
635  /*
636  * syntax is:
637  * syslog.facility => level,level,level
638  */
639  facility = strchr(channel, '.');
640  if (!facility++ || !facility) {
641  facility = "local0";
642  }
643 
644  chan->facility = ast_syslog_facility(facility);
645 
646  if (chan->facility < 0) {
647  fprintf(stderr, "Logger Warning: bad syslog facility in logger.conf\n");
648  ast_free(chan);
649  return NULL;
650  }
651 
652  chan->type = LOGTYPE_SYSLOG;
653  openlog("asterisk", LOG_PID, chan->facility);
654  } else {
655  if (!(chan->fileptr = fopen(chan->filename, "a"))) {
656  /* Can't do real logging here since we're called with a lock
657  * so log to any attached consoles */
658  ast_console_puts_mutable("ERROR: Unable to open log file '", __LOG_ERROR);
663  ast_free(chan);
664  return NULL;
665  } else {
666  /* Create our date/time */
667  ast_localtime(&now, &tm, NULL);
668  ast_strftime(datestring, sizeof(datestring), dateformat, &tm);
669 
670  fprintf(chan->fileptr, "[%s] Asterisk %s built by %s @ %s on a %s running %s on %s\n",
673  fflush(chan->fileptr);
674  }
675  chan->type = LOGTYPE_FILE;
676  }
677  make_components(chan);
678 
679  return chan;
680 }
const char * ast_build_user
Definition: buildinfo.c:34
int facility
Definition: logger.c:137
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:558
const char * ast_get_version(void)
Retrieve the Asterisk version string.
char components[0]
Definition: logger.c:153
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
const char * ast_build_date
Definition: buildinfo.c:33
const char * ast_build_os
Definition: buildinfo.c:32
struct timeval ast_tvnow(void)
Returns current timeval. Meant to replace calls to gettimeofday().
Definition: time.h:150
Definition: muted.c:95
#define __LOG_ERROR
Definition: logger.h:284
#define NULL
Definition: resample.c:96
static void make_components(struct logchannel *chan)
Definition: logger.c:477
const char * ast_build_hostname
Definition: buildinfo.c:29
const char * ast_build_machine
Definition: buildinfo.c:31
int dynamic
Definition: logger.c:151
int errno
enum logtypes type
Definition: logger.c:141
#define ast_strlen_zero(a)
Definition: muted.c:73
#define ast_free(a)
Definition: astmm.h:182
#define ast_calloc(num, len)
A wrapper for calloc()
Definition: astmm.h:204
void ast_console_puts_mutable(const char *string, int level)
log the string to the console, and all attached console clients
Definition: asterisk.c:1274
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
FILE * fileptr
Definition: logger.c:143
char filename[PATH_MAX]
Definition: logger.c:145
static char dateformat[256]
Definition: logger.c:77
int lineno
Definition: logger.c:149
int ast_syslog_facility(const char *facility)
Maps a syslog facility name from a string to a syslog facility constant.
Definition: syslog.c:85

◆ reload_logger()

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

Definition at line 1128 of file logger.c.

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

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

1129 {
1130  int queue_rotate = rotate;
1131  struct logchannel *f;
1132  int res = 0;
1133 
1135 
1136  if (qlog) {
1137  if (rotate < 0) {
1138  /* Check filesize - this one typically doesn't need an auto-rotate */
1139  if (ftello(qlog) > 0x40000000) { /* Arbitrarily, 1 GB */
1140  fclose(qlog);
1141  qlog = NULL;
1142  } else {
1143  queue_rotate = 0;
1144  }
1145  } else {
1146  fclose(qlog);
1147  qlog = NULL;
1148  }
1149  } else {
1150  queue_rotate = 0;
1151  }
1152 
1154 
1156  if (f->disabled) {
1157  f->disabled = 0; /* Re-enable logging at reload */
1158  /*** DOCUMENTATION
1159  <managerEventInstance>
1160  <synopsis>Raised when a logging channel is re-enabled after a reload operation.</synopsis>
1161  <syntax>
1162  <parameter name="Channel">
1163  <para>The name of the logging channel.</para>
1164  </parameter>
1165  </syntax>
1166  </managerEventInstance>
1167  ***/
1168  manager_event(EVENT_FLAG_SYSTEM, "LogChannel", "Channel: %s\r\nEnabled: Yes\r\n", f->filename);
1169  }
1170  if (f->fileptr && (f->fileptr != stdout) && (f->fileptr != stderr)) {
1171  int rotate_this = 0;
1172  if (rotatestrategy != NONE && ftello(f->fileptr) > 0x40000000) { /* Arbitrarily, 1 GB */
1173  /* Be more proactive about rotating massive log files */
1174  rotate_this = 1;
1175  }
1176  fclose(f->fileptr); /* Close file */
1177  f->fileptr = NULL;
1178  if (rotate || rotate_this) {
1179  rotate_file(f->filename);
1180  }
1181  }
1182  }
1183 
1185 
1186  init_logger_chain(altconf);
1187 
1188  ast_unload_realtime("queue_log");
1189  if (logfiles.queue_log) {
1190  res = logger_queue_restart(queue_rotate);
1192  ast_verb_update();
1193  ast_queue_log("NONE", "NONE", "NONE", "CONFIGRELOAD", "%s", "");
1194  ast_verb(1, "Asterisk Queue Logger restarted\n");
1195  } else {
1197  ast_verb_update();
1198  }
1199 
1200  return res;
1201 }
static int init_logger_chain(const char *altconf)
Read config, setup channels.
Definition: logger.c:708
static struct @397 logfiles
static int rotate_file(const char *filename)
Definition: logger.c:961
void ast_verb_update(void)
Re-evaluate the system max verbosity level (ast_verb_sys_level).
Definition: logger.c:2219
#define AST_RWLIST_WRLOCK(head)
Write locks a list.
Definition: linkedlists.h:51
int ast_unload_realtime(const char *family)
Release any resources cached for a realtime family.
Definition: main/config.c:3406
#define AST_RWLIST_UNLOCK(head)
Attempts to unlock a read/write based list.
Definition: linkedlists.h:150
#define NULL
Definition: resample.c:96
static FILE * qlog
Definition: logger.c:191
#define ast_verb(level,...)
Definition: logger.h:455
void ast_queue_log(const char *queuename, const char *callid, const char *agent, const char *event, const char *fmt,...)
Definition: logger.c:881
static int filesize_reload_needed
Definition: logger.c:82
#define EVENT_FLAG_SYSTEM
Definition: manager.h:71
#define AST_RWLIST_TRAVERSE
Definition: linkedlists.h:493
int disabled
Definition: logger.c:135
const char * ast_config_AST_LOG_DIR
Definition: options.c:159
FILE * fileptr
Definition: logger.c:143
char filename[PATH_MAX]
Definition: logger.c:145
rotatestrategy
Definition: logger.c:96
Definition: logger.c:97
struct logchannel::@398 list
static int logger_queue_restart(int queue_rotate)
Definition: logger.c:1100
#define manager_event(category, event, contents,...)
External routines may send asterisk manager events this way.
Definition: manager.h:248
int ast_mkdir(const char *path, int mode)
Recursively create directory path.
Definition: main/utils.c:2102

◆ reload_module()

static int reload_module ( void  )
static

Definition at line 2552 of file logger.c.

References NULL, and reload_logger().

Referenced by load_module().

2553 {
2554  return reload_logger(0, NULL);
2555 }
#define NULL
Definition: resample.c:96
static int reload_logger(int rotate, const char *altconf)
Definition: logger.c:1128

◆ rotate_file()

static int rotate_file ( const char *  filename)
static

Definition at line 961 of file logger.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().

962 {
963  char old[PATH_MAX];
964  char new[PATH_MAX];
965  int x, y, which, found, res = 0, fd;
966  char *suffixes[4] = { "", ".gz", ".bz2", ".Z" };
967 
968  switch (rotatestrategy) {
969  case NONE:
970  /* No rotation */
971  break;
972  case SEQUENTIAL:
973  for (x = 0; ; x++) {
974  snprintf(new, sizeof(new), "%s.%d", filename, x);
975  fd = open(new, O_RDONLY);
976  if (fd > -1)
977  close(fd);
978  else
979  break;
980  }
981  if (rename(filename, new)) {
982  fprintf(stderr, "Unable to rename file '%s' to '%s'\n", filename, new);
983  res = -1;
984  } else {
985  filename = new;
986  }
987  break;
988  case TIMESTAMP:
989  snprintf(new, sizeof(new), "%s.%ld", filename, (long)time(NULL));
990  if (rename(filename, new)) {
991  fprintf(stderr, "Unable to rename file '%s' to '%s'\n", filename, new);
992  res = -1;
993  } else {
994  filename = new;
995  }
996  break;
997  case ROTATE:
998  /* Find the next empty slot, including a possible suffix */
999  for (x = 0; ; x++) {
1000  found = 0;
1001  for (which = 0; which < ARRAY_LEN(suffixes); which++) {
1002  snprintf(new, sizeof(new), "%s.%d%s", filename, x, suffixes[which]);
1003  fd = open(new, O_RDONLY);
1004  if (fd > -1) {
1005  close(fd);
1006  found = 1;
1007  break;
1008  }
1009  }
1010  if (!found) {
1011  break;
1012  }
1013  }
1014 
1015  /* Found an empty slot */
1016  for (y = x; y > 0; y--) {
1017  for (which = 0; which < ARRAY_LEN(suffixes); which++) {
1018  snprintf(old, sizeof(old), "%s.%d%s", filename, y - 1, suffixes[which]);
1019  fd = open(old, O_RDONLY);
1020  if (fd > -1) {
1021  /* Found the right suffix */
1022  close(fd);
1023  snprintf(new, sizeof(new), "%s.%d%s", filename, y, suffixes[which]);
1024  if (rename(old, new)) {
1025  fprintf(stderr, "Unable to rename file '%s' to '%s'\n", old, new);
1026  res = -1;
1027  }
1028  break;
1029  }
1030  }
1031  }
1032 
1033  /* Finally, rename the current file */
1034  snprintf(new, sizeof(new), "%s.0", filename);
1035  if (rename(filename, new)) {
1036  fprintf(stderr, "Unable to rename file '%s' to '%s'\n", filename, new);
1037  res = -1;
1038  } else {
1039  filename = new;
1040  }
1041  }
1042 
1045  char buf[512];
1046 
1047  pbx_builtin_setvar_helper(c, "filename", filename);
1048  pbx_substitute_variables_helper(c, exec_after_rotate, buf, sizeof(buf));
1049  if (c) {
1050  c = ast_channel_unref(c);
1051  }
1052  if (ast_safe_system(buf) == -1) {
1053  ast_log(LOG_WARNING, "error executing '%s'\n", buf);
1054  }
1055  }
1056  return res;
1057 }
Main Channel structure associated with a channel.
#define ARRAY_LEN(a)
Definition: isdn_lib.c:42
#define ast_channel_unref(c)
Decrease channel reference count.
Definition: channel.h:2938
char buf[BUFSIZE]
Definition: eagi_proxy.c:66
#define LOG_WARNING
Definition: logger.h:274
static struct test_val c
#define NULL
Definition: resample.c:96
Definition: logger.c:99
#define ast_dummy_channel_alloc()
Create a fake channel structure.
Definition: channel.h:1283
static char exec_after_rotate[256]
Definition: logger.c:80
int ast_safe_system(const char *s)
Safely spawn an OS shell command while closing file descriptors.
Definition: extconf.c:829
#define ast_strlen_zero(a)
Definition: muted.c:73
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...
char filename[PATH_MAX]
Definition: logger.c:145
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:2088
rotatestrategy
Definition: logger.c:96
void pbx_substitute_variables_helper(struct ast_channel *c, const char *cp1, char *cp2, int count)
Definition: ael_main.c:211
Definition: logger.c:97
#define PATH_MAX
Definition: asterisk.h:40

◆ unload_module()

static int unload_module ( void  )
static

Definition at line 2557 of file logger.c.

Referenced by load_module().

2558 {
2559  return 0;
2560 }

◆ update_logchannels()

static void update_logchannels ( void  )
static

Definition at line 2347 of file logger.c.

References __LOG_TRACE, ast_free, ast_log_full(), AST_RWLIST_TRAVERSE, AST_RWLIST_UNLOCK, AST_RWLIST_WRLOCK, ast_skip_blanks(), ast_str_buffer(), ast_str_create, ast_str_set(), ast_threadstorage_get_ptr(), AST_THREADSTORAGE_RAW(), ast_threadstorage_set_ptr(), AST_TRACE_INDENT_DEC_AFTER, AST_TRACE_INDENT_DEC_BEFORE, AST_TRACE_INDENT_INC_AFTER, AST_TRACE_INDENT_INC_BEFORE, AST_TRACE_INDENT_NONE, AST_TRACE_INDENT_PROVIDED, AST_TRACE_INDENT_SAME, make_ari_stubs::file, format, global_logmask, logchannel::list, logchannel::logmask, make_components(), NULL, and S_OR.

Referenced by ast_logger_register_level(), and ast_logger_unregister_level().

2348 {
2349  struct logchannel *cur;
2350 
2352 
2353  global_logmask = 0;
2354 
2356  make_components(cur);
2357  global_logmask |= cur->logmask;
2358  }
2359 
2361 }
static unsigned int global_logmask
Definition: logger.c:83
#define AST_RWLIST_WRLOCK(head)
Write locks a list.
Definition: linkedlists.h:51
#define AST_RWLIST_UNLOCK(head)
Attempts to unlock a read/write based list.
Definition: linkedlists.h:150
static void make_components(struct logchannel *chan)
Definition: logger.c:477
unsigned int logmask
Definition: logger.c:133
#define AST_RWLIST_TRAVERSE
Definition: linkedlists.h:493
struct logchannel::@398 list

◆ verb_console_free()

static void verb_console_free ( void *  v_console)
static

Definition at line 2272 of file logger.c.

References ast_free, and verb_console_unregister().

2273 {
2274  struct verb_console *console = v_console;
2275 
2276  verb_console_unregister(console);
2277  ast_free(console);
2278 }
#define ast_free(a)
Definition: astmm.h:182
static void verb_console_unregister(struct verb_console *console)
Definition: logger.c:2262

◆ verb_console_unregister()

static void verb_console_unregister ( struct verb_console console)
static

Definition at line 2262 of file logger.c.

References AST_RWLIST_REMOVE, AST_RWLIST_UNLOCK, AST_RWLIST_WRLOCK, and ast_verb_update().

Referenced by ast_verb_console_unregister(), and verb_console_free().

2263 {
2265  console = AST_RWLIST_REMOVE(&verb_consoles, console, node);
2267  if (console) {
2268  ast_verb_update();
2269  }
2270 }
Definition: test_heap.c:38
void ast_verb_update(void)
Re-evaluate the system max verbosity level (ast_verb_sys_level).
Definition: logger.c:2219
#define AST_RWLIST_WRLOCK(head)
Write locks a list.
Definition: linkedlists.h:51
#define AST_RWLIST_UNLOCK(head)
Attempts to unlock a read/write based list.
Definition: linkedlists.h:150
#define AST_RWLIST_REMOVE
Definition: linkedlists.h:884

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

◆ ast_module_info

const struct ast_module_info* ast_module_info = &__mod_info
static

Definition at line 2575 of file logger.c.

◆ cli_logger

struct ast_cli_entry cli_logger[]
static

Definition at line 1546 of file logger.c.

◆ close_logger_thread

int close_logger_thread = 0
static

Definition at line 189 of file logger.c.

◆ colors

const int colors[NUMLOGLEVELS]
static

Colors used in the console for logging.

Definition at line 215 of file logger.c.

◆ dateformat

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

◆ display_callids

int display_callids
static

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

Referenced by init_logger_chain(), and rotate_file().

◆ filesize_reload_needed

int filesize_reload_needed
static

Definition at line 82 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:1555

Definition at line 1561 of file logger.c.

◆ high_water_alert

unsigned int high_water_alert
static

Definition at line 94 of file logger.c.

Referenced by ast_log_full(), and logger_thread().

◆ hostname

char hostname[MAXHOSTNAMELEN]
static

Definition at line 110 of file logger.c.

Referenced by init_logger_chain(), and make_filename().

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

Definition at line 204 of file logger.c.

◆ log_buf

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

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

◆ logfiles

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

Definition at line 422 of file logger.c.

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

Definition at line 312 of file logger.c.

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

Definition at line 472 of file logger.c.

◆ logger_initialized

int logger_initialized
static

◆ logger_messages_discarded

int logger_messages_discarded
static

Definition at line 93 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 89 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 187 of file logger.c.

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

Referenced by ast_create_callid().

◆ qlog

FILE* qlog
static

Definition at line 191 of file logger.c.

◆ queue_adaptive_realtime

unsigned int queue_adaptive_realtime

Definition at line 106 of file logger.c.

◆ queue_log

unsigned int queue_log

Definition at line 104 of file logger.c.

◆ queue_log_name

char queue_log_name[256] = QUEUELOG
static

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

◆ queue_log_to_file

unsigned int queue_log_to_file

Definition at line 105 of file logger.c.

◆ queuelog_init

int queuelog_init
static

Definition at line 84 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 2217 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 250 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 251 of file logger.c.