1999-12-05 07:28:29 +00:00
|
|
|
/*
|
2005-09-14 20:46:50 +00:00
|
|
|
* Asterisk -- An open source telephony toolkit.
|
1999-12-05 07:28:29 +00:00
|
|
|
*
|
2006-02-22 21:53:56 +00:00
|
|
|
* Copyright (C) 1999 - 2006, Digium, Inc.
|
2005-09-14 20:46:50 +00:00
|
|
|
*
|
|
|
|
* Mark Spencer <markster@digium.com>
|
|
|
|
*
|
|
|
|
* See http://www.asterisk.org for more information about
|
|
|
|
* the Asterisk project. Please do not directly contact
|
|
|
|
* any of the maintainers of this project for assistance;
|
|
|
|
* the project provides a web site, mailing lists and IRC
|
|
|
|
* channels for your use.
|
1999-12-05 07:28:29 +00:00
|
|
|
*
|
2005-09-14 20:46:50 +00:00
|
|
|
* This program is free software, distributed under the terms of
|
|
|
|
* the GNU General Public License Version 2. See the LICENSE file
|
|
|
|
* at the top of the source tree.
|
|
|
|
*/
|
|
|
|
|
2005-10-24 20:12:06 +00:00
|
|
|
/*! \file
|
2005-12-30 21:18:06 +00:00
|
|
|
*
|
2005-10-24 20:12:06 +00:00
|
|
|
* \brief Asterisk Logger
|
2009-06-25 23:54:03 +00:00
|
|
|
*
|
1999-12-05 07:28:29 +00:00
|
|
|
* Logging routines
|
|
|
|
*
|
2005-12-30 21:18:06 +00:00
|
|
|
* \author Mark Spencer <markster@digium.com>
|
1999-12-05 07:28:29 +00:00
|
|
|
*/
|
|
|
|
|
2012-10-18 14:17:40 +00:00
|
|
|
/*! \li \ref logger.c uses the configuration file \ref logger.conf
|
|
|
|
* \addtogroup configuration_file Configuration Files
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*!
|
|
|
|
* \page logger.conf logger.conf
|
|
|
|
* \verbinclude logger.conf.sample
|
|
|
|
*/
|
|
|
|
|
2012-06-15 16:20:16 +00:00
|
|
|
/*** MODULEINFO
|
|
|
|
<support_level>core</support_level>
|
|
|
|
***/
|
|
|
|
|
2006-06-07 18:54:56 +00:00
|
|
|
#include "asterisk.h"
|
|
|
|
|
|
|
|
ASTERISK_FILE_VERSION(__FILE__, "$Revision$")
|
|
|
|
|
2009-06-25 23:54:03 +00:00
|
|
|
/* When we include logger.h again it will trample on some stuff in syslog.h, but
|
|
|
|
* nothing we care about in here. */
|
2005-04-22 13:11:34 +00:00
|
|
|
#include <syslog.h>
|
2013-06-08 22:09:07 +00:00
|
|
|
#include <signal.h>
|
|
|
|
#include <time.h>
|
|
|
|
#include <sys/stat.h>
|
|
|
|
#include <fcntl.h>
|
2005-04-22 13:11:34 +00:00
|
|
|
|
2009-06-25 23:54:03 +00:00
|
|
|
#include "asterisk/_private.h"
|
|
|
|
#include "asterisk/paths.h" /* use ast_config_AST_LOG_DIR */
|
2005-04-21 06:02:45 +00:00
|
|
|
#include "asterisk/logger.h"
|
2005-08-31 02:43:44 +00:00
|
|
|
#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"
|
2012-03-29 20:01:20 +00:00
|
|
|
#include "asterisk/astobj2.h"
|
Merge team/russell/ast_verbose_threadstorage
- instead of defining a free() wrapper in a bunch of files, define it as
ast_free() in utils.h and remove the copies from all the files.
- centralize and abstract the code used for doing thread storage. The code
lives in threadstorage.h, with one function being implemented in utils.c.
This new API includes generic thread storage as well as special functions
for handling thread local dynamic length string buffers.
- update ast_inet_ntoa() to use the new threadstorage API
- update ast_state2str() to use the new threadstorage API
- update ast_cli() to use the new threadstorage API
- Modify manager_event() to use thread storage. Instead of using a buffer of
4096 characters as the workspace for building the manager event, use a thread
local dynamic string. Now there is no length limitation on the length of the
body of a manager event.
- Significantly simplify the handling of ast_verbose() ...
- Instead of using a static char buffer and a lock to make sure only one
thread can be using ast_verbose() at a time, use a thread local dynamic
string as the workspace for preparing the verbose message. Instead of
locking around the entire function, the only locking done now is when the
message has been built and is being deliviered to the list of registered
verbose message handlers.
- This function was doing a strdup() on every message passed to it and
keeping a queue of the last 200 messages in memory. This has been
completely removed. The only place this was used was that if there were
any messages in the verbose queue when a verbose handler was registered,
all of the messages in the queue would be fed to it. So, I just made sure
that the console verbose handler and the network verbose handler (for
remote asterisk consoles) were registered before any verbose messages.
pbx_gtkconsole and pbx_kdeconsole will now lose a few verbose messages at
startup, but I didn't feel the performance hit of this message queue was
worth saving the initial verbose output for these very rarely used modules.
- I have removed the last three arguments to the verbose handlers, leaving
only the string itself because they aren't needed anymore. For example,
ast_verbose had some logic for telling the verbose handler to add
a newline if the buffer was completely full. Now that the buffer can grow
as needed, this doesn't matter anymore.
- remove unused function, ast_verbose_dmesg() which was to dispatch the
message queue
- Convert the list of verbose handlers to use the linked list macros.
- add missing newline characters to a few ast_verbose() calls
- convert the list of log channels to use the linked list macros in logger.c
- fix close_logger() to close all of the files it opened for logging
- update ast_log() to use a thread local dynamic string for its workspace
for preparing log messages instead of a buffer of size BUFSIZ (8kB on my
system) allocated on the stack. The dynamic string in this case is limited
to only growing to a maximum size of BUFSIZ.
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@39272 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2006-08-08 06:32:04 +00:00
|
|
|
#include "asterisk/threadstorage.h"
|
2006-12-21 21:57:16 +00:00
|
|
|
#include "asterisk/strings.h"
|
2007-08-28 20:03:48 +00:00
|
|
|
#include "asterisk/pbx.h"
|
2009-01-09 16:32:34 +00:00
|
|
|
#include "asterisk/app.h"
|
2009-06-25 23:54:03 +00:00
|
|
|
#include "asterisk/syslog.h"
|
2011-09-07 08:06:32 +00:00
|
|
|
#include "asterisk/buildinfo.h"
|
|
|
|
#include "asterisk/ast_version.h"
|
2013-06-08 22:09:07 +00:00
|
|
|
#include "asterisk/backtrace.h"
|
1999-12-05 07:28:29 +00:00
|
|
|
|
2012-07-11 02:06:05 +00:00
|
|
|
/*** DOCUMENTATION
|
|
|
|
***/
|
|
|
|
|
2004-05-18 05:47:27 +00:00
|
|
|
static char dateformat[256] = "%b %e %T"; /* Original Asterisk Format */
|
2005-03-31 19:08:51 +00:00
|
|
|
|
2006-09-26 17:09:01 +00:00
|
|
|
static char queue_log_name[256] = QUEUELOG;
|
2007-08-28 20:03:48 +00:00
|
|
|
static char exec_after_rotate[256] = "";
|
2006-09-26 17:09:01 +00:00
|
|
|
|
2006-12-27 22:14:33 +00:00
|
|
|
static int filesize_reload_needed;
|
2009-05-15 13:13:47 +00:00
|
|
|
static unsigned int global_logmask = 0xFFFF;
|
2010-07-20 23:23:25 +00:00
|
|
|
static int queuelog_init;
|
2011-08-10 20:51:07 +00:00
|
|
|
static int logger_initialized;
|
2012-03-29 20:01:20 +00:00
|
|
|
static volatile int next_unique_callid; /* Used to assign unique call_ids to calls */
|
|
|
|
static int display_callids;
|
|
|
|
static void unique_callid_cleanup(void *data);
|
|
|
|
|
|
|
|
struct ast_callid {
|
|
|
|
int call_identifier; /* Numerical value of the call displayed in the logs */
|
|
|
|
};
|
|
|
|
|
|
|
|
AST_THREADSTORAGE_CUSTOM(unique_callid, NULL, unique_callid_cleanup);
|
2007-08-28 20:03:48 +00:00
|
|
|
|
2009-06-15 17:34:30 +00:00
|
|
|
static enum rotatestrategy {
|
2012-09-12 17:13:02 +00:00
|
|
|
NONE = 0, /* Do not rotate log files at all, instead rely on external mechanisms */
|
2007-08-28 20:03:48 +00:00
|
|
|
SEQUENTIAL = 1 << 0, /* Original method - create a new file, in order */
|
|
|
|
ROTATE = 1 << 1, /* Rotate all files, such that the oldest file has the highest suffix */
|
|
|
|
TIMESTAMP = 1 << 2, /* Append the epoch timestamp onto the end of the archived file */
|
|
|
|
} rotatestrategy = SEQUENTIAL;
|
1999-12-05 07:28:29 +00:00
|
|
|
|
2005-03-11 08:49:01 +00:00
|
|
|
static struct {
|
|
|
|
unsigned int queue_log:1;
|
2010-07-20 23:23:25 +00:00
|
|
|
unsigned int queue_log_to_file:1;
|
|
|
|
unsigned int queue_adaptive_realtime:1;
|
2013-01-28 01:50:54 +00:00
|
|
|
unsigned int queue_log_realtime_use_gmt:1;
|
2009-05-02 19:02:22 +00:00
|
|
|
} logfiles = { 1 };
|
2005-03-11 08:49:01 +00:00
|
|
|
|
2005-05-08 16:44:25 +00:00
|
|
|
static char hostname[MAXHOSTNAMELEN];
|
2004-09-05 03:48:05 +00:00
|
|
|
|
2005-03-31 19:08:51 +00:00
|
|
|
enum logtypes {
|
|
|
|
LOGTYPE_SYSLOG,
|
|
|
|
LOGTYPE_FILE,
|
|
|
|
LOGTYPE_CONSOLE,
|
|
|
|
};
|
|
|
|
|
2004-01-12 05:05:35 +00:00
|
|
|
struct logchannel {
|
2009-05-15 13:13:47 +00:00
|
|
|
/*! What to log to this channel */
|
|
|
|
unsigned int logmask;
|
|
|
|
/*! If this channel is disabled or not */
|
|
|
|
int disabled;
|
|
|
|
/*! syslog facility */
|
|
|
|
int facility;
|
2012-02-14 20:27:16 +00:00
|
|
|
/*! Verbosity level */
|
|
|
|
int verbosity;
|
2009-05-15 13:13:47 +00:00
|
|
|
/*! Type of log channel */
|
|
|
|
enum logtypes type;
|
|
|
|
/*! logfile logging file pointer */
|
|
|
|
FILE *fileptr;
|
|
|
|
/*! Filename */
|
|
|
|
char filename[PATH_MAX];
|
|
|
|
/*! field for linking to list */
|
Merge team/russell/ast_verbose_threadstorage
- instead of defining a free() wrapper in a bunch of files, define it as
ast_free() in utils.h and remove the copies from all the files.
- centralize and abstract the code used for doing thread storage. The code
lives in threadstorage.h, with one function being implemented in utils.c.
This new API includes generic thread storage as well as special functions
for handling thread local dynamic length string buffers.
- update ast_inet_ntoa() to use the new threadstorage API
- update ast_state2str() to use the new threadstorage API
- update ast_cli() to use the new threadstorage API
- Modify manager_event() to use thread storage. Instead of using a buffer of
4096 characters as the workspace for building the manager event, use a thread
local dynamic string. Now there is no length limitation on the length of the
body of a manager event.
- Significantly simplify the handling of ast_verbose() ...
- Instead of using a static char buffer and a lock to make sure only one
thread can be using ast_verbose() at a time, use a thread local dynamic
string as the workspace for preparing the verbose message. Instead of
locking around the entire function, the only locking done now is when the
message has been built and is being deliviered to the list of registered
verbose message handlers.
- This function was doing a strdup() on every message passed to it and
keeping a queue of the last 200 messages in memory. This has been
completely removed. The only place this was used was that if there were
any messages in the verbose queue when a verbose handler was registered,
all of the messages in the queue would be fed to it. So, I just made sure
that the console verbose handler and the network verbose handler (for
remote asterisk consoles) were registered before any verbose messages.
pbx_gtkconsole and pbx_kdeconsole will now lose a few verbose messages at
startup, but I didn't feel the performance hit of this message queue was
worth saving the initial verbose output for these very rarely used modules.
- I have removed the last three arguments to the verbose handlers, leaving
only the string itself because they aren't needed anymore. For example,
ast_verbose had some logic for telling the verbose handler to add
a newline if the buffer was completely full. Now that the buffer can grow
as needed, this doesn't matter anymore.
- remove unused function, ast_verbose_dmesg() which was to dispatch the
message queue
- Convert the list of verbose handlers to use the linked list macros.
- add missing newline characters to a few ast_verbose() calls
- convert the list of log channels to use the linked list macros in logger.c
- fix close_logger() to close all of the files it opened for logging
- update ast_log() to use a thread local dynamic string for its workspace
for preparing log messages instead of a buffer of size BUFSIZ (8kB on my
system) allocated on the stack. The dynamic string in this case is limited
to only growing to a maximum size of BUFSIZ.
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@39272 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2006-08-08 06:32:04 +00:00
|
|
|
AST_LIST_ENTRY(logchannel) list;
|
2009-05-15 13:13:47 +00:00
|
|
|
/*! Line number from configuration file */
|
|
|
|
int lineno;
|
|
|
|
/*! Components (levels) from last config load */
|
|
|
|
char components[0];
|
2002-02-11 04:25:04 +00:00
|
|
|
};
|
|
|
|
|
2007-07-20 01:54:52 +00:00
|
|
|
static AST_RWLIST_HEAD_STATIC(logchannels, logchannel);
|
1999-12-05 07:28:29 +00:00
|
|
|
|
2006-12-21 21:57:16 +00:00
|
|
|
enum logmsgtypes {
|
|
|
|
LOGMSG_NORMAL = 0,
|
|
|
|
LOGMSG_VERBOSE,
|
|
|
|
};
|
|
|
|
|
|
|
|
struct logmsg {
|
|
|
|
enum logmsgtypes type;
|
|
|
|
int level;
|
|
|
|
int line;
|
2010-12-12 03:58:33 +00:00
|
|
|
int lwp;
|
2012-03-29 20:01:20 +00:00
|
|
|
struct ast_callid *callid;
|
2009-05-15 13:13:47 +00:00
|
|
|
AST_DECLARE_STRING_FIELDS(
|
|
|
|
AST_STRING_FIELD(date);
|
|
|
|
AST_STRING_FIELD(file);
|
|
|
|
AST_STRING_FIELD(function);
|
|
|
|
AST_STRING_FIELD(message);
|
|
|
|
AST_STRING_FIELD(level_name);
|
|
|
|
);
|
2006-12-21 21:57:16 +00:00
|
|
|
AST_LIST_ENTRY(logmsg) list;
|
|
|
|
};
|
|
|
|
|
2012-03-29 20:01:20 +00:00
|
|
|
static void logmsg_free(struct logmsg *msg)
|
|
|
|
{
|
|
|
|
if (msg->callid) {
|
|
|
|
ast_callid_unref(msg->callid);
|
|
|
|
}
|
|
|
|
ast_free(msg);
|
|
|
|
}
|
|
|
|
|
2006-12-21 21:57:16 +00:00
|
|
|
static AST_LIST_HEAD_STATIC(logmsgs, logmsg);
|
|
|
|
static pthread_t logthread = AST_PTHREADT_NULL;
|
|
|
|
static ast_cond_t logcond;
|
2009-10-02 03:04:34 +00:00
|
|
|
static int close_logger_thread = 0;
|
2006-12-21 21:57:16 +00:00
|
|
|
|
2006-12-27 22:14:33 +00:00
|
|
|
static FILE *qlog;
|
1999-12-05 07:28:29 +00:00
|
|
|
|
2009-05-15 13:13:47 +00:00
|
|
|
/*! \brief 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.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/* Modifications to this array are protected by the rwlock in the
|
|
|
|
* logchannels list.
|
|
|
|
*/
|
|
|
|
|
2012-03-14 10:56:53 +00:00
|
|
|
static char *levels[NUMLOGLEVELS] = {
|
2004-06-29 04:42:19 +00:00
|
|
|
"DEBUG",
|
2009-05-02 19:02:22 +00:00
|
|
|
"---EVENT---", /* no longer used */
|
2004-06-29 04:42:19 +00:00
|
|
|
"NOTICE",
|
|
|
|
"WARNING",
|
|
|
|
"ERROR",
|
2005-08-22 21:19:59 +00:00
|
|
|
"VERBOSE",
|
2009-05-15 13:13:47 +00:00
|
|
|
"DTMF",
|
1999-12-05 07:28:29 +00:00
|
|
|
};
|
|
|
|
|
2007-12-06 14:29:20 +00:00
|
|
|
/*! \brief Colors used in the console for logging */
|
2012-03-14 10:56:53 +00:00
|
|
|
static const int colors[NUMLOGLEVELS] = {
|
2004-06-29 04:42:19 +00:00
|
|
|
COLOR_BRGREEN,
|
2009-05-15 13:13:47 +00:00
|
|
|
COLOR_BRBLUE, /* no longer used */
|
2004-06-29 04:42:19 +00:00
|
|
|
COLOR_YELLOW,
|
|
|
|
COLOR_BRRED,
|
|
|
|
COLOR_RED,
|
2005-08-22 21:19:59 +00:00
|
|
|
COLOR_GREEN,
|
2009-05-15 13:13:47 +00:00
|
|
|
COLOR_BRGREEN,
|
|
|
|
0,
|
|
|
|
0,
|
|
|
|
0,
|
|
|
|
0,
|
|
|
|
0,
|
|
|
|
0,
|
|
|
|
0,
|
|
|
|
0,
|
|
|
|
0,
|
|
|
|
COLOR_BRBLUE,
|
|
|
|
COLOR_BRBLUE,
|
|
|
|
COLOR_BRBLUE,
|
|
|
|
COLOR_BRBLUE,
|
|
|
|
COLOR_BRBLUE,
|
|
|
|
COLOR_BRBLUE,
|
|
|
|
COLOR_BRBLUE,
|
|
|
|
COLOR_BRBLUE,
|
|
|
|
COLOR_BRBLUE,
|
|
|
|
COLOR_BRBLUE,
|
|
|
|
COLOR_BRBLUE,
|
|
|
|
COLOR_BRBLUE,
|
|
|
|
COLOR_BRBLUE,
|
|
|
|
COLOR_BRBLUE,
|
|
|
|
COLOR_BRBLUE,
|
|
|
|
COLOR_BRBLUE,
|
2002-06-21 01:40:13 +00:00
|
|
|
};
|
|
|
|
|
2006-10-19 01:00:57 +00:00
|
|
|
AST_THREADSTORAGE(verbose_buf);
|
2006-12-18 15:36:31 +00:00
|
|
|
#define VERBOSE_BUF_INIT_SIZE 256
|
Merge team/russell/ast_verbose_threadstorage
- instead of defining a free() wrapper in a bunch of files, define it as
ast_free() in utils.h and remove the copies from all the files.
- centralize and abstract the code used for doing thread storage. The code
lives in threadstorage.h, with one function being implemented in utils.c.
This new API includes generic thread storage as well as special functions
for handling thread local dynamic length string buffers.
- update ast_inet_ntoa() to use the new threadstorage API
- update ast_state2str() to use the new threadstorage API
- update ast_cli() to use the new threadstorage API
- Modify manager_event() to use thread storage. Instead of using a buffer of
4096 characters as the workspace for building the manager event, use a thread
local dynamic string. Now there is no length limitation on the length of the
body of a manager event.
- Significantly simplify the handling of ast_verbose() ...
- Instead of using a static char buffer and a lock to make sure only one
thread can be using ast_verbose() at a time, use a thread local dynamic
string as the workspace for preparing the verbose message. Instead of
locking around the entire function, the only locking done now is when the
message has been built and is being deliviered to the list of registered
verbose message handlers.
- This function was doing a strdup() on every message passed to it and
keeping a queue of the last 200 messages in memory. This has been
completely removed. The only place this was used was that if there were
any messages in the verbose queue when a verbose handler was registered,
all of the messages in the queue would be fed to it. So, I just made sure
that the console verbose handler and the network verbose handler (for
remote asterisk consoles) were registered before any verbose messages.
pbx_gtkconsole and pbx_kdeconsole will now lose a few verbose messages at
startup, but I didn't feel the performance hit of this message queue was
worth saving the initial verbose output for these very rarely used modules.
- I have removed the last three arguments to the verbose handlers, leaving
only the string itself because they aren't needed anymore. For example,
ast_verbose had some logic for telling the verbose handler to add
a newline if the buffer was completely full. Now that the buffer can grow
as needed, this doesn't matter anymore.
- remove unused function, ast_verbose_dmesg() which was to dispatch the
message queue
- Convert the list of verbose handlers to use the linked list macros.
- add missing newline characters to a few ast_verbose() calls
- convert the list of log channels to use the linked list macros in logger.c
- fix close_logger() to close all of the files it opened for logging
- update ast_log() to use a thread local dynamic string for its workspace
for preparing log messages instead of a buffer of size BUFSIZ (8kB on my
system) allocated on the stack. The dynamic string in this case is limited
to only growing to a maximum size of BUFSIZ.
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@39272 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2006-08-08 06:32:04 +00:00
|
|
|
|
2006-10-19 01:00:57 +00:00
|
|
|
AST_THREADSTORAGE(log_buf);
|
2006-12-18 15:36:31 +00:00
|
|
|
#define LOG_BUF_INIT_SIZE 256
|
Merge team/russell/ast_verbose_threadstorage
- instead of defining a free() wrapper in a bunch of files, define it as
ast_free() in utils.h and remove the copies from all the files.
- centralize and abstract the code used for doing thread storage. The code
lives in threadstorage.h, with one function being implemented in utils.c.
This new API includes generic thread storage as well as special functions
for handling thread local dynamic length string buffers.
- update ast_inet_ntoa() to use the new threadstorage API
- update ast_state2str() to use the new threadstorage API
- update ast_cli() to use the new threadstorage API
- Modify manager_event() to use thread storage. Instead of using a buffer of
4096 characters as the workspace for building the manager event, use a thread
local dynamic string. Now there is no length limitation on the length of the
body of a manager event.
- Significantly simplify the handling of ast_verbose() ...
- Instead of using a static char buffer and a lock to make sure only one
thread can be using ast_verbose() at a time, use a thread local dynamic
string as the workspace for preparing the verbose message. Instead of
locking around the entire function, the only locking done now is when the
message has been built and is being deliviered to the list of registered
verbose message handlers.
- This function was doing a strdup() on every message passed to it and
keeping a queue of the last 200 messages in memory. This has been
completely removed. The only place this was used was that if there were
any messages in the verbose queue when a verbose handler was registered,
all of the messages in the queue would be fed to it. So, I just made sure
that the console verbose handler and the network verbose handler (for
remote asterisk consoles) were registered before any verbose messages.
pbx_gtkconsole and pbx_kdeconsole will now lose a few verbose messages at
startup, but I didn't feel the performance hit of this message queue was
worth saving the initial verbose output for these very rarely used modules.
- I have removed the last three arguments to the verbose handlers, leaving
only the string itself because they aren't needed anymore. For example,
ast_verbose had some logic for telling the verbose handler to add
a newline if the buffer was completely full. Now that the buffer can grow
as needed, this doesn't matter anymore.
- remove unused function, ast_verbose_dmesg() which was to dispatch the
message queue
- Convert the list of verbose handlers to use the linked list macros.
- add missing newline characters to a few ast_verbose() calls
- convert the list of log channels to use the linked list macros in logger.c
- fix close_logger() to close all of the files it opened for logging
- update ast_log() to use a thread local dynamic string for its workspace
for preparing log messages instead of a buffer of size BUFSIZ (8kB on my
system) allocated on the stack. The dynamic string in this case is limited
to only growing to a maximum size of BUFSIZ.
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@39272 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2006-08-08 06:32:04 +00:00
|
|
|
|
2010-07-20 23:23:25 +00:00
|
|
|
static void logger_queue_init(void);
|
|
|
|
|
2012-02-14 20:27:16 +00:00
|
|
|
static unsigned int make_components(const char *s, int lineno, int *verbosity)
|
2002-02-11 04:25:04 +00:00
|
|
|
{
|
|
|
|
char *w;
|
2009-05-15 13:13:47 +00:00
|
|
|
unsigned int res = 0;
|
2007-11-14 13:18:40 +00:00
|
|
|
char *stringp = ast_strdupa(s);
|
2009-05-15 13:13:47 +00:00
|
|
|
unsigned int x;
|
2006-07-21 23:58:14 +00:00
|
|
|
|
2012-02-14 20:27:16 +00:00
|
|
|
*verbosity = 3;
|
|
|
|
|
2006-07-21 23:58:14 +00:00
|
|
|
while ((w = strsep(&stringp, ","))) {
|
|
|
|
w = ast_skip_blanks(w);
|
2009-05-15 13:13:47 +00:00
|
|
|
|
2010-05-19 15:29:28 +00:00
|
|
|
if (!strcmp(w, "*")) {
|
2010-05-20 12:06:11 +00:00
|
|
|
res = 0xFFFFFFFF;
|
2010-05-19 15:29:28 +00:00
|
|
|
break;
|
2012-02-14 20:27:16 +00:00
|
|
|
} else if (!strncasecmp(w, "verbose(", 8) && sscanf(w + 8, "%d)", verbosity) == 1) {
|
|
|
|
res |= (1 << __LOG_VERBOSE);
|
|
|
|
break;
|
2010-05-19 15:29:28 +00:00
|
|
|
} else for (x = 0; x < ARRAY_LEN(levels); x++) {
|
2009-05-15 13:13:47 +00:00
|
|
|
if (levels[x] && !strcasecmp(w, levels[x])) {
|
|
|
|
res |= (1 << x);
|
|
|
|
break;
|
|
|
|
}
|
2005-03-31 19:08:51 +00:00
|
|
|
}
|
2002-02-11 04:25:04 +00:00
|
|
|
}
|
2006-07-21 23:58:14 +00:00
|
|
|
|
2002-02-11 04:25:04 +00:00
|
|
|
return res;
|
|
|
|
}
|
|
|
|
|
2007-11-14 13:18:40 +00:00
|
|
|
static struct logchannel *make_logchannel(const char *channel, const char *components, int lineno)
|
2002-02-11 04:25:04 +00:00
|
|
|
{
|
2004-01-12 05:05:35 +00:00
|
|
|
struct logchannel *chan;
|
|
|
|
char *facility;
|
2011-09-07 08:06:32 +00:00
|
|
|
struct ast_tm tm;
|
|
|
|
struct timeval now = ast_tvnow();
|
|
|
|
char datestring[256];
|
2004-01-12 05:05:35 +00:00
|
|
|
|
2009-05-15 13:13:47 +00:00
|
|
|
if (ast_strlen_zero(channel) || !(chan = ast_calloc(1, sizeof(*chan) + strlen(components) + 1)))
|
2002-02-11 04:25:04 +00:00
|
|
|
return NULL;
|
2004-01-12 05:05:35 +00:00
|
|
|
|
2009-05-15 13:13:47 +00:00
|
|
|
strcpy(chan->components, components);
|
|
|
|
chan->lineno = lineno;
|
|
|
|
|
2005-04-01 16:09:21 +00:00
|
|
|
if (!strcasecmp(channel, "console")) {
|
|
|
|
chan->type = LOGTYPE_CONSOLE;
|
|
|
|
} else if (!strncasecmp(channel, "syslog", 6)) {
|
|
|
|
/*
|
|
|
|
* syntax is:
|
|
|
|
* syslog.facility => level,level,level
|
|
|
|
*/
|
|
|
|
facility = strchr(channel, '.');
|
2007-01-23 00:11:32 +00:00
|
|
|
if (!facility++ || !facility) {
|
2005-04-01 16:09:21 +00:00
|
|
|
facility = "local0";
|
|
|
|
}
|
2004-12-14 23:36:30 +00:00
|
|
|
|
2009-06-25 23:54:03 +00:00
|
|
|
chan->facility = ast_syslog_facility(facility);
|
|
|
|
|
|
|
|
if (chan->facility < 0) {
|
2005-04-01 16:09:21 +00:00
|
|
|
fprintf(stderr, "Logger Warning: bad syslog facility in logger.conf\n");
|
2007-12-12 20:05:13 +00:00
|
|
|
ast_free(chan);
|
2005-04-01 16:09:21 +00:00
|
|
|
return NULL;
|
|
|
|
}
|
2004-01-12 05:05:35 +00:00
|
|
|
|
2005-04-01 16:09:21 +00:00
|
|
|
chan->type = LOGTYPE_SYSLOG;
|
2009-05-15 13:13:47 +00:00
|
|
|
ast_copy_string(chan->filename, channel, sizeof(chan->filename));
|
2005-04-01 16:09:21 +00:00
|
|
|
openlog("asterisk", LOG_PID, chan->facility);
|
|
|
|
} else {
|
2007-01-23 00:11:32 +00:00
|
|
|
if (!ast_strlen_zero(hostname)) {
|
2009-05-08 14:06:15 +00:00
|
|
|
snprintf(chan->filename, sizeof(chan->filename), "%s/%s.%s",
|
|
|
|
channel[0] != '/' ? ast_config_AST_LOG_DIR : "", channel, hostname);
|
2005-04-01 16:09:21 +00:00
|
|
|
} else {
|
2009-05-08 14:06:15 +00:00
|
|
|
snprintf(chan->filename, sizeof(chan->filename), "%s/%s",
|
|
|
|
channel[0] != '/' ? ast_config_AST_LOG_DIR : "", channel);
|
2002-02-11 04:25:04 +00:00
|
|
|
}
|
2009-05-15 13:13:47 +00:00
|
|
|
if (!(chan->fileptr = fopen(chan->filename, "a"))) {
|
2011-08-12 16:22:45 +00:00
|
|
|
/* Can't do real logging here since we're called with a lock
|
|
|
|
* so log to any attached consoles */
|
|
|
|
ast_console_puts_mutable("ERROR: Unable to open log file '", __LOG_ERROR);
|
|
|
|
ast_console_puts_mutable(chan->filename, __LOG_ERROR);
|
|
|
|
ast_console_puts_mutable("': ", __LOG_ERROR);
|
|
|
|
ast_console_puts_mutable(strerror(errno), __LOG_ERROR);
|
|
|
|
ast_console_puts_mutable("'\n", __LOG_ERROR);
|
|
|
|
ast_free(chan);
|
|
|
|
return NULL;
|
2011-09-07 08:06:32 +00:00
|
|
|
} else {
|
|
|
|
/* Create our date/time */
|
|
|
|
ast_localtime(&now, &tm, NULL);
|
|
|
|
ast_strftime(datestring, sizeof(datestring), dateformat, &tm);
|
|
|
|
|
|
|
|
fprintf(chan->fileptr, "[%s] Asterisk %s built by %s @ %s on a %s running %s on %s\n",
|
|
|
|
datestring, ast_get_version(), ast_build_user, ast_build_hostname,
|
|
|
|
ast_build_machine, ast_build_os, ast_build_date);
|
|
|
|
fflush(chan->fileptr);
|
2011-08-12 16:22:45 +00:00
|
|
|
}
|
2005-04-01 16:09:21 +00:00
|
|
|
chan->type = LOGTYPE_FILE;
|
2002-02-11 04:25:04 +00:00
|
|
|
}
|
2012-02-14 20:27:16 +00:00
|
|
|
chan->logmask = make_components(chan->components, lineno, &chan->verbosity);
|
2009-05-15 13:13:47 +00:00
|
|
|
|
2004-01-12 05:05:35 +00:00
|
|
|
return chan;
|
2002-02-11 04:25:04 +00:00
|
|
|
}
|
|
|
|
|
2010-12-31 09:21:47 +00:00
|
|
|
static void init_logger_chain(int locked, const char *altconf)
|
2002-02-11 04:25:04 +00:00
|
|
|
{
|
Merge team/russell/ast_verbose_threadstorage
- instead of defining a free() wrapper in a bunch of files, define it as
ast_free() in utils.h and remove the copies from all the files.
- centralize and abstract the code used for doing thread storage. The code
lives in threadstorage.h, with one function being implemented in utils.c.
This new API includes generic thread storage as well as special functions
for handling thread local dynamic length string buffers.
- update ast_inet_ntoa() to use the new threadstorage API
- update ast_state2str() to use the new threadstorage API
- update ast_cli() to use the new threadstorage API
- Modify manager_event() to use thread storage. Instead of using a buffer of
4096 characters as the workspace for building the manager event, use a thread
local dynamic string. Now there is no length limitation on the length of the
body of a manager event.
- Significantly simplify the handling of ast_verbose() ...
- Instead of using a static char buffer and a lock to make sure only one
thread can be using ast_verbose() at a time, use a thread local dynamic
string as the workspace for preparing the verbose message. Instead of
locking around the entire function, the only locking done now is when the
message has been built and is being deliviered to the list of registered
verbose message handlers.
- This function was doing a strdup() on every message passed to it and
keeping a queue of the last 200 messages in memory. This has been
completely removed. The only place this was used was that if there were
any messages in the verbose queue when a verbose handler was registered,
all of the messages in the queue would be fed to it. So, I just made sure
that the console verbose handler and the network verbose handler (for
remote asterisk consoles) were registered before any verbose messages.
pbx_gtkconsole and pbx_kdeconsole will now lose a few verbose messages at
startup, but I didn't feel the performance hit of this message queue was
worth saving the initial verbose output for these very rarely used modules.
- I have removed the last three arguments to the verbose handlers, leaving
only the string itself because they aren't needed anymore. For example,
ast_verbose had some logic for telling the verbose handler to add
a newline if the buffer was completely full. Now that the buffer can grow
as needed, this doesn't matter anymore.
- remove unused function, ast_verbose_dmesg() which was to dispatch the
message queue
- Convert the list of verbose handlers to use the linked list macros.
- add missing newline characters to a few ast_verbose() calls
- convert the list of log channels to use the linked list macros in logger.c
- fix close_logger() to close all of the files it opened for logging
- update ast_log() to use a thread local dynamic string for its workspace
for preparing log messages instead of a buffer of size BUFSIZ (8kB on my
system) allocated on the stack. The dynamic string in this case is limited
to only growing to a maximum size of BUFSIZ.
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@39272 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2006-08-08 06:32:04 +00:00
|
|
|
struct logchannel *chan;
|
2002-02-11 04:25:04 +00:00
|
|
|
struct ast_config *cfg;
|
|
|
|
struct ast_variable *var;
|
2006-09-20 20:40:39 +00:00
|
|
|
const char *s;
|
2008-05-19 16:03:33 +00:00
|
|
|
struct ast_flags config_flags = { 0 };
|
2007-08-16 21:09:46 +00:00
|
|
|
|
2012-03-29 20:01:20 +00:00
|
|
|
display_callids = 1;
|
|
|
|
|
2010-12-31 09:21:47 +00:00
|
|
|
if (!(cfg = ast_config_load2(S_OR(altconf, "logger.conf"), "logger", config_flags)) || cfg == CONFIG_STATUS_FILEINVALID) {
|
2007-08-16 21:09:46 +00:00
|
|
|
return;
|
2010-07-20 23:23:25 +00:00
|
|
|
}
|
2002-02-11 04:25:04 +00:00
|
|
|
|
2004-01-12 05:05:35 +00:00
|
|
|
/* delete our list of log channels */
|
2010-07-20 23:23:25 +00:00
|
|
|
if (!locked) {
|
2007-08-28 21:35:20 +00:00
|
|
|
AST_RWLIST_WRLOCK(&logchannels);
|
2010-07-20 23:23:25 +00:00
|
|
|
}
|
|
|
|
while ((chan = AST_RWLIST_REMOVE_HEAD(&logchannels, list))) {
|
2007-12-12 20:05:13 +00:00
|
|
|
ast_free(chan);
|
2010-07-20 23:23:25 +00:00
|
|
|
}
|
2009-05-15 13:13:47 +00:00
|
|
|
global_logmask = 0;
|
2010-07-20 23:23:25 +00:00
|
|
|
if (!locked) {
|
2007-08-28 21:35:20 +00:00
|
|
|
AST_RWLIST_UNLOCK(&logchannels);
|
2010-07-20 23:23:25 +00:00
|
|
|
}
|
|
|
|
|
2006-09-07 03:35:42 +00:00
|
|
|
errno = 0;
|
2004-01-12 05:05:35 +00:00
|
|
|
/* close syslog */
|
|
|
|
closelog();
|
2010-07-20 23:23:25 +00:00
|
|
|
|
2006-02-08 23:14:17 +00:00
|
|
|
/* If no config file, we're fine, set default options. */
|
|
|
|
if (!cfg) {
|
2010-07-20 23:23:25 +00:00
|
|
|
if (errno) {
|
2006-09-07 03:35:42 +00:00
|
|
|
fprintf(stderr, "Unable to open logger.conf: %s; default settings will be used.\n", strerror(errno));
|
2010-07-20 23:23:25 +00:00
|
|
|
} else {
|
2006-09-07 03:35:42 +00:00
|
|
|
fprintf(stderr, "Errors detected in logger.conf: see above; default settings will be used.\n");
|
2010-07-20 23:23:25 +00:00
|
|
|
}
|
|
|
|
if (!(chan = ast_calloc(1, sizeof(*chan)))) {
|
2006-02-27 01:43:42 +00:00
|
|
|
return;
|
2010-07-20 23:23:25 +00:00
|
|
|
}
|
2006-02-08 23:14:17 +00:00
|
|
|
chan->type = LOGTYPE_CONSOLE;
|
2009-05-15 13:13:47 +00:00
|
|
|
chan->logmask = __LOG_WARNING | __LOG_NOTICE | __LOG_ERROR;
|
2010-07-20 23:23:25 +00:00
|
|
|
if (!locked) {
|
2007-08-28 21:35:20 +00:00
|
|
|
AST_RWLIST_WRLOCK(&logchannels);
|
2010-07-20 23:23:25 +00:00
|
|
|
}
|
2007-07-20 01:54:52 +00:00
|
|
|
AST_RWLIST_INSERT_HEAD(&logchannels, chan, list);
|
2009-05-15 13:13:47 +00:00
|
|
|
global_logmask |= chan->logmask;
|
2010-07-20 23:23:25 +00:00
|
|
|
if (!locked) {
|
2007-08-28 21:35:20 +00:00
|
|
|
AST_RWLIST_UNLOCK(&logchannels);
|
2010-07-20 23:23:25 +00:00
|
|
|
}
|
2005-03-31 19:08:51 +00:00
|
|
|
return;
|
2006-02-08 23:14:17 +00:00
|
|
|
}
|
2010-07-20 23:23:25 +00:00
|
|
|
|
2004-09-05 03:48:05 +00:00
|
|
|
if ((s = ast_variable_retrieve(cfg, "general", "appendhostname"))) {
|
Merge team/russell/ast_verbose_threadstorage
- instead of defining a free() wrapper in a bunch of files, define it as
ast_free() in utils.h and remove the copies from all the files.
- centralize and abstract the code used for doing thread storage. The code
lives in threadstorage.h, with one function being implemented in utils.c.
This new API includes generic thread storage as well as special functions
for handling thread local dynamic length string buffers.
- update ast_inet_ntoa() to use the new threadstorage API
- update ast_state2str() to use the new threadstorage API
- update ast_cli() to use the new threadstorage API
- Modify manager_event() to use thread storage. Instead of using a buffer of
4096 characters as the workspace for building the manager event, use a thread
local dynamic string. Now there is no length limitation on the length of the
body of a manager event.
- Significantly simplify the handling of ast_verbose() ...
- Instead of using a static char buffer and a lock to make sure only one
thread can be using ast_verbose() at a time, use a thread local dynamic
string as the workspace for preparing the verbose message. Instead of
locking around the entire function, the only locking done now is when the
message has been built and is being deliviered to the list of registered
verbose message handlers.
- This function was doing a strdup() on every message passed to it and
keeping a queue of the last 200 messages in memory. This has been
completely removed. The only place this was used was that if there were
any messages in the verbose queue when a verbose handler was registered,
all of the messages in the queue would be fed to it. So, I just made sure
that the console verbose handler and the network verbose handler (for
remote asterisk consoles) were registered before any verbose messages.
pbx_gtkconsole and pbx_kdeconsole will now lose a few verbose messages at
startup, but I didn't feel the performance hit of this message queue was
worth saving the initial verbose output for these very rarely used modules.
- I have removed the last three arguments to the verbose handlers, leaving
only the string itself because they aren't needed anymore. For example,
ast_verbose had some logic for telling the verbose handler to add
a newline if the buffer was completely full. Now that the buffer can grow
as needed, this doesn't matter anymore.
- remove unused function, ast_verbose_dmesg() which was to dispatch the
message queue
- Convert the list of verbose handlers to use the linked list macros.
- add missing newline characters to a few ast_verbose() calls
- convert the list of log channels to use the linked list macros in logger.c
- fix close_logger() to close all of the files it opened for logging
- update ast_log() to use a thread local dynamic string for its workspace
for preparing log messages instead of a buffer of size BUFSIZ (8kB on my
system) allocated on the stack. The dynamic string in this case is limited
to only growing to a maximum size of BUFSIZ.
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@39272 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2006-08-08 06:32:04 +00:00
|
|
|
if (ast_true(s)) {
|
|
|
|
if (gethostname(hostname, sizeof(hostname) - 1)) {
|
2005-07-10 22:56:21 +00:00
|
|
|
ast_copy_string(hostname, "unknown", sizeof(hostname));
|
2007-08-28 20:03:48 +00:00
|
|
|
fprintf(stderr, "What box has no hostname???\n");
|
2004-09-05 03:48:05 +00:00
|
|
|
}
|
|
|
|
} else
|
|
|
|
hostname[0] = '\0';
|
|
|
|
} else
|
|
|
|
hostname[0] = '\0';
|
2012-03-29 20:01:20 +00:00
|
|
|
if ((s = ast_variable_retrieve(cfg, "general", "display_callids"))) {
|
|
|
|
display_callids = ast_true(s);
|
|
|
|
}
|
Merge team/russell/ast_verbose_threadstorage
- instead of defining a free() wrapper in a bunch of files, define it as
ast_free() in utils.h and remove the copies from all the files.
- centralize and abstract the code used for doing thread storage. The code
lives in threadstorage.h, with one function being implemented in utils.c.
This new API includes generic thread storage as well as special functions
for handling thread local dynamic length string buffers.
- update ast_inet_ntoa() to use the new threadstorage API
- update ast_state2str() to use the new threadstorage API
- update ast_cli() to use the new threadstorage API
- Modify manager_event() to use thread storage. Instead of using a buffer of
4096 characters as the workspace for building the manager event, use a thread
local dynamic string. Now there is no length limitation on the length of the
body of a manager event.
- Significantly simplify the handling of ast_verbose() ...
- Instead of using a static char buffer and a lock to make sure only one
thread can be using ast_verbose() at a time, use a thread local dynamic
string as the workspace for preparing the verbose message. Instead of
locking around the entire function, the only locking done now is when the
message has been built and is being deliviered to the list of registered
verbose message handlers.
- This function was doing a strdup() on every message passed to it and
keeping a queue of the last 200 messages in memory. This has been
completely removed. The only place this was used was that if there were
any messages in the verbose queue when a verbose handler was registered,
all of the messages in the queue would be fed to it. So, I just made sure
that the console verbose handler and the network verbose handler (for
remote asterisk consoles) were registered before any verbose messages.
pbx_gtkconsole and pbx_kdeconsole will now lose a few verbose messages at
startup, but I didn't feel the performance hit of this message queue was
worth saving the initial verbose output for these very rarely used modules.
- I have removed the last three arguments to the verbose handlers, leaving
only the string itself because they aren't needed anymore. For example,
ast_verbose had some logic for telling the verbose handler to add
a newline if the buffer was completely full. Now that the buffer can grow
as needed, this doesn't matter anymore.
- remove unused function, ast_verbose_dmesg() which was to dispatch the
message queue
- Convert the list of verbose handlers to use the linked list macros.
- add missing newline characters to a few ast_verbose() calls
- convert the list of log channels to use the linked list macros in logger.c
- fix close_logger() to close all of the files it opened for logging
- update ast_log() to use a thread local dynamic string for its workspace
for preparing log messages instead of a buffer of size BUFSIZ (8kB on my
system) allocated on the stack. The dynamic string in this case is limited
to only growing to a maximum size of BUFSIZ.
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@39272 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2006-08-08 06:32:04 +00:00
|
|
|
if ((s = ast_variable_retrieve(cfg, "general", "dateformat")))
|
2005-07-10 22:56:21 +00:00
|
|
|
ast_copy_string(dateformat, s, sizeof(dateformat));
|
Merge team/russell/ast_verbose_threadstorage
- instead of defining a free() wrapper in a bunch of files, define it as
ast_free() in utils.h and remove the copies from all the files.
- centralize and abstract the code used for doing thread storage. The code
lives in threadstorage.h, with one function being implemented in utils.c.
This new API includes generic thread storage as well as special functions
for handling thread local dynamic length string buffers.
- update ast_inet_ntoa() to use the new threadstorage API
- update ast_state2str() to use the new threadstorage API
- update ast_cli() to use the new threadstorage API
- Modify manager_event() to use thread storage. Instead of using a buffer of
4096 characters as the workspace for building the manager event, use a thread
local dynamic string. Now there is no length limitation on the length of the
body of a manager event.
- Significantly simplify the handling of ast_verbose() ...
- Instead of using a static char buffer and a lock to make sure only one
thread can be using ast_verbose() at a time, use a thread local dynamic
string as the workspace for preparing the verbose message. Instead of
locking around the entire function, the only locking done now is when the
message has been built and is being deliviered to the list of registered
verbose message handlers.
- This function was doing a strdup() on every message passed to it and
keeping a queue of the last 200 messages in memory. This has been
completely removed. The only place this was used was that if there were
any messages in the verbose queue when a verbose handler was registered,
all of the messages in the queue would be fed to it. So, I just made sure
that the console verbose handler and the network verbose handler (for
remote asterisk consoles) were registered before any verbose messages.
pbx_gtkconsole and pbx_kdeconsole will now lose a few verbose messages at
startup, but I didn't feel the performance hit of this message queue was
worth saving the initial verbose output for these very rarely used modules.
- I have removed the last three arguments to the verbose handlers, leaving
only the string itself because they aren't needed anymore. For example,
ast_verbose had some logic for telling the verbose handler to add
a newline if the buffer was completely full. Now that the buffer can grow
as needed, this doesn't matter anymore.
- remove unused function, ast_verbose_dmesg() which was to dispatch the
message queue
- Convert the list of verbose handlers to use the linked list macros.
- add missing newline characters to a few ast_verbose() calls
- convert the list of log channels to use the linked list macros in logger.c
- fix close_logger() to close all of the files it opened for logging
- update ast_log() to use a thread local dynamic string for its workspace
for preparing log messages instead of a buffer of size BUFSIZ (8kB on my
system) allocated on the stack. The dynamic string in this case is limited
to only growing to a maximum size of BUFSIZ.
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@39272 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2006-08-08 06:32:04 +00:00
|
|
|
else
|
2005-07-10 22:56:21 +00:00
|
|
|
ast_copy_string(dateformat, "%b %e %T", sizeof(dateformat));
|
2010-07-20 23:23:25 +00:00
|
|
|
if ((s = ast_variable_retrieve(cfg, "general", "queue_log"))) {
|
2005-03-11 08:49:01 +00:00
|
|
|
logfiles.queue_log = ast_true(s);
|
2010-07-20 23:23:25 +00:00
|
|
|
}
|
|
|
|
if ((s = ast_variable_retrieve(cfg, "general", "queue_log_to_file"))) {
|
|
|
|
logfiles.queue_log_to_file = ast_true(s);
|
|
|
|
}
|
|
|
|
if ((s = ast_variable_retrieve(cfg, "general", "queue_log_name"))) {
|
2006-09-26 17:09:01 +00:00
|
|
|
ast_copy_string(queue_log_name, s, sizeof(queue_log_name));
|
2010-07-20 23:23:25 +00:00
|
|
|
}
|
2013-01-28 01:50:54 +00:00
|
|
|
if ((s = ast_variable_retrieve(cfg, "general", "queue_log_realtime_use_gmt"))) {
|
|
|
|
logfiles.queue_log_realtime_use_gmt = ast_true(s);
|
|
|
|
}
|
2010-07-20 23:23:25 +00:00
|
|
|
if ((s = ast_variable_retrieve(cfg, "general", "exec_after_rotate"))) {
|
2007-08-28 20:03:48 +00:00
|
|
|
ast_copy_string(exec_after_rotate, s, sizeof(exec_after_rotate));
|
2010-07-20 23:23:25 +00:00
|
|
|
}
|
2007-08-28 20:03:48 +00:00
|
|
|
if ((s = ast_variable_retrieve(cfg, "general", "rotatestrategy"))) {
|
2010-07-20 23:23:25 +00:00
|
|
|
if (strcasecmp(s, "timestamp") == 0) {
|
2007-08-28 20:03:48 +00:00
|
|
|
rotatestrategy = TIMESTAMP;
|
2010-07-20 23:23:25 +00:00
|
|
|
} else if (strcasecmp(s, "rotate") == 0) {
|
2007-08-28 20:03:48 +00:00
|
|
|
rotatestrategy = ROTATE;
|
2010-07-20 23:23:25 +00:00
|
|
|
} else if (strcasecmp(s, "sequential") == 0) {
|
2007-08-28 20:03:48 +00:00
|
|
|
rotatestrategy = SEQUENTIAL;
|
2012-09-12 17:13:02 +00:00
|
|
|
} else if (strcasecmp(s, "none") == 0) {
|
|
|
|
rotatestrategy = NONE;
|
2010-07-20 23:23:25 +00:00
|
|
|
} else {
|
2007-08-28 20:03:48 +00:00
|
|
|
fprintf(stderr, "Unknown rotatestrategy: %s\n", s);
|
2010-07-20 23:23:25 +00:00
|
|
|
}
|
2007-08-28 20:03:48 +00:00
|
|
|
} else {
|
|
|
|
if ((s = ast_variable_retrieve(cfg, "general", "rotatetimestamp"))) {
|
|
|
|
rotatestrategy = ast_true(s) ? TIMESTAMP : SEQUENTIAL;
|
|
|
|
fprintf(stderr, "rotatetimestamp option has been deprecated. Please use rotatestrategy instead.\n");
|
|
|
|
}
|
|
|
|
}
|
2005-03-11 08:49:01 +00:00
|
|
|
|
2010-07-20 23:23:25 +00:00
|
|
|
if (!locked) {
|
2007-08-28 21:35:20 +00:00
|
|
|
AST_RWLIST_WRLOCK(&logchannels);
|
2010-07-20 23:23:25 +00:00
|
|
|
}
|
2002-02-11 04:25:04 +00:00
|
|
|
var = ast_variable_browse(cfg, "logfiles");
|
Merge team/russell/ast_verbose_threadstorage
- instead of defining a free() wrapper in a bunch of files, define it as
ast_free() in utils.h and remove the copies from all the files.
- centralize and abstract the code used for doing thread storage. The code
lives in threadstorage.h, with one function being implemented in utils.c.
This new API includes generic thread storage as well as special functions
for handling thread local dynamic length string buffers.
- update ast_inet_ntoa() to use the new threadstorage API
- update ast_state2str() to use the new threadstorage API
- update ast_cli() to use the new threadstorage API
- Modify manager_event() to use thread storage. Instead of using a buffer of
4096 characters as the workspace for building the manager event, use a thread
local dynamic string. Now there is no length limitation on the length of the
body of a manager event.
- Significantly simplify the handling of ast_verbose() ...
- Instead of using a static char buffer and a lock to make sure only one
thread can be using ast_verbose() at a time, use a thread local dynamic
string as the workspace for preparing the verbose message. Instead of
locking around the entire function, the only locking done now is when the
message has been built and is being deliviered to the list of registered
verbose message handlers.
- This function was doing a strdup() on every message passed to it and
keeping a queue of the last 200 messages in memory. This has been
completely removed. The only place this was used was that if there were
any messages in the verbose queue when a verbose handler was registered,
all of the messages in the queue would be fed to it. So, I just made sure
that the console verbose handler and the network verbose handler (for
remote asterisk consoles) were registered before any verbose messages.
pbx_gtkconsole and pbx_kdeconsole will now lose a few verbose messages at
startup, but I didn't feel the performance hit of this message queue was
worth saving the initial verbose output for these very rarely used modules.
- I have removed the last three arguments to the verbose handlers, leaving
only the string itself because they aren't needed anymore. For example,
ast_verbose had some logic for telling the verbose handler to add
a newline if the buffer was completely full. Now that the buffer can grow
as needed, this doesn't matter anymore.
- remove unused function, ast_verbose_dmesg() which was to dispatch the
message queue
- Convert the list of verbose handlers to use the linked list macros.
- add missing newline characters to a few ast_verbose() calls
- convert the list of log channels to use the linked list macros in logger.c
- fix close_logger() to close all of the files it opened for logging
- update ast_log() to use a thread local dynamic string for its workspace
for preparing log messages instead of a buffer of size BUFSIZ (8kB on my
system) allocated on the stack. The dynamic string in this case is limited
to only growing to a maximum size of BUFSIZ.
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@39272 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2006-08-08 06:32:04 +00:00
|
|
|
for (; var; var = var->next) {
|
2010-07-20 23:23:25 +00:00
|
|
|
if (!(chan = make_logchannel(var->name, var->value, var->lineno))) {
|
2011-08-12 16:22:45 +00:00
|
|
|
/* Print error message directly to the consoles since the lock is held
|
|
|
|
* and we don't want to unlock with the list partially built */
|
|
|
|
ast_console_puts_mutable("ERROR: Unable to create log channel '", __LOG_ERROR);
|
|
|
|
ast_console_puts_mutable(var->name, __LOG_ERROR);
|
|
|
|
ast_console_puts_mutable("'\n", __LOG_ERROR);
|
Merge team/russell/ast_verbose_threadstorage
- instead of defining a free() wrapper in a bunch of files, define it as
ast_free() in utils.h and remove the copies from all the files.
- centralize and abstract the code used for doing thread storage. The code
lives in threadstorage.h, with one function being implemented in utils.c.
This new API includes generic thread storage as well as special functions
for handling thread local dynamic length string buffers.
- update ast_inet_ntoa() to use the new threadstorage API
- update ast_state2str() to use the new threadstorage API
- update ast_cli() to use the new threadstorage API
- Modify manager_event() to use thread storage. Instead of using a buffer of
4096 characters as the workspace for building the manager event, use a thread
local dynamic string. Now there is no length limitation on the length of the
body of a manager event.
- Significantly simplify the handling of ast_verbose() ...
- Instead of using a static char buffer and a lock to make sure only one
thread can be using ast_verbose() at a time, use a thread local dynamic
string as the workspace for preparing the verbose message. Instead of
locking around the entire function, the only locking done now is when the
message has been built and is being deliviered to the list of registered
verbose message handlers.
- This function was doing a strdup() on every message passed to it and
keeping a queue of the last 200 messages in memory. This has been
completely removed. The only place this was used was that if there were
any messages in the verbose queue when a verbose handler was registered,
all of the messages in the queue would be fed to it. So, I just made sure
that the console verbose handler and the network verbose handler (for
remote asterisk consoles) were registered before any verbose messages.
pbx_gtkconsole and pbx_kdeconsole will now lose a few verbose messages at
startup, but I didn't feel the performance hit of this message queue was
worth saving the initial verbose output for these very rarely used modules.
- I have removed the last three arguments to the verbose handlers, leaving
only the string itself because they aren't needed anymore. For example,
ast_verbose had some logic for telling the verbose handler to add
a newline if the buffer was completely full. Now that the buffer can grow
as needed, this doesn't matter anymore.
- remove unused function, ast_verbose_dmesg() which was to dispatch the
message queue
- Convert the list of verbose handlers to use the linked list macros.
- add missing newline characters to a few ast_verbose() calls
- convert the list of log channels to use the linked list macros in logger.c
- fix close_logger() to close all of the files it opened for logging
- update ast_log() to use a thread local dynamic string for its workspace
for preparing log messages instead of a buffer of size BUFSIZ (8kB on my
system) allocated on the stack. The dynamic string in this case is limited
to only growing to a maximum size of BUFSIZ.
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@39272 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2006-08-08 06:32:04 +00:00
|
|
|
continue;
|
2010-07-20 23:23:25 +00:00
|
|
|
}
|
2007-07-20 01:54:52 +00:00
|
|
|
AST_RWLIST_INSERT_HEAD(&logchannels, chan, list);
|
Merge team/russell/ast_verbose_threadstorage
- instead of defining a free() wrapper in a bunch of files, define it as
ast_free() in utils.h and remove the copies from all the files.
- centralize and abstract the code used for doing thread storage. The code
lives in threadstorage.h, with one function being implemented in utils.c.
This new API includes generic thread storage as well as special functions
for handling thread local dynamic length string buffers.
- update ast_inet_ntoa() to use the new threadstorage API
- update ast_state2str() to use the new threadstorage API
- update ast_cli() to use the new threadstorage API
- Modify manager_event() to use thread storage. Instead of using a buffer of
4096 characters as the workspace for building the manager event, use a thread
local dynamic string. Now there is no length limitation on the length of the
body of a manager event.
- Significantly simplify the handling of ast_verbose() ...
- Instead of using a static char buffer and a lock to make sure only one
thread can be using ast_verbose() at a time, use a thread local dynamic
string as the workspace for preparing the verbose message. Instead of
locking around the entire function, the only locking done now is when the
message has been built and is being deliviered to the list of registered
verbose message handlers.
- This function was doing a strdup() on every message passed to it and
keeping a queue of the last 200 messages in memory. This has been
completely removed. The only place this was used was that if there were
any messages in the verbose queue when a verbose handler was registered,
all of the messages in the queue would be fed to it. So, I just made sure
that the console verbose handler and the network verbose handler (for
remote asterisk consoles) were registered before any verbose messages.
pbx_gtkconsole and pbx_kdeconsole will now lose a few verbose messages at
startup, but I didn't feel the performance hit of this message queue was
worth saving the initial verbose output for these very rarely used modules.
- I have removed the last three arguments to the verbose handlers, leaving
only the string itself because they aren't needed anymore. For example,
ast_verbose had some logic for telling the verbose handler to add
a newline if the buffer was completely full. Now that the buffer can grow
as needed, this doesn't matter anymore.
- remove unused function, ast_verbose_dmesg() which was to dispatch the
message queue
- Convert the list of verbose handlers to use the linked list macros.
- add missing newline characters to a few ast_verbose() calls
- convert the list of log channels to use the linked list macros in logger.c
- fix close_logger() to close all of the files it opened for logging
- update ast_log() to use a thread local dynamic string for its workspace
for preparing log messages instead of a buffer of size BUFSIZ (8kB on my
system) allocated on the stack. The dynamic string in this case is limited
to only growing to a maximum size of BUFSIZ.
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@39272 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2006-08-08 06:32:04 +00:00
|
|
|
global_logmask |= chan->logmask;
|
2002-02-11 04:25:04 +00:00
|
|
|
}
|
2011-08-10 20:51:07 +00:00
|
|
|
|
2010-07-20 23:23:25 +00:00
|
|
|
if (qlog) {
|
|
|
|
fclose(qlog);
|
2011-08-10 20:51:07 +00:00
|
|
|
qlog = NULL;
|
2010-07-20 23:23:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (!locked) {
|
2007-08-28 21:35:20 +00:00
|
|
|
AST_RWLIST_UNLOCK(&logchannels);
|
2010-07-20 23:23:25 +00:00
|
|
|
}
|
2004-01-12 05:05:35 +00:00
|
|
|
|
2005-01-25 06:10:20 +00:00
|
|
|
ast_config_destroy(cfg);
|
2002-02-11 04:25:04 +00:00
|
|
|
}
|
|
|
|
|
2008-04-16 22:57:54 +00:00
|
|
|
void ast_child_verbose(int level, const char *fmt, ...)
|
|
|
|
{
|
|
|
|
char *msg = NULL, *emsg = NULL, *sptr, *eptr;
|
|
|
|
va_list ap, aq;
|
|
|
|
int size;
|
|
|
|
|
|
|
|
va_start(ap, fmt);
|
|
|
|
va_copy(aq, ap);
|
|
|
|
if ((size = vsnprintf(msg, 0, fmt, ap)) < 0) {
|
|
|
|
va_end(ap);
|
|
|
|
va_end(aq);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
va_end(ap);
|
|
|
|
|
|
|
|
if (!(msg = ast_malloc(size + 1))) {
|
|
|
|
va_end(aq);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
vsnprintf(msg, size + 1, fmt, aq);
|
|
|
|
va_end(aq);
|
|
|
|
|
|
|
|
if (!(emsg = ast_malloc(size * 2 + 1))) {
|
|
|
|
ast_free(msg);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
for (sptr = msg, eptr = emsg; ; sptr++) {
|
|
|
|
if (*sptr == '"') {
|
|
|
|
*eptr++ = '\\';
|
|
|
|
}
|
|
|
|
*eptr++ = *sptr;
|
|
|
|
if (*sptr == '\0') {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
ast_free(msg);
|
|
|
|
|
|
|
|
fprintf(stdout, "verbose \"%s\" %d\n", emsg, level);
|
|
|
|
fflush(stdout);
|
|
|
|
ast_free(emsg);
|
|
|
|
}
|
|
|
|
|
2004-02-12 22:11:02 +00:00
|
|
|
void ast_queue_log(const char *queuename, const char *callid, const char *agent, const char *event, const char *fmt, ...)
|
|
|
|
{
|
|
|
|
va_list ap;
|
2010-07-20 23:23:25 +00:00
|
|
|
struct timeval tv;
|
|
|
|
struct ast_tm tm;
|
2007-07-20 01:54:52 +00:00
|
|
|
char qlog_msg[8192];
|
|
|
|
int qlog_len;
|
2010-07-20 23:23:25 +00:00
|
|
|
char time_str[30];
|
|
|
|
|
2011-08-10 20:51:07 +00:00
|
|
|
if (!logger_initialized) {
|
|
|
|
/* You are too early. We are not open yet! */
|
|
|
|
return;
|
|
|
|
}
|
2010-07-20 23:23:25 +00:00
|
|
|
if (!queuelog_init) {
|
2011-08-10 20:51:07 +00:00
|
|
|
AST_RWLIST_WRLOCK(&logchannels);
|
|
|
|
if (!queuelog_init) {
|
|
|
|
/*
|
|
|
|
* We have delayed initializing the queue logging system so
|
|
|
|
* preloaded realtime modules can get up. We must initialize
|
|
|
|
* now since someone is trying to log something.
|
|
|
|
*/
|
|
|
|
logger_queue_init();
|
|
|
|
queuelog_init = 1;
|
|
|
|
AST_RWLIST_UNLOCK(&logchannels);
|
|
|
|
ast_queue_log("NONE", "NONE", "NONE", "QUEUESTART", "%s", "");
|
|
|
|
} else {
|
|
|
|
AST_RWLIST_UNLOCK(&logchannels);
|
|
|
|
}
|
2010-07-20 23:23:25 +00:00
|
|
|
}
|
2007-12-26 15:58:17 +00:00
|
|
|
|
|
|
|
if (ast_check_realtime("queue_log")) {
|
2010-07-20 23:23:25 +00:00
|
|
|
tv = ast_tvnow();
|
2013-01-28 01:50:54 +00:00
|
|
|
ast_localtime(&tv, &tm, logfiles.queue_log_realtime_use_gmt ? "GMT" : NULL);
|
2010-07-20 23:23:25 +00:00
|
|
|
ast_strftime(time_str, sizeof(time_str), "%F %T.%6q", &tm);
|
2004-02-12 22:11:02 +00:00
|
|
|
va_start(ap, fmt);
|
2007-12-26 15:58:17 +00:00
|
|
|
vsnprintf(qlog_msg, sizeof(qlog_msg), fmt, ap);
|
2004-02-12 22:11:02 +00:00
|
|
|
va_end(ap);
|
2010-07-20 23:23:25 +00:00
|
|
|
if (logfiles.queue_adaptive_realtime) {
|
|
|
|
AST_DECLARE_APP_ARGS(args,
|
|
|
|
AST_APP_ARG(data)[5];
|
|
|
|
);
|
|
|
|
AST_NONSTANDARD_APP_ARGS(args, qlog_msg, '|');
|
|
|
|
/* Ensure fields are large enough to receive data */
|
2011-08-10 20:51:07 +00:00
|
|
|
ast_realtime_require_field("queue_log",
|
|
|
|
"data1", RQ_CHAR, strlen(S_OR(args.data[0], "")),
|
2010-07-20 23:23:25 +00:00
|
|
|
"data2", RQ_CHAR, strlen(S_OR(args.data[1], "")),
|
|
|
|
"data3", RQ_CHAR, strlen(S_OR(args.data[2], "")),
|
|
|
|
"data4", RQ_CHAR, strlen(S_OR(args.data[3], "")),
|
|
|
|
"data5", RQ_CHAR, strlen(S_OR(args.data[4], "")),
|
|
|
|
SENTINEL);
|
|
|
|
|
|
|
|
/* Store the log */
|
|
|
|
ast_store_realtime("queue_log", "time", time_str,
|
|
|
|
"callid", callid,
|
|
|
|
"queuename", queuename,
|
|
|
|
"agent", agent,
|
|
|
|
"event", event,
|
|
|
|
"data1", S_OR(args.data[0], ""),
|
|
|
|
"data2", S_OR(args.data[1], ""),
|
|
|
|
"data3", S_OR(args.data[2], ""),
|
|
|
|
"data4", S_OR(args.data[3], ""),
|
|
|
|
"data5", S_OR(args.data[4], ""),
|
|
|
|
SENTINEL);
|
|
|
|
} else {
|
|
|
|
ast_store_realtime("queue_log", "time", time_str,
|
|
|
|
"callid", callid,
|
|
|
|
"queuename", queuename,
|
|
|
|
"agent", agent,
|
|
|
|
"event", event,
|
|
|
|
"data", qlog_msg,
|
|
|
|
SENTINEL);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!logfiles.queue_log_to_file) {
|
|
|
|
return;
|
2007-12-26 15:58:17 +00:00
|
|
|
}
|
2010-07-20 23:23:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (qlog) {
|
|
|
|
va_start(ap, fmt);
|
|
|
|
qlog_len = snprintf(qlog_msg, sizeof(qlog_msg), "%ld|%s|%s|%s|%s|", (long)time(NULL), callid, queuename, agent, event);
|
|
|
|
vsnprintf(qlog_msg + qlog_len, sizeof(qlog_msg) - qlog_len, fmt, ap);
|
|
|
|
va_end(ap);
|
2007-12-26 15:58:17 +00:00
|
|
|
AST_RWLIST_RDLOCK(&logchannels);
|
|
|
|
if (qlog) {
|
|
|
|
fprintf(qlog, "%s\n", qlog_msg);
|
|
|
|
fflush(qlog);
|
|
|
|
}
|
|
|
|
AST_RWLIST_UNLOCK(&logchannels);
|
2007-07-20 01:54:52 +00:00
|
|
|
}
|
2004-02-12 22:11:02 +00:00
|
|
|
}
|
|
|
|
|
2007-08-28 20:03:48 +00:00
|
|
|
static int rotate_file(const char *filename)
|
|
|
|
{
|
|
|
|
char old[PATH_MAX];
|
|
|
|
char new[PATH_MAX];
|
|
|
|
int x, y, which, found, res = 0, fd;
|
|
|
|
char *suffixes[4] = { "", ".gz", ".bz2", ".Z" };
|
|
|
|
|
|
|
|
switch (rotatestrategy) {
|
2012-09-12 17:13:02 +00:00
|
|
|
case NONE:
|
|
|
|
/* No rotation */
|
|
|
|
break;
|
2007-08-28 20:03:48 +00:00
|
|
|
case SEQUENTIAL:
|
|
|
|
for (x = 0; ; x++) {
|
|
|
|
snprintf(new, sizeof(new), "%s.%d", filename, x);
|
|
|
|
fd = open(new, O_RDONLY);
|
|
|
|
if (fd > -1)
|
|
|
|
close(fd);
|
|
|
|
else
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (rename(filename, new)) {
|
|
|
|
fprintf(stderr, "Unable to rename file '%s' to '%s'\n", filename, new);
|
|
|
|
res = -1;
|
2010-07-20 23:23:25 +00:00
|
|
|
} else {
|
|
|
|
filename = new;
|
2007-08-28 20:03:48 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
case TIMESTAMP:
|
|
|
|
snprintf(new, sizeof(new), "%s.%ld", filename, (long)time(NULL));
|
|
|
|
if (rename(filename, new)) {
|
|
|
|
fprintf(stderr, "Unable to rename file '%s' to '%s'\n", filename, new);
|
|
|
|
res = -1;
|
2010-07-20 23:23:25 +00:00
|
|
|
} else {
|
|
|
|
filename = new;
|
2007-08-28 20:03:48 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
case ROTATE:
|
|
|
|
/* Find the next empty slot, including a possible suffix */
|
|
|
|
for (x = 0; ; x++) {
|
|
|
|
found = 0;
|
2008-07-08 16:40:28 +00:00
|
|
|
for (which = 0; which < ARRAY_LEN(suffixes); which++) {
|
2007-08-28 20:03:48 +00:00
|
|
|
snprintf(new, sizeof(new), "%s.%d%s", filename, x, suffixes[which]);
|
|
|
|
fd = open(new, O_RDONLY);
|
2008-07-16 00:52:48 +00:00
|
|
|
if (fd > -1) {
|
2007-08-28 20:03:48 +00:00
|
|
|
close(fd);
|
|
|
|
found = 1;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2008-07-16 00:52:48 +00:00
|
|
|
if (!found) {
|
2007-08-28 20:03:48 +00:00
|
|
|
break;
|
2008-07-16 00:52:48 +00:00
|
|
|
}
|
2007-08-28 20:03:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Found an empty slot */
|
2008-07-16 00:52:48 +00:00
|
|
|
for (y = x; y > 0; y--) {
|
2008-07-08 16:40:28 +00:00
|
|
|
for (which = 0; which < ARRAY_LEN(suffixes); which++) {
|
2007-08-28 20:03:48 +00:00
|
|
|
snprintf(old, sizeof(old), "%s.%d%s", filename, y - 1, suffixes[which]);
|
|
|
|
fd = open(old, O_RDONLY);
|
|
|
|
if (fd > -1) {
|
|
|
|
/* Found the right suffix */
|
|
|
|
close(fd);
|
|
|
|
snprintf(new, sizeof(new), "%s.%d%s", filename, y, suffixes[which]);
|
|
|
|
if (rename(old, new)) {
|
|
|
|
fprintf(stderr, "Unable to rename file '%s' to '%s'\n", old, new);
|
|
|
|
res = -1;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Finally, rename the current file */
|
|
|
|
snprintf(new, sizeof(new), "%s.0", filename);
|
|
|
|
if (rename(filename, new)) {
|
|
|
|
fprintf(stderr, "Unable to rename file '%s' to '%s'\n", filename, new);
|
|
|
|
res = -1;
|
2011-08-10 20:51:07 +00:00
|
|
|
} else {
|
|
|
|
filename = new;
|
2007-08-28 20:03:48 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!ast_strlen_zero(exec_after_rotate)) {
|
2009-06-26 15:28:53 +00:00
|
|
|
struct ast_channel *c = ast_dummy_channel_alloc();
|
This commits the performance mods that give the priority processing engine in the pbx, a 25-30% speed boost. The two updates used, are, first, to merge the ast_exists_extension() and the ast_spawn_extension() where they are called sequentially in a loop in the code, into a slightly upgraded version of ast_spawn_extension(), with a few extra args; and, second, I modified the substitute_variables_helper_full, so it zeroes out the byte after the evaluated string instead of demanding you pre-zero the buffer; I also went thru the code and removed the code that zeroed this buffer before every call to the substitute_variables_helper_full. The first fix provides about a 9% speedup, and the second the rest. These figures come from the 'PIPS' benchmark I describe in blogs, conf. reports, etc.
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@88166 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2007-11-01 22:26:51 +00:00
|
|
|
char buf[512];
|
2011-09-26 19:40:12 +00:00
|
|
|
|
2007-08-28 20:03:48 +00:00
|
|
|
pbx_builtin_setvar_helper(c, "filename", filename);
|
|
|
|
pbx_substitute_variables_helper(c, exec_after_rotate, buf, sizeof(buf));
|
2011-09-26 19:40:12 +00:00
|
|
|
if (c) {
|
|
|
|
c = ast_channel_unref(c);
|
|
|
|
}
|
2009-08-17 18:18:16 +00:00
|
|
|
if (ast_safe_system(buf) == -1) {
|
2009-01-09 16:32:34 +00:00
|
|
|
ast_log(LOG_WARNING, "error executing '%s'\n", buf);
|
2008-11-02 18:52:13 +00:00
|
|
|
}
|
2007-08-28 20:03:48 +00:00
|
|
|
}
|
|
|
|
return res;
|
|
|
|
}
|
|
|
|
|
2011-08-10 20:51:07 +00:00
|
|
|
/*!
|
|
|
|
* \internal
|
|
|
|
* \brief Start the realtime queue logging if configured.
|
|
|
|
*
|
|
|
|
* \retval TRUE if not to open queue log file.
|
|
|
|
*/
|
|
|
|
static int logger_queue_rt_start(void)
|
|
|
|
{
|
|
|
|
if (ast_check_realtime("queue_log")) {
|
|
|
|
if (!ast_realtime_require_field("queue_log",
|
|
|
|
"time", RQ_DATETIME, 26,
|
|
|
|
"data1", RQ_CHAR, 20,
|
|
|
|
"data2", RQ_CHAR, 20,
|
|
|
|
"data3", RQ_CHAR, 20,
|
|
|
|
"data4", RQ_CHAR, 20,
|
|
|
|
"data5", RQ_CHAR, 20,
|
|
|
|
SENTINEL)) {
|
|
|
|
logfiles.queue_adaptive_realtime = 1;
|
|
|
|
} else {
|
|
|
|
logfiles.queue_adaptive_realtime = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!logfiles.queue_log_to_file) {
|
|
|
|
/* Don't open the log file. */
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*!
|
|
|
|
* \internal
|
|
|
|
* \brief Rotate the queue log file and restart.
|
|
|
|
*
|
|
|
|
* \param queue_rotate Log queue rotation mode.
|
|
|
|
*
|
|
|
|
* \note Assumes logchannels is write locked on entry.
|
|
|
|
*
|
|
|
|
* \retval 0 on success.
|
|
|
|
* \retval -1 on error.
|
|
|
|
*/
|
|
|
|
static int logger_queue_restart(int queue_rotate)
|
|
|
|
{
|
|
|
|
int res = 0;
|
|
|
|
char qfname[PATH_MAX];
|
|
|
|
|
|
|
|
if (logger_queue_rt_start()) {
|
|
|
|
return res;
|
|
|
|
}
|
|
|
|
|
|
|
|
snprintf(qfname, sizeof(qfname), "%s/%s", ast_config_AST_LOG_DIR, queue_log_name);
|
|
|
|
if (qlog) {
|
|
|
|
/* Just in case it was still open. */
|
|
|
|
fclose(qlog);
|
|
|
|
qlog = NULL;
|
|
|
|
}
|
|
|
|
if (queue_rotate) {
|
|
|
|
rotate_file(qfname);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Open the log file. */
|
|
|
|
qlog = fopen(qfname, "a");
|
|
|
|
if (!qlog) {
|
|
|
|
ast_log(LOG_ERROR, "Unable to create queue log: %s\n", strerror(errno));
|
|
|
|
res = -1;
|
|
|
|
}
|
|
|
|
return res;
|
|
|
|
}
|
|
|
|
|
2010-12-31 09:21:47 +00:00
|
|
|
static int reload_logger(int rotate, const char *altconf)
|
1999-12-05 07:28:29 +00:00
|
|
|
{
|
2009-05-02 19:02:22 +00:00
|
|
|
int queue_rotate = rotate;
|
2004-01-12 05:05:35 +00:00
|
|
|
struct logchannel *f;
|
2007-08-28 20:03:48 +00:00
|
|
|
int res = 0;
|
2005-03-31 19:08:51 +00:00
|
|
|
|
2007-07-20 01:54:52 +00:00
|
|
|
AST_RWLIST_WRLOCK(&logchannels);
|
Merge team/russell/ast_verbose_threadstorage
- instead of defining a free() wrapper in a bunch of files, define it as
ast_free() in utils.h and remove the copies from all the files.
- centralize and abstract the code used for doing thread storage. The code
lives in threadstorage.h, with one function being implemented in utils.c.
This new API includes generic thread storage as well as special functions
for handling thread local dynamic length string buffers.
- update ast_inet_ntoa() to use the new threadstorage API
- update ast_state2str() to use the new threadstorage API
- update ast_cli() to use the new threadstorage API
- Modify manager_event() to use thread storage. Instead of using a buffer of
4096 characters as the workspace for building the manager event, use a thread
local dynamic string. Now there is no length limitation on the length of the
body of a manager event.
- Significantly simplify the handling of ast_verbose() ...
- Instead of using a static char buffer and a lock to make sure only one
thread can be using ast_verbose() at a time, use a thread local dynamic
string as the workspace for preparing the verbose message. Instead of
locking around the entire function, the only locking done now is when the
message has been built and is being deliviered to the list of registered
verbose message handlers.
- This function was doing a strdup() on every message passed to it and
keeping a queue of the last 200 messages in memory. This has been
completely removed. The only place this was used was that if there were
any messages in the verbose queue when a verbose handler was registered,
all of the messages in the queue would be fed to it. So, I just made sure
that the console verbose handler and the network verbose handler (for
remote asterisk consoles) were registered before any verbose messages.
pbx_gtkconsole and pbx_kdeconsole will now lose a few verbose messages at
startup, but I didn't feel the performance hit of this message queue was
worth saving the initial verbose output for these very rarely used modules.
- I have removed the last three arguments to the verbose handlers, leaving
only the string itself because they aren't needed anymore. For example,
ast_verbose had some logic for telling the verbose handler to add
a newline if the buffer was completely full. Now that the buffer can grow
as needed, this doesn't matter anymore.
- remove unused function, ast_verbose_dmesg() which was to dispatch the
message queue
- Convert the list of verbose handlers to use the linked list macros.
- add missing newline characters to a few ast_verbose() calls
- convert the list of log channels to use the linked list macros in logger.c
- fix close_logger() to close all of the files it opened for logging
- update ast_log() to use a thread local dynamic string for its workspace
for preparing log messages instead of a buffer of size BUFSIZ (8kB on my
system) allocated on the stack. The dynamic string in this case is limited
to only growing to a maximum size of BUFSIZ.
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@39272 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2006-08-08 06:32:04 +00:00
|
|
|
|
2007-08-28 20:03:48 +00:00
|
|
|
if (qlog) {
|
|
|
|
if (rotate < 0) {
|
|
|
|
/* Check filesize - this one typically doesn't need an auto-rotate */
|
2010-07-20 23:23:25 +00:00
|
|
|
if (ftello(qlog) > 0x40000000) { /* Arbitrarily, 1 GB */
|
2007-08-28 20:03:48 +00:00
|
|
|
fclose(qlog);
|
|
|
|
qlog = NULL;
|
2010-07-20 23:23:25 +00:00
|
|
|
} else {
|
2009-05-02 18:39:48 +00:00
|
|
|
queue_rotate = 0;
|
2010-07-20 23:23:25 +00:00
|
|
|
}
|
2007-08-28 20:03:48 +00:00
|
|
|
} else {
|
|
|
|
fclose(qlog);
|
|
|
|
qlog = NULL;
|
|
|
|
}
|
2010-07-20 23:23:25 +00:00
|
|
|
} else {
|
2006-02-26 16:40:39 +00:00
|
|
|
queue_rotate = 0;
|
2010-07-20 23:23:25 +00:00
|
|
|
}
|
2003-11-26 22:00:07 +00:00
|
|
|
|
2007-06-22 04:35:12 +00:00
|
|
|
ast_mkdir(ast_config_AST_LOG_DIR, 0777);
|
2003-11-26 22:00:07 +00:00
|
|
|
|
2007-07-20 01:54:52 +00:00
|
|
|
AST_RWLIST_TRAVERSE(&logchannels, f, list) {
|
2005-03-31 19:08:51 +00:00
|
|
|
if (f->disabled) {
|
|
|
|
f->disabled = 0; /* Re-enable logging at reload */
|
2012-07-10 22:26:27 +00:00
|
|
|
/*** DOCUMENTATION
|
|
|
|
<managerEventInstance>
|
|
|
|
<synopsis>Raised when a logging channel is re-enabled after a reload operation.</synopsis>
|
|
|
|
<syntax>
|
|
|
|
<parameter name="Channel">
|
|
|
|
<para>The name of the logging channel.</para>
|
|
|
|
</parameter>
|
|
|
|
</syntax>
|
|
|
|
</managerEventInstance>
|
|
|
|
***/
|
2005-03-31 19:08:51 +00:00
|
|
|
manager_event(EVENT_FLAG_SYSTEM, "LogChannel", "Channel: %s\r\nEnabled: Yes\r\n", f->filename);
|
|
|
|
}
|
2004-01-12 05:05:35 +00:00
|
|
|
if (f->fileptr && (f->fileptr != stdout) && (f->fileptr != stderr)) {
|
2010-07-20 23:23:25 +00:00
|
|
|
int rotate_this = 0;
|
2012-09-12 17:13:02 +00:00
|
|
|
if (rotatestrategy != NONE && ftello(f->fileptr) > 0x40000000) { /* Arbitrarily, 1 GB */
|
2010-07-20 23:23:25 +00:00
|
|
|
/* Be more proactive about rotating massive log files */
|
|
|
|
rotate_this = 1;
|
|
|
|
}
|
2005-03-31 19:08:51 +00:00
|
|
|
fclose(f->fileptr); /* Close file */
|
2004-01-12 05:05:35 +00:00
|
|
|
f->fileptr = NULL;
|
2010-07-20 23:23:25 +00:00
|
|
|
if (rotate || rotate_this) {
|
2007-08-28 20:03:48 +00:00
|
|
|
rotate_file(f->filename);
|
2010-07-20 23:23:25 +00:00
|
|
|
}
|
2004-01-12 05:05:35 +00:00
|
|
|
}
|
2003-11-26 22:00:07 +00:00
|
|
|
}
|
|
|
|
|
2005-07-05 20:31:34 +00:00
|
|
|
filesize_reload_needed = 0;
|
2007-08-28 20:03:48 +00:00
|
|
|
|
2010-12-31 09:21:47 +00:00
|
|
|
init_logger_chain(1 /* locked */, altconf);
|
2005-03-11 08:49:01 +00:00
|
|
|
|
2011-08-10 20:51:07 +00:00
|
|
|
ast_unload_realtime("queue_log");
|
2006-02-26 16:40:39 +00:00
|
|
|
if (logfiles.queue_log) {
|
2011-08-10 20:51:07 +00:00
|
|
|
res = logger_queue_restart(queue_rotate);
|
|
|
|
AST_RWLIST_UNLOCK(&logchannels);
|
|
|
|
ast_queue_log("NONE", "NONE", "NONE", "CONFIGRELOAD", "%s", "");
|
|
|
|
ast_verb(1, "Asterisk Queue Logger restarted\n");
|
|
|
|
} else {
|
|
|
|
AST_RWLIST_UNLOCK(&logchannels);
|
2006-02-26 16:40:39 +00:00
|
|
|
}
|
Merge team/russell/ast_verbose_threadstorage
- instead of defining a free() wrapper in a bunch of files, define it as
ast_free() in utils.h and remove the copies from all the files.
- centralize and abstract the code used for doing thread storage. The code
lives in threadstorage.h, with one function being implemented in utils.c.
This new API includes generic thread storage as well as special functions
for handling thread local dynamic length string buffers.
- update ast_inet_ntoa() to use the new threadstorage API
- update ast_state2str() to use the new threadstorage API
- update ast_cli() to use the new threadstorage API
- Modify manager_event() to use thread storage. Instead of using a buffer of
4096 characters as the workspace for building the manager event, use a thread
local dynamic string. Now there is no length limitation on the length of the
body of a manager event.
- Significantly simplify the handling of ast_verbose() ...
- Instead of using a static char buffer and a lock to make sure only one
thread can be using ast_verbose() at a time, use a thread local dynamic
string as the workspace for preparing the verbose message. Instead of
locking around the entire function, the only locking done now is when the
message has been built and is being deliviered to the list of registered
verbose message handlers.
- This function was doing a strdup() on every message passed to it and
keeping a queue of the last 200 messages in memory. This has been
completely removed. The only place this was used was that if there were
any messages in the verbose queue when a verbose handler was registered,
all of the messages in the queue would be fed to it. So, I just made sure
that the console verbose handler and the network verbose handler (for
remote asterisk consoles) were registered before any verbose messages.
pbx_gtkconsole and pbx_kdeconsole will now lose a few verbose messages at
startup, but I didn't feel the performance hit of this message queue was
worth saving the initial verbose output for these very rarely used modules.
- I have removed the last three arguments to the verbose handlers, leaving
only the string itself because they aren't needed anymore. For example,
ast_verbose had some logic for telling the verbose handler to add
a newline if the buffer was completely full. Now that the buffer can grow
as needed, this doesn't matter anymore.
- remove unused function, ast_verbose_dmesg() which was to dispatch the
message queue
- Convert the list of verbose handlers to use the linked list macros.
- add missing newline characters to a few ast_verbose() calls
- convert the list of log channels to use the linked list macros in logger.c
- fix close_logger() to close all of the files it opened for logging
- update ast_log() to use a thread local dynamic string for its workspace
for preparing log messages instead of a buffer of size BUFSIZ (8kB on my
system) allocated on the stack. The dynamic string in this case is limited
to only growing to a maximum size of BUFSIZ.
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@39272 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2006-08-08 06:32:04 +00:00
|
|
|
|
2006-02-26 16:40:39 +00:00
|
|
|
return res;
|
2002-02-11 04:25:04 +00:00
|
|
|
}
|
|
|
|
|
2007-12-06 14:23:12 +00:00
|
|
|
/*! \brief Reload the logger module without rotating log files (also used from loader.c during
|
|
|
|
a full Asterisk reload) */
|
|
|
|
int logger_reload(void)
|
|
|
|
{
|
2010-12-31 09:21:47 +00:00
|
|
|
if (reload_logger(0, NULL)) {
|
2007-12-06 14:23:12 +00:00
|
|
|
return RESULT_FAILURE;
|
2010-07-25 17:33:45 +00:00
|
|
|
}
|
2007-12-06 14:23:12 +00:00
|
|
|
return RESULT_SUCCESS;
|
|
|
|
}
|
|
|
|
|
2007-09-18 22:43:45 +00:00
|
|
|
static char *handle_logger_reload(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
|
2003-10-02 06:40:10 +00:00
|
|
|
{
|
2007-09-18 22:43:45 +00:00
|
|
|
switch (cmd) {
|
|
|
|
case CLI_INIT:
|
|
|
|
e->command = "logger reload";
|
2010-12-31 09:21:47 +00:00
|
|
|
e->usage =
|
|
|
|
"Usage: logger reload [<alt-conf>]\n"
|
2007-09-18 22:43:45 +00:00
|
|
|
" Reloads the logger subsystem state. Use after restarting syslogd(8) if you are using syslog logging.\n";
|
|
|
|
return NULL;
|
|
|
|
case CLI_GENERATE:
|
|
|
|
return NULL;
|
|
|
|
}
|
2010-12-31 09:21:47 +00:00
|
|
|
if (reload_logger(0, a->argc == 3 ? a->argv[2] : NULL)) {
|
2007-09-18 22:43:45 +00:00
|
|
|
ast_cli(a->fd, "Failed to reload the logger\n");
|
|
|
|
return CLI_FAILURE;
|
2007-12-06 14:23:12 +00:00
|
|
|
}
|
|
|
|
return CLI_SUCCESS;
|
2003-11-26 22:00:07 +00:00
|
|
|
}
|
|
|
|
|
2007-09-18 22:43:45 +00:00
|
|
|
static char *handle_logger_rotate(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
|
2003-11-26 22:00:07 +00:00
|
|
|
{
|
2007-09-18 22:43:45 +00:00
|
|
|
switch (cmd) {
|
|
|
|
case CLI_INIT:
|
|
|
|
e->command = "logger rotate";
|
2012-03-22 19:51:16 +00:00
|
|
|
e->usage =
|
2007-09-18 22:43:45 +00:00
|
|
|
"Usage: logger rotate\n"
|
|
|
|
" Rotates and Reopens the log files.\n";
|
|
|
|
return NULL;
|
|
|
|
case CLI_GENERATE:
|
2012-03-22 19:51:16 +00:00
|
|
|
return NULL;
|
2007-09-18 22:43:45 +00:00
|
|
|
}
|
2010-12-31 09:21:47 +00:00
|
|
|
if (reload_logger(1, NULL)) {
|
2007-09-18 22:43:45 +00:00
|
|
|
ast_cli(a->fd, "Failed to reload the logger and rotate log files\n");
|
|
|
|
return CLI_FAILURE;
|
2012-03-22 19:51:16 +00:00
|
|
|
}
|
2007-12-06 14:23:12 +00:00
|
|
|
return CLI_SUCCESS;
|
2003-10-02 06:40:10 +00:00
|
|
|
}
|
|
|
|
|
2008-05-29 21:30:37 +00:00
|
|
|
static char *handle_logger_set_level(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
|
|
|
|
{
|
|
|
|
int x;
|
|
|
|
int state;
|
|
|
|
int level = -1;
|
|
|
|
|
|
|
|
switch (cmd) {
|
|
|
|
case CLI_INIT:
|
2010-04-12 14:39:37 +00:00
|
|
|
e->command = "logger set level {DEBUG|NOTICE|WARNING|ERROR|VERBOSE|DTMF} {on|off}";
|
2012-03-22 19:51:16 +00:00
|
|
|
e->usage =
|
2010-04-12 14:39:37 +00:00
|
|
|
"Usage: logger set level {DEBUG|NOTICE|WARNING|ERROR|VERBOSE|DTMF} {on|off}\n"
|
2008-05-29 21:30:37 +00:00
|
|
|
" Set a specific log level to enabled/disabled for this console.\n";
|
|
|
|
return NULL;
|
|
|
|
case CLI_GENERATE:
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (a->argc < 5)
|
|
|
|
return CLI_SHOWUSAGE;
|
|
|
|
|
2009-05-15 13:13:47 +00:00
|
|
|
AST_RWLIST_WRLOCK(&logchannels);
|
|
|
|
|
|
|
|
for (x = 0; x < ARRAY_LEN(levels); x++) {
|
|
|
|
if (levels[x] && !strcasecmp(a->argv[3], levels[x])) {
|
2008-05-29 21:30:37 +00:00
|
|
|
level = x;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-05-15 13:13:47 +00:00
|
|
|
AST_RWLIST_UNLOCK(&logchannels);
|
|
|
|
|
2008-05-29 21:30:37 +00:00
|
|
|
state = ast_true(a->argv[4]) ? 1 : 0;
|
|
|
|
|
|
|
|
if (level != -1) {
|
|
|
|
ast_console_toggle_loglevel(a->fd, level, state);
|
|
|
|
ast_cli(a->fd, "Logger status for '%s' has been set to '%s'.\n", levels[level], state ? "on" : "off");
|
|
|
|
} else
|
|
|
|
return CLI_SHOWUSAGE;
|
|
|
|
|
|
|
|
return CLI_SUCCESS;
|
|
|
|
}
|
|
|
|
|
2006-01-20 00:18:42 +00:00
|
|
|
/*! \brief CLI command to show logging system configuration */
|
2007-09-18 22:43:45 +00:00
|
|
|
static char *handle_logger_show_channels(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
|
2005-03-31 19:08:51 +00:00
|
|
|
{
|
|
|
|
#define FORMATL "%-35.35s %-8.8s %-9.9s "
|
|
|
|
struct logchannel *chan;
|
2007-09-18 22:43:45 +00:00
|
|
|
switch (cmd) {
|
|
|
|
case CLI_INIT:
|
|
|
|
e->command = "logger show channels";
|
2012-03-22 19:51:16 +00:00
|
|
|
e->usage =
|
2007-09-18 22:43:45 +00:00
|
|
|
"Usage: logger show channels\n"
|
|
|
|
" List configured logger channels.\n";
|
|
|
|
return NULL;
|
|
|
|
case CLI_GENERATE:
|
2012-03-22 19:51:16 +00:00
|
|
|
return NULL;
|
2007-09-18 22:43:45 +00:00
|
|
|
}
|
2008-03-04 23:04:29 +00:00
|
|
|
ast_cli(a->fd, FORMATL, "Channel", "Type", "Status");
|
2007-09-18 22:43:45 +00:00
|
|
|
ast_cli(a->fd, "Configuration\n");
|
2008-03-04 23:04:29 +00:00
|
|
|
ast_cli(a->fd, FORMATL, "-------", "----", "------");
|
2007-09-18 22:43:45 +00:00
|
|
|
ast_cli(a->fd, "-------------\n");
|
2007-07-20 01:54:52 +00:00
|
|
|
AST_RWLIST_RDLOCK(&logchannels);
|
|
|
|
AST_RWLIST_TRAVERSE(&logchannels, chan, list) {
|
2009-05-15 13:13:47 +00:00
|
|
|
unsigned int level;
|
|
|
|
|
2008-03-04 23:04:29 +00:00
|
|
|
ast_cli(a->fd, FORMATL, chan->filename, chan->type == LOGTYPE_CONSOLE ? "Console" : (chan->type == LOGTYPE_SYSLOG ? "Syslog" : "File"),
|
2005-03-31 19:08:51 +00:00
|
|
|
chan->disabled ? "Disabled" : "Enabled");
|
2007-09-18 22:43:45 +00:00
|
|
|
ast_cli(a->fd, " - ");
|
2009-05-15 13:13:47 +00:00
|
|
|
for (level = 0; level < ARRAY_LEN(levels); level++) {
|
2010-06-10 12:28:17 +00:00
|
|
|
if ((chan->logmask & (1 << level)) && levels[level]) {
|
2009-05-15 13:13:47 +00:00
|
|
|
ast_cli(a->fd, "%s ", levels[level]);
|
|
|
|
}
|
|
|
|
}
|
2007-09-18 22:43:45 +00:00
|
|
|
ast_cli(a->fd, "\n");
|
2005-03-31 19:08:51 +00:00
|
|
|
}
|
2007-07-20 01:54:52 +00:00
|
|
|
AST_RWLIST_UNLOCK(&logchannels);
|
2007-09-18 22:43:45 +00:00
|
|
|
ast_cli(a->fd, "\n");
|
2010-05-26 21:17:46 +00:00
|
|
|
|
2007-09-18 22:43:45 +00:00
|
|
|
return CLI_SUCCESS;
|
2005-03-31 19:08:51 +00:00
|
|
|
}
|
|
|
|
|
Merge team/russell/ast_verbose_threadstorage
- instead of defining a free() wrapper in a bunch of files, define it as
ast_free() in utils.h and remove the copies from all the files.
- centralize and abstract the code used for doing thread storage. The code
lives in threadstorage.h, with one function being implemented in utils.c.
This new API includes generic thread storage as well as special functions
for handling thread local dynamic length string buffers.
- update ast_inet_ntoa() to use the new threadstorage API
- update ast_state2str() to use the new threadstorage API
- update ast_cli() to use the new threadstorage API
- Modify manager_event() to use thread storage. Instead of using a buffer of
4096 characters as the workspace for building the manager event, use a thread
local dynamic string. Now there is no length limitation on the length of the
body of a manager event.
- Significantly simplify the handling of ast_verbose() ...
- Instead of using a static char buffer and a lock to make sure only one
thread can be using ast_verbose() at a time, use a thread local dynamic
string as the workspace for preparing the verbose message. Instead of
locking around the entire function, the only locking done now is when the
message has been built and is being deliviered to the list of registered
verbose message handlers.
- This function was doing a strdup() on every message passed to it and
keeping a queue of the last 200 messages in memory. This has been
completely removed. The only place this was used was that if there were
any messages in the verbose queue when a verbose handler was registered,
all of the messages in the queue would be fed to it. So, I just made sure
that the console verbose handler and the network verbose handler (for
remote asterisk consoles) were registered before any verbose messages.
pbx_gtkconsole and pbx_kdeconsole will now lose a few verbose messages at
startup, but I didn't feel the performance hit of this message queue was
worth saving the initial verbose output for these very rarely used modules.
- I have removed the last three arguments to the verbose handlers, leaving
only the string itself because they aren't needed anymore. For example,
ast_verbose had some logic for telling the verbose handler to add
a newline if the buffer was completely full. Now that the buffer can grow
as needed, this doesn't matter anymore.
- remove unused function, ast_verbose_dmesg() which was to dispatch the
message queue
- Convert the list of verbose handlers to use the linked list macros.
- add missing newline characters to a few ast_verbose() calls
- convert the list of log channels to use the linked list macros in logger.c
- fix close_logger() to close all of the files it opened for logging
- update ast_log() to use a thread local dynamic string for its workspace
for preparing log messages instead of a buffer of size BUFSIZ (8kB on my
system) allocated on the stack. The dynamic string in this case is limited
to only growing to a maximum size of BUFSIZ.
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@39272 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2006-08-08 06:32:04 +00:00
|
|
|
struct verb {
|
|
|
|
void (*verboser)(const char *string);
|
|
|
|
AST_LIST_ENTRY(verb) list;
|
|
|
|
};
|
2003-10-02 06:40:10 +00:00
|
|
|
|
2007-07-20 01:54:52 +00:00
|
|
|
static AST_RWLIST_HEAD_STATIC(verbosers, verb);
|
2003-10-02 06:40:10 +00:00
|
|
|
|
2006-09-18 19:54:18 +00:00
|
|
|
static struct ast_cli_entry cli_logger[] = {
|
2007-10-22 20:05:18 +00:00
|
|
|
AST_CLI_DEFINE(handle_logger_show_channels, "List configured log channels"),
|
|
|
|
AST_CLI_DEFINE(handle_logger_reload, "Reopens the log files"),
|
2008-05-29 21:30:37 +00:00
|
|
|
AST_CLI_DEFINE(handle_logger_rotate, "Rotates and reopens the log files"),
|
|
|
|
AST_CLI_DEFINE(handle_logger_set_level, "Enables/Disables a specific logging level for this console")
|
2006-09-18 19:54:18 +00:00
|
|
|
};
|
2003-11-26 22:00:07 +00:00
|
|
|
|
2010-05-26 21:17:46 +00:00
|
|
|
static void _handle_SIGXFSZ(int sig)
|
2004-06-29 04:42:19 +00:00
|
|
|
{
|
2004-03-30 16:16:05 +00:00
|
|
|
/* Indicate need to reload */
|
2005-07-05 20:31:34 +00:00
|
|
|
filesize_reload_needed = 1;
|
2003-11-26 22:00:07 +00:00
|
|
|
}
|
|
|
|
|
2010-05-26 21:17:46 +00:00
|
|
|
static struct sigaction handle_SIGXFSZ = {
|
|
|
|
.sa_handler = _handle_SIGXFSZ,
|
2010-06-10 08:15:45 +00:00
|
|
|
.sa_flags = SA_RESTART,
|
2010-05-26 21:17:46 +00:00
|
|
|
};
|
|
|
|
|
2009-06-25 17:01:32 +00:00
|
|
|
static void ast_log_vsyslog(struct logmsg *msg)
|
2006-12-21 21:57:16 +00:00
|
|
|
{
|
|
|
|
char buf[BUFSIZ];
|
2009-06-25 23:54:03 +00:00
|
|
|
int syslog_level = ast_syslog_priority_from_loglevel(msg->level);
|
2013-05-13 21:21:03 +00:00
|
|
|
char call_identifier_str[13];
|
|
|
|
|
|
|
|
if (msg->callid) {
|
|
|
|
snprintf(call_identifier_str, sizeof(call_identifier_str), "[C-%08x]", msg->callid->call_identifier);
|
|
|
|
} else {
|
|
|
|
call_identifier_str[0] = '\0';
|
|
|
|
}
|
2006-12-21 21:57:16 +00:00
|
|
|
|
2009-06-25 23:54:03 +00:00
|
|
|
if (syslog_level < 0) {
|
2006-12-21 21:57:16 +00:00
|
|
|
/* we are locked here, so cannot ast_log() */
|
2009-06-25 17:01:32 +00:00
|
|
|
fprintf(stderr, "ast_log_vsyslog called with bogus level: %d\n", msg->level);
|
2006-12-21 21:57:16 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2013-05-13 21:21:03 +00:00
|
|
|
snprintf(buf, sizeof(buf), "%s[%d]%s: %s:%d in %s: %s",
|
|
|
|
levels[msg->level], msg->lwp, call_identifier_str, msg->file, msg->line, msg->function, msg->message);
|
2006-12-21 21:57:16 +00:00
|
|
|
|
2008-03-04 23:04:29 +00:00
|
|
|
term_strip(buf, buf, strlen(buf) + 1);
|
2009-06-25 23:54:03 +00:00
|
|
|
syslog(syslog_level, "%s", buf);
|
2006-12-21 21:57:16 +00:00
|
|
|
}
|
|
|
|
|
2012-02-14 20:27:16 +00:00
|
|
|
/* These gymnastics are due to platforms which designate char as unsigned by
|
|
|
|
* default. Level is the negative character -- offset by 1, because \0 is the
|
|
|
|
* EOS delimiter. */
|
|
|
|
#define VERBOSE_MAGIC2LEVEL(x) (((char) -*(signed char *) (x)) - 1)
|
|
|
|
#define VERBOSE_HASMAGIC(x) (*(signed char *) (x) < 0)
|
|
|
|
|
2007-12-06 14:29:20 +00:00
|
|
|
/*! \brief Print a normal log message to the channels */
|
2006-12-21 21:57:16 +00:00
|
|
|
static void logger_print_normal(struct logmsg *logmsg)
|
|
|
|
{
|
|
|
|
struct logchannel *chan = NULL;
|
|
|
|
char buf[BUFSIZ];
|
2010-09-20 21:25:01 +00:00
|
|
|
struct verb *v = NULL;
|
2012-02-14 20:27:16 +00:00
|
|
|
int level = 0;
|
2010-09-20 21:25:01 +00:00
|
|
|
|
|
|
|
if (logmsg->level == __LOG_VERBOSE) {
|
|
|
|
char *tmpmsg = ast_strdupa(logmsg->message + 1);
|
2012-02-14 20:27:16 +00:00
|
|
|
level = VERBOSE_MAGIC2LEVEL(logmsg->message);
|
2010-09-20 21:25:01 +00:00
|
|
|
/* Iterate through the list of verbosers and pass them the log message string */
|
|
|
|
AST_RWLIST_RDLOCK(&verbosers);
|
|
|
|
AST_RWLIST_TRAVERSE(&verbosers, v, list)
|
|
|
|
v->verboser(logmsg->message);
|
|
|
|
AST_RWLIST_UNLOCK(&verbosers);
|
|
|
|
ast_string_field_set(logmsg, message, tmpmsg);
|
|
|
|
}
|
2006-12-21 21:57:16 +00:00
|
|
|
|
2007-07-20 01:54:52 +00:00
|
|
|
AST_RWLIST_RDLOCK(&logchannels);
|
2006-12-21 21:57:16 +00:00
|
|
|
|
2007-07-20 01:54:52 +00:00
|
|
|
if (!AST_RWLIST_EMPTY(&logchannels)) {
|
|
|
|
AST_RWLIST_TRAVERSE(&logchannels, chan, list) {
|
2012-06-20 21:33:11 +00:00
|
|
|
char call_identifier_str[13];
|
2012-03-29 20:01:20 +00:00
|
|
|
|
|
|
|
if (logmsg->callid) {
|
|
|
|
snprintf(call_identifier_str, sizeof(call_identifier_str), "[C-%08x]", logmsg->callid->call_identifier);
|
2012-06-20 21:33:11 +00:00
|
|
|
} else {
|
|
|
|
call_identifier_str[0] = '\0';
|
2012-03-29 20:01:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2006-12-21 21:57:16 +00:00
|
|
|
/* If the channel is disabled, then move on to the next one */
|
2012-02-14 20:27:16 +00:00
|
|
|
if (chan->disabled) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
if (logmsg->level == __LOG_VERBOSE && level > chan->verbosity) {
|
2006-12-21 21:57:16 +00:00
|
|
|
continue;
|
2012-02-14 20:27:16 +00:00
|
|
|
}
|
|
|
|
|
2006-12-21 21:57:16 +00:00
|
|
|
/* Check syslog channels */
|
|
|
|
if (chan->type == LOGTYPE_SYSLOG && (chan->logmask & (1 << logmsg->level))) {
|
2009-06-25 17:01:32 +00:00
|
|
|
ast_log_vsyslog(logmsg);
|
2006-12-21 21:57:16 +00:00
|
|
|
/* Console channels */
|
|
|
|
} else if (chan->type == LOGTYPE_CONSOLE && (chan->logmask & (1 << logmsg->level))) {
|
|
|
|
char linestr[128];
|
|
|
|
|
|
|
|
/* If the level is verbose, then skip it */
|
|
|
|
if (logmsg->level == __LOG_VERBOSE)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
/* Turn the numerical line number into a string */
|
|
|
|
snprintf(linestr, sizeof(linestr), "%d", logmsg->line);
|
|
|
|
/* Build string to print out */
|
2013-02-14 18:47:56 +00:00
|
|
|
snprintf(buf, sizeof(buf), "[%s] " COLORIZE_FMT "[%d]%s: " COLORIZE_FMT ":" COLORIZE_FMT " " COLORIZE_FMT ": %s",
|
2006-12-21 21:57:16 +00:00
|
|
|
logmsg->date,
|
2013-02-14 18:47:56 +00:00
|
|
|
COLORIZE(colors[logmsg->level], 0, logmsg->level_name),
|
2010-12-12 03:58:33 +00:00
|
|
|
logmsg->lwp,
|
2012-03-29 20:01:20 +00:00
|
|
|
call_identifier_str,
|
2013-02-14 18:47:56 +00:00
|
|
|
COLORIZE(COLOR_BRWHITE, 0, logmsg->file),
|
|
|
|
COLORIZE(COLOR_BRWHITE, 0, linestr),
|
|
|
|
COLORIZE(COLOR_BRWHITE, 0, logmsg->function),
|
2009-05-15 13:13:47 +00:00
|
|
|
logmsg->message);
|
2006-12-21 21:57:16 +00:00
|
|
|
/* Print out */
|
2008-05-29 21:30:37 +00:00
|
|
|
ast_console_puts_mutable(buf, logmsg->level);
|
2006-12-21 21:57:16 +00:00
|
|
|
/* File channels */
|
|
|
|
} else if (chan->type == LOGTYPE_FILE && (chan->logmask & (1 << logmsg->level))) {
|
|
|
|
int res = 0;
|
|
|
|
|
|
|
|
/* If no file pointer exists, skip it */
|
2010-02-24 21:17:26 +00:00
|
|
|
if (!chan->fileptr) {
|
2006-12-21 21:57:16 +00:00
|
|
|
continue;
|
2010-02-24 21:17:26 +00:00
|
|
|
}
|
|
|
|
|
2006-12-21 21:57:16 +00:00
|
|
|
/* Print out to the file */
|
2012-03-29 20:01:20 +00:00
|
|
|
res = fprintf(chan->fileptr, "[%s] %s[%d]%s %s: %s",
|
|
|
|
logmsg->date, logmsg->level_name, logmsg->lwp, call_identifier_str,
|
|
|
|
logmsg->file, term_strip(buf, logmsg->message, BUFSIZ));
|
2009-05-15 13:13:47 +00:00
|
|
|
if (res <= 0 && !ast_strlen_zero(logmsg->message)) {
|
2006-12-21 21:57:16 +00:00
|
|
|
fprintf(stderr, "**** Asterisk Logging Error: ***********\n");
|
|
|
|
if (errno == ENOMEM || errno == ENOSPC)
|
|
|
|
fprintf(stderr, "Asterisk logging error: Out of disk space, can't log to log file %s\n", chan->filename);
|
|
|
|
else
|
|
|
|
fprintf(stderr, "Logger Warning: Unable to write to log file '%s': %s (disabled)\n", chan->filename, strerror(errno));
|
2012-07-10 22:26:27 +00:00
|
|
|
/*** DOCUMENTATION
|
|
|
|
<managerEventInstance>
|
|
|
|
<synopsis>Raised when a logging channel is disabled.</synopsis>
|
|
|
|
<syntax>
|
|
|
|
<parameter name="Channel">
|
|
|
|
<para>The name of the logging channel.</para>
|
|
|
|
</parameter>
|
|
|
|
</syntax>
|
|
|
|
</managerEventInstance>
|
|
|
|
***/
|
2006-12-21 21:57:16 +00:00
|
|
|
manager_event(EVENT_FLAG_SYSTEM, "LogChannel", "Channel: %s\r\nEnabled: No\r\nReason: %d - %s\r\n", chan->filename, errno, strerror(errno));
|
|
|
|
chan->disabled = 1;
|
2007-02-20 23:26:00 +00:00
|
|
|
} else if (res > 0) {
|
|
|
|
fflush(chan->fileptr);
|
2006-12-21 21:57:16 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else if (logmsg->level != __LOG_VERBOSE) {
|
2009-05-15 13:13:47 +00:00
|
|
|
fputs(logmsg->message, stdout);
|
2006-12-21 21:57:16 +00:00
|
|
|
}
|
|
|
|
|
2007-07-20 01:54:52 +00:00
|
|
|
AST_RWLIST_UNLOCK(&logchannels);
|
2006-12-21 21:57:16 +00:00
|
|
|
|
|
|
|
/* If we need to reload because of the file size, then do so */
|
|
|
|
if (filesize_reload_needed) {
|
2010-12-31 09:21:47 +00:00
|
|
|
reload_logger(-1, NULL);
|
2008-02-05 23:00:15 +00:00
|
|
|
ast_verb(1, "Rotated Logs Per SIGXFSZ (Exceeded file size limit)\n");
|
2006-12-21 21:57:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2007-12-06 14:29:20 +00:00
|
|
|
/*! \brief Actual logging thread */
|
2006-12-21 21:57:16 +00:00
|
|
|
static void *logger_thread(void *data)
|
|
|
|
{
|
|
|
|
struct logmsg *next = NULL, *msg = NULL;
|
|
|
|
|
|
|
|
for (;;) {
|
|
|
|
/* We lock the message list, and see if any message exists... if not we wait on the condition to be signalled */
|
|
|
|
AST_LIST_LOCK(&logmsgs);
|
2009-02-16 18:25:57 +00:00
|
|
|
if (AST_LIST_EMPTY(&logmsgs)) {
|
|
|
|
if (close_logger_thread) {
|
2012-03-30 21:38:16 +00:00
|
|
|
AST_LIST_UNLOCK(&logmsgs);
|
2009-02-16 18:25:57 +00:00
|
|
|
break;
|
|
|
|
} else {
|
|
|
|
ast_cond_wait(&logcond, &logmsgs.lock);
|
|
|
|
}
|
|
|
|
}
|
2006-12-21 21:57:16 +00:00
|
|
|
next = AST_LIST_FIRST(&logmsgs);
|
|
|
|
AST_LIST_HEAD_INIT_NOLOCK(&logmsgs);
|
|
|
|
AST_LIST_UNLOCK(&logmsgs);
|
|
|
|
|
|
|
|
/* Otherwise go through and process each message in the order added */
|
|
|
|
while ((msg = next)) {
|
|
|
|
/* Get the next entry now so that we can free our current structure later */
|
|
|
|
next = AST_LIST_NEXT(msg, list);
|
|
|
|
|
|
|
|
/* Depending on the type, send it to the proper function */
|
2010-09-20 21:25:01 +00:00
|
|
|
logger_print_normal(msg);
|
2006-12-21 21:57:16 +00:00
|
|
|
|
|
|
|
/* Free the data since we are done */
|
2012-03-29 20:01:20 +00:00
|
|
|
logmsg_free(msg);
|
2006-12-21 21:57:16 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2011-08-10 20:51:07 +00:00
|
|
|
/*!
|
|
|
|
* \internal
|
|
|
|
* \brief Initialize the logger queue.
|
|
|
|
*
|
|
|
|
* \note Assumes logchannels is write locked on entry.
|
|
|
|
*
|
|
|
|
* \return Nothing
|
|
|
|
*/
|
2010-07-20 23:23:25 +00:00
|
|
|
static void logger_queue_init(void)
|
2002-02-11 04:25:04 +00:00
|
|
|
{
|
2010-07-20 23:23:25 +00:00
|
|
|
ast_unload_realtime("queue_log");
|
2011-08-10 20:51:07 +00:00
|
|
|
if (logfiles.queue_log) {
|
|
|
|
char qfname[PATH_MAX];
|
|
|
|
|
|
|
|
if (logger_queue_rt_start()) {
|
|
|
|
return;
|
2010-07-20 23:23:25 +00:00
|
|
|
}
|
2003-11-26 22:00:07 +00:00
|
|
|
|
2011-08-10 20:51:07 +00:00
|
|
|
/* Open the log file. */
|
|
|
|
snprintf(qfname, sizeof(qfname), "%s/%s", ast_config_AST_LOG_DIR,
|
|
|
|
queue_log_name);
|
|
|
|
if (qlog) {
|
|
|
|
/* Just in case it was already open. */
|
|
|
|
fclose(qlog);
|
|
|
|
}
|
|
|
|
qlog = fopen(qfname, "a");
|
|
|
|
if (!qlog) {
|
|
|
|
ast_log(LOG_ERROR, "Unable to create queue log: %s\n", strerror(errno));
|
|
|
|
}
|
|
|
|
}
|
2010-07-20 23:23:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
int init_logger(void)
|
|
|
|
{
|
2003-11-26 22:00:07 +00:00
|
|
|
/* auto rotate if sig SIGXFSZ comes a-knockin */
|
2010-05-26 21:17:46 +00:00
|
|
|
sigaction(SIGXFSZ, &handle_SIGXFSZ, NULL);
|
2003-11-26 22:00:07 +00:00
|
|
|
|
2012-11-23 00:02:23 +00:00
|
|
|
/* Re-initialize the logmsgs mutex. The recursive mutex can be accessed prior
|
|
|
|
* to Asterisk being forked into the background, which can cause the thread
|
|
|
|
* ID tracked by the underlying pthread mutex to be different than the ID of
|
|
|
|
* the thread that unlocks the mutex. Since init_logger is called after the
|
|
|
|
* fork, it is safe to initialize the mutex here for future accesses.
|
|
|
|
*/
|
|
|
|
ast_mutex_destroy(&logmsgs.lock);
|
|
|
|
ast_mutex_init(&logmsgs.lock);
|
2006-12-21 21:57:16 +00:00
|
|
|
ast_cond_init(&logcond, NULL);
|
2012-11-23 00:02:23 +00:00
|
|
|
|
|
|
|
/* start logger thread */
|
2006-12-21 21:57:16 +00:00
|
|
|
if (ast_pthread_create(&logthread, NULL, logger_thread, NULL) < 0) {
|
|
|
|
ast_cond_destroy(&logcond);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2006-09-18 19:54:18 +00:00
|
|
|
/* register the logger cli commands */
|
2008-12-05 10:31:25 +00:00
|
|
|
ast_cli_register_multiple(cli_logger, ARRAY_LEN(cli_logger));
|
2004-01-12 05:05:35 +00:00
|
|
|
|
2007-06-22 04:35:12 +00:00
|
|
|
ast_mkdir(ast_config_AST_LOG_DIR, 0777);
|
2010-07-20 23:23:25 +00:00
|
|
|
|
2004-01-12 05:05:35 +00:00
|
|
|
/* create log channels */
|
2010-12-31 09:21:47 +00:00
|
|
|
init_logger_chain(0 /* locked */, NULL);
|
2011-08-10 20:51:07 +00:00
|
|
|
logger_initialized = 1;
|
2005-03-11 08:49:01 +00:00
|
|
|
|
2010-07-20 23:23:25 +00:00
|
|
|
return 0;
|
1999-12-05 07:28:29 +00:00
|
|
|
}
|
|
|
|
|
2004-06-17 01:13:10 +00:00
|
|
|
void close_logger(void)
|
|
|
|
{
|
2006-12-21 21:57:16 +00:00
|
|
|
struct logchannel *f = NULL;
|
2012-12-11 02:44:53 +00:00
|
|
|
struct verb *cur = NULL;
|
|
|
|
|
|
|
|
ast_cli_unregister_multiple(cli_logger, ARRAY_LEN(cli_logger));
|
2006-12-21 21:57:16 +00:00
|
|
|
|
2011-08-10 20:51:07 +00:00
|
|
|
logger_initialized = 0;
|
|
|
|
|
2006-12-21 21:57:16 +00:00
|
|
|
/* Stop logger thread */
|
|
|
|
AST_LIST_LOCK(&logmsgs);
|
|
|
|
close_logger_thread = 1;
|
|
|
|
ast_cond_signal(&logcond);
|
|
|
|
AST_LIST_UNLOCK(&logmsgs);
|
2004-06-17 01:13:10 +00:00
|
|
|
|
2007-10-10 13:46:57 +00:00
|
|
|
if (logthread != AST_PTHREADT_NULL)
|
|
|
|
pthread_join(logthread, NULL);
|
|
|
|
|
2012-12-11 02:44:53 +00:00
|
|
|
AST_RWLIST_WRLOCK(&verbosers);
|
|
|
|
while ((cur = AST_LIST_REMOVE_HEAD(&verbosers, list))) {
|
|
|
|
ast_free(cur);
|
|
|
|
}
|
|
|
|
AST_RWLIST_UNLOCK(&verbosers);
|
|
|
|
|
2007-07-20 01:54:52 +00:00
|
|
|
AST_RWLIST_WRLOCK(&logchannels);
|
Merge team/russell/ast_verbose_threadstorage
- instead of defining a free() wrapper in a bunch of files, define it as
ast_free() in utils.h and remove the copies from all the files.
- centralize and abstract the code used for doing thread storage. The code
lives in threadstorage.h, with one function being implemented in utils.c.
This new API includes generic thread storage as well as special functions
for handling thread local dynamic length string buffers.
- update ast_inet_ntoa() to use the new threadstorage API
- update ast_state2str() to use the new threadstorage API
- update ast_cli() to use the new threadstorage API
- Modify manager_event() to use thread storage. Instead of using a buffer of
4096 characters as the workspace for building the manager event, use a thread
local dynamic string. Now there is no length limitation on the length of the
body of a manager event.
- Significantly simplify the handling of ast_verbose() ...
- Instead of using a static char buffer and a lock to make sure only one
thread can be using ast_verbose() at a time, use a thread local dynamic
string as the workspace for preparing the verbose message. Instead of
locking around the entire function, the only locking done now is when the
message has been built and is being deliviered to the list of registered
verbose message handlers.
- This function was doing a strdup() on every message passed to it and
keeping a queue of the last 200 messages in memory. This has been
completely removed. The only place this was used was that if there were
any messages in the verbose queue when a verbose handler was registered,
all of the messages in the queue would be fed to it. So, I just made sure
that the console verbose handler and the network verbose handler (for
remote asterisk consoles) were registered before any verbose messages.
pbx_gtkconsole and pbx_kdeconsole will now lose a few verbose messages at
startup, but I didn't feel the performance hit of this message queue was
worth saving the initial verbose output for these very rarely used modules.
- I have removed the last three arguments to the verbose handlers, leaving
only the string itself because they aren't needed anymore. For example,
ast_verbose had some logic for telling the verbose handler to add
a newline if the buffer was completely full. Now that the buffer can grow
as needed, this doesn't matter anymore.
- remove unused function, ast_verbose_dmesg() which was to dispatch the
message queue
- Convert the list of verbose handlers to use the linked list macros.
- add missing newline characters to a few ast_verbose() calls
- convert the list of log channels to use the linked list macros in logger.c
- fix close_logger() to close all of the files it opened for logging
- update ast_log() to use a thread local dynamic string for its workspace
for preparing log messages instead of a buffer of size BUFSIZ (8kB on my
system) allocated on the stack. The dynamic string in this case is limited
to only growing to a maximum size of BUFSIZ.
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@39272 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2006-08-08 06:32:04 +00:00
|
|
|
|
|
|
|
if (qlog) {
|
|
|
|
fclose(qlog);
|
|
|
|
qlog = NULL;
|
|
|
|
}
|
|
|
|
|
2012-12-11 02:44:53 +00:00
|
|
|
while ((f = AST_LIST_REMOVE_HEAD(&logchannels, list))) {
|
Merge team/russell/ast_verbose_threadstorage
- instead of defining a free() wrapper in a bunch of files, define it as
ast_free() in utils.h and remove the copies from all the files.
- centralize and abstract the code used for doing thread storage. The code
lives in threadstorage.h, with one function being implemented in utils.c.
This new API includes generic thread storage as well as special functions
for handling thread local dynamic length string buffers.
- update ast_inet_ntoa() to use the new threadstorage API
- update ast_state2str() to use the new threadstorage API
- update ast_cli() to use the new threadstorage API
- Modify manager_event() to use thread storage. Instead of using a buffer of
4096 characters as the workspace for building the manager event, use a thread
local dynamic string. Now there is no length limitation on the length of the
body of a manager event.
- Significantly simplify the handling of ast_verbose() ...
- Instead of using a static char buffer and a lock to make sure only one
thread can be using ast_verbose() at a time, use a thread local dynamic
string as the workspace for preparing the verbose message. Instead of
locking around the entire function, the only locking done now is when the
message has been built and is being deliviered to the list of registered
verbose message handlers.
- This function was doing a strdup() on every message passed to it and
keeping a queue of the last 200 messages in memory. This has been
completely removed. The only place this was used was that if there were
any messages in the verbose queue when a verbose handler was registered,
all of the messages in the queue would be fed to it. So, I just made sure
that the console verbose handler and the network verbose handler (for
remote asterisk consoles) were registered before any verbose messages.
pbx_gtkconsole and pbx_kdeconsole will now lose a few verbose messages at
startup, but I didn't feel the performance hit of this message queue was
worth saving the initial verbose output for these very rarely used modules.
- I have removed the last three arguments to the verbose handlers, leaving
only the string itself because they aren't needed anymore. For example,
ast_verbose had some logic for telling the verbose handler to add
a newline if the buffer was completely full. Now that the buffer can grow
as needed, this doesn't matter anymore.
- remove unused function, ast_verbose_dmesg() which was to dispatch the
message queue
- Convert the list of verbose handlers to use the linked list macros.
- add missing newline characters to a few ast_verbose() calls
- convert the list of log channels to use the linked list macros in logger.c
- fix close_logger() to close all of the files it opened for logging
- update ast_log() to use a thread local dynamic string for its workspace
for preparing log messages instead of a buffer of size BUFSIZ (8kB on my
system) allocated on the stack. The dynamic string in this case is limited
to only growing to a maximum size of BUFSIZ.
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@39272 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2006-08-08 06:32:04 +00:00
|
|
|
if (f->fileptr && (f->fileptr != stdout) && (f->fileptr != stderr)) {
|
|
|
|
fclose(f->fileptr);
|
|
|
|
f->fileptr = NULL;
|
2004-06-17 01:13:10 +00:00
|
|
|
}
|
2012-12-11 02:44:53 +00:00
|
|
|
ast_free(f);
|
2004-06-17 01:13:10 +00:00
|
|
|
}
|
Merge team/russell/ast_verbose_threadstorage
- instead of defining a free() wrapper in a bunch of files, define it as
ast_free() in utils.h and remove the copies from all the files.
- centralize and abstract the code used for doing thread storage. The code
lives in threadstorage.h, with one function being implemented in utils.c.
This new API includes generic thread storage as well as special functions
for handling thread local dynamic length string buffers.
- update ast_inet_ntoa() to use the new threadstorage API
- update ast_state2str() to use the new threadstorage API
- update ast_cli() to use the new threadstorage API
- Modify manager_event() to use thread storage. Instead of using a buffer of
4096 characters as the workspace for building the manager event, use a thread
local dynamic string. Now there is no length limitation on the length of the
body of a manager event.
- Significantly simplify the handling of ast_verbose() ...
- Instead of using a static char buffer and a lock to make sure only one
thread can be using ast_verbose() at a time, use a thread local dynamic
string as the workspace for preparing the verbose message. Instead of
locking around the entire function, the only locking done now is when the
message has been built and is being deliviered to the list of registered
verbose message handlers.
- This function was doing a strdup() on every message passed to it and
keeping a queue of the last 200 messages in memory. This has been
completely removed. The only place this was used was that if there were
any messages in the verbose queue when a verbose handler was registered,
all of the messages in the queue would be fed to it. So, I just made sure
that the console verbose handler and the network verbose handler (for
remote asterisk consoles) were registered before any verbose messages.
pbx_gtkconsole and pbx_kdeconsole will now lose a few verbose messages at
startup, but I didn't feel the performance hit of this message queue was
worth saving the initial verbose output for these very rarely used modules.
- I have removed the last three arguments to the verbose handlers, leaving
only the string itself because they aren't needed anymore. For example,
ast_verbose had some logic for telling the verbose handler to add
a newline if the buffer was completely full. Now that the buffer can grow
as needed, this doesn't matter anymore.
- remove unused function, ast_verbose_dmesg() which was to dispatch the
message queue
- Convert the list of verbose handlers to use the linked list macros.
- add missing newline characters to a few ast_verbose() calls
- convert the list of log channels to use the linked list macros in logger.c
- fix close_logger() to close all of the files it opened for logging
- update ast_log() to use a thread local dynamic string for its workspace
for preparing log messages instead of a buffer of size BUFSIZ (8kB on my
system) allocated on the stack. The dynamic string in this case is limited
to only growing to a maximum size of BUFSIZ.
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@39272 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2006-08-08 06:32:04 +00:00
|
|
|
|
|
|
|
closelog(); /* syslog */
|
|
|
|
|
2007-07-20 01:54:52 +00:00
|
|
|
AST_RWLIST_UNLOCK(&logchannels);
|
2004-06-17 01:13:10 +00:00
|
|
|
}
|
|
|
|
|
2012-05-17 16:28:20 +00:00
|
|
|
void ast_callid_strnprint(char *buffer, size_t buffer_size, struct ast_callid *callid)
|
|
|
|
{
|
|
|
|
snprintf(buffer, buffer_size, "[C-%08x]", callid->call_identifier);
|
|
|
|
}
|
|
|
|
|
2012-03-29 20:01:20 +00:00
|
|
|
struct ast_callid *ast_create_callid(void)
|
|
|
|
{
|
|
|
|
struct ast_callid *call;
|
|
|
|
|
2013-01-16 18:09:28 +00:00
|
|
|
call = ao2_alloc_options(sizeof(struct ast_callid), NULL, AO2_ALLOC_OPT_LOCK_NOLOCK);
|
|
|
|
if (!call) {
|
2012-03-29 20:01:20 +00:00
|
|
|
ast_log(LOG_ERROR, "Could not allocate callid struct.\n");
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2013-01-16 18:09:28 +00:00
|
|
|
call->call_identifier = ast_atomic_fetchadd_int(&next_unique_callid, +1);
|
2013-02-15 17:38:22 +00:00
|
|
|
#ifdef TEST_FRAMEWORK
|
2012-05-17 16:28:20 +00:00
|
|
|
ast_debug(3, "CALL_ID [C-%08x] created by thread.\n", call->call_identifier);
|
2013-02-15 17:38:22 +00:00
|
|
|
#endif
|
2012-03-29 20:01:20 +00:00
|
|
|
return call;
|
|
|
|
}
|
|
|
|
|
|
|
|
struct ast_callid *ast_read_threadstorage_callid(void)
|
|
|
|
{
|
|
|
|
struct ast_callid **callid;
|
|
|
|
callid = ast_threadstorage_get(&unique_callid, sizeof(struct ast_callid **));
|
|
|
|
if (callid && *callid) {
|
|
|
|
ast_callid_ref(*callid);
|
|
|
|
return *callid;
|
|
|
|
}
|
|
|
|
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2013-02-15 17:38:22 +00:00
|
|
|
int ast_callid_threadassoc_change(struct ast_callid *callid)
|
|
|
|
{
|
|
|
|
struct ast_callid **id =
|
|
|
|
ast_threadstorage_get(&unique_callid, sizeof(struct ast_callid **));
|
|
|
|
|
|
|
|
if (!id) {
|
|
|
|
ast_log(LOG_ERROR, "Failed to allocate thread storage.\n");
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (*id && (*id != callid)) {
|
|
|
|
#ifdef TEST_FRAMEWORK
|
|
|
|
ast_debug(3, "CALL_ID [C-%08x] being removed from thread.\n", (*id)->call_identifier);
|
|
|
|
#endif
|
|
|
|
*id = ast_callid_unref(*id);
|
|
|
|
*id = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!(*id) && callid) {
|
|
|
|
/* callid will be unreffed at thread destruction */
|
|
|
|
ast_callid_ref(callid);
|
|
|
|
*id = callid;
|
|
|
|
#ifdef TEST_FRAMEWORK
|
|
|
|
ast_debug(3, "CALL_ID [C-%08x] bound to thread.\n", callid->call_identifier);
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2012-03-29 20:01:20 +00:00
|
|
|
int ast_callid_threadassoc_add(struct ast_callid *callid)
|
|
|
|
{
|
|
|
|
struct ast_callid **pointing;
|
|
|
|
pointing = ast_threadstorage_get(&unique_callid, sizeof(struct ast_callid **));
|
|
|
|
if (!(pointing)) {
|
|
|
|
ast_log(LOG_ERROR, "Failed to allocate thread storage.\n");
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!(*pointing)) {
|
|
|
|
/* callid will be unreffed at thread destruction */
|
|
|
|
ast_callid_ref(callid);
|
|
|
|
*pointing = callid;
|
2013-02-15 17:38:22 +00:00
|
|
|
#ifdef TEST_FRAMEWORK
|
2012-05-17 16:28:20 +00:00
|
|
|
ast_debug(3, "CALL_ID [C-%08x] bound to thread.\n", callid->call_identifier);
|
2013-02-15 17:38:22 +00:00
|
|
|
#endif
|
2012-03-29 20:01:20 +00:00
|
|
|
} else {
|
|
|
|
ast_log(LOG_WARNING, "Attempted to ast_callid_threadassoc_add on thread already associated with a callid.\n");
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2013-01-09 23:22:00 +00:00
|
|
|
int ast_callid_threadassoc_remove(void)
|
2012-05-17 16:28:20 +00:00
|
|
|
{
|
|
|
|
struct ast_callid **pointing;
|
|
|
|
pointing = ast_threadstorage_get(&unique_callid, sizeof(struct ast_callid **));
|
|
|
|
if (!(pointing)) {
|
|
|
|
ast_log(LOG_ERROR, "Failed to allocate thread storage.\n");
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!(*pointing)) {
|
|
|
|
ast_log(LOG_ERROR, "Tried to clean callid thread storage with no callid in thread storage.\n");
|
|
|
|
return -1;
|
|
|
|
} else {
|
2013-02-15 17:38:22 +00:00
|
|
|
#ifdef TEST_FRAMEWORK
|
2012-09-18 20:19:49 +00:00
|
|
|
ast_debug(3, "CALL_ID [C-%08x] being removed from thread.\n", (*pointing)->call_identifier);
|
2013-02-15 17:38:22 +00:00
|
|
|
#endif
|
2012-05-17 16:28:20 +00:00
|
|
|
*pointing = ast_callid_unref(*pointing);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
int ast_callid_threadstorage_auto(struct ast_callid **callid)
|
|
|
|
{
|
|
|
|
struct ast_callid *tmp;
|
|
|
|
|
|
|
|
/* Start by trying to see if a callid is available from thread storage */
|
|
|
|
tmp = ast_read_threadstorage_callid();
|
|
|
|
if (tmp) {
|
|
|
|
*callid = tmp;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* If that failed, try to create a new one and bind it. */
|
|
|
|
tmp = ast_create_callid();
|
|
|
|
if (tmp) {
|
|
|
|
ast_callid_threadassoc_add(tmp);
|
|
|
|
*callid = tmp;
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* If neither worked, then something must have gone wrong. */
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
void ast_callid_threadstorage_auto_clean(struct ast_callid *callid, int callid_created)
|
|
|
|
{
|
|
|
|
if (callid) {
|
|
|
|
/* If the callid was created rather than simply grabbed from the thread storage, we need to unbind here. */
|
|
|
|
if (callid_created == 1) {
|
|
|
|
ast_callid_threadassoc_remove();
|
|
|
|
}
|
|
|
|
callid = ast_callid_unref(callid);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-03-29 20:01:20 +00:00
|
|
|
/*!
|
|
|
|
* \internal
|
|
|
|
* \brief thread storage cleanup function for unique_callid
|
|
|
|
*/
|
|
|
|
static void unique_callid_cleanup(void *data)
|
|
|
|
{
|
|
|
|
struct ast_callid **callid = data;
|
|
|
|
|
|
|
|
if (*callid) {
|
|
|
|
ast_callid_unref(*callid);
|
|
|
|
}
|
|
|
|
|
|
|
|
ast_free(data);
|
|
|
|
}
|
|
|
|
|
Merge team/russell/ast_verbose_threadstorage
- instead of defining a free() wrapper in a bunch of files, define it as
ast_free() in utils.h and remove the copies from all the files.
- centralize and abstract the code used for doing thread storage. The code
lives in threadstorage.h, with one function being implemented in utils.c.
This new API includes generic thread storage as well as special functions
for handling thread local dynamic length string buffers.
- update ast_inet_ntoa() to use the new threadstorage API
- update ast_state2str() to use the new threadstorage API
- update ast_cli() to use the new threadstorage API
- Modify manager_event() to use thread storage. Instead of using a buffer of
4096 characters as the workspace for building the manager event, use a thread
local dynamic string. Now there is no length limitation on the length of the
body of a manager event.
- Significantly simplify the handling of ast_verbose() ...
- Instead of using a static char buffer and a lock to make sure only one
thread can be using ast_verbose() at a time, use a thread local dynamic
string as the workspace for preparing the verbose message. Instead of
locking around the entire function, the only locking done now is when the
message has been built and is being deliviered to the list of registered
verbose message handlers.
- This function was doing a strdup() on every message passed to it and
keeping a queue of the last 200 messages in memory. This has been
completely removed. The only place this was used was that if there were
any messages in the verbose queue when a verbose handler was registered,
all of the messages in the queue would be fed to it. So, I just made sure
that the console verbose handler and the network verbose handler (for
remote asterisk consoles) were registered before any verbose messages.
pbx_gtkconsole and pbx_kdeconsole will now lose a few verbose messages at
startup, but I didn't feel the performance hit of this message queue was
worth saving the initial verbose output for these very rarely used modules.
- I have removed the last three arguments to the verbose handlers, leaving
only the string itself because they aren't needed anymore. For example,
ast_verbose had some logic for telling the verbose handler to add
a newline if the buffer was completely full. Now that the buffer can grow
as needed, this doesn't matter anymore.
- remove unused function, ast_verbose_dmesg() which was to dispatch the
message queue
- Convert the list of verbose handlers to use the linked list macros.
- add missing newline characters to a few ast_verbose() calls
- convert the list of log channels to use the linked list macros in logger.c
- fix close_logger() to close all of the files it opened for logging
- update ast_log() to use a thread local dynamic string for its workspace
for preparing log messages instead of a buffer of size BUFSIZ (8kB on my
system) allocated on the stack. The dynamic string in this case is limited
to only growing to a maximum size of BUFSIZ.
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@39272 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2006-08-08 06:32:04 +00:00
|
|
|
/*!
|
|
|
|
* \brief send log messages to syslog and/or the console
|
2004-01-12 05:05:35 +00:00
|
|
|
*/
|
2012-03-29 20:01:20 +00:00
|
|
|
static void __attribute__((format(printf, 6, 0))) ast_log_full(int level, const char *file, int line, const char *function, struct ast_callid *callid, const char *fmt, va_list ap)
|
1999-12-05 07:28:29 +00:00
|
|
|
{
|
2006-12-21 21:57:16 +00:00
|
|
|
struct logmsg *logmsg = NULL;
|
|
|
|
struct ast_str *buf = NULL;
|
2007-07-18 19:47:20 +00:00
|
|
|
struct ast_tm tm;
|
2008-08-10 20:23:50 +00:00
|
|
|
struct timeval now = ast_tvnow();
|
2006-12-21 21:57:16 +00:00
|
|
|
int res = 0;
|
2009-05-15 13:13:47 +00:00
|
|
|
char datestring[256];
|
Merge team/russell/ast_verbose_threadstorage
- instead of defining a free() wrapper in a bunch of files, define it as
ast_free() in utils.h and remove the copies from all the files.
- centralize and abstract the code used for doing thread storage. The code
lives in threadstorage.h, with one function being implemented in utils.c.
This new API includes generic thread storage as well as special functions
for handling thread local dynamic length string buffers.
- update ast_inet_ntoa() to use the new threadstorage API
- update ast_state2str() to use the new threadstorage API
- update ast_cli() to use the new threadstorage API
- Modify manager_event() to use thread storage. Instead of using a buffer of
4096 characters as the workspace for building the manager event, use a thread
local dynamic string. Now there is no length limitation on the length of the
body of a manager event.
- Significantly simplify the handling of ast_verbose() ...
- Instead of using a static char buffer and a lock to make sure only one
thread can be using ast_verbose() at a time, use a thread local dynamic
string as the workspace for preparing the verbose message. Instead of
locking around the entire function, the only locking done now is when the
message has been built and is being deliviered to the list of registered
verbose message handlers.
- This function was doing a strdup() on every message passed to it and
keeping a queue of the last 200 messages in memory. This has been
completely removed. The only place this was used was that if there were
any messages in the verbose queue when a verbose handler was registered,
all of the messages in the queue would be fed to it. So, I just made sure
that the console verbose handler and the network verbose handler (for
remote asterisk consoles) were registered before any verbose messages.
pbx_gtkconsole and pbx_kdeconsole will now lose a few verbose messages at
startup, but I didn't feel the performance hit of this message queue was
worth saving the initial verbose output for these very rarely used modules.
- I have removed the last three arguments to the verbose handlers, leaving
only the string itself because they aren't needed anymore. For example,
ast_verbose had some logic for telling the verbose handler to add
a newline if the buffer was completely full. Now that the buffer can grow
as needed, this doesn't matter anymore.
- remove unused function, ast_verbose_dmesg() which was to dispatch the
message queue
- Convert the list of verbose handlers to use the linked list macros.
- add missing newline characters to a few ast_verbose() calls
- convert the list of log channels to use the linked list macros in logger.c
- fix close_logger() to close all of the files it opened for logging
- update ast_log() to use a thread local dynamic string for its workspace
for preparing log messages instead of a buffer of size BUFSIZ (8kB on my
system) allocated on the stack. The dynamic string in this case is limited
to only growing to a maximum size of BUFSIZ.
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@39272 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2006-08-08 06:32:04 +00:00
|
|
|
|
2006-12-15 23:10:42 +00:00
|
|
|
if (!(buf = ast_str_thread_get(&log_buf, LOG_BUF_INIT_SIZE)))
|
Merge team/russell/ast_verbose_threadstorage
- instead of defining a free() wrapper in a bunch of files, define it as
ast_free() in utils.h and remove the copies from all the files.
- centralize and abstract the code used for doing thread storage. The code
lives in threadstorage.h, with one function being implemented in utils.c.
This new API includes generic thread storage as well as special functions
for handling thread local dynamic length string buffers.
- update ast_inet_ntoa() to use the new threadstorage API
- update ast_state2str() to use the new threadstorage API
- update ast_cli() to use the new threadstorage API
- Modify manager_event() to use thread storage. Instead of using a buffer of
4096 characters as the workspace for building the manager event, use a thread
local dynamic string. Now there is no length limitation on the length of the
body of a manager event.
- Significantly simplify the handling of ast_verbose() ...
- Instead of using a static char buffer and a lock to make sure only one
thread can be using ast_verbose() at a time, use a thread local dynamic
string as the workspace for preparing the verbose message. Instead of
locking around the entire function, the only locking done now is when the
message has been built and is being deliviered to the list of registered
verbose message handlers.
- This function was doing a strdup() on every message passed to it and
keeping a queue of the last 200 messages in memory. This has been
completely removed. The only place this was used was that if there were
any messages in the verbose queue when a verbose handler was registered,
all of the messages in the queue would be fed to it. So, I just made sure
that the console verbose handler and the network verbose handler (for
remote asterisk consoles) were registered before any verbose messages.
pbx_gtkconsole and pbx_kdeconsole will now lose a few verbose messages at
startup, but I didn't feel the performance hit of this message queue was
worth saving the initial verbose output for these very rarely used modules.
- I have removed the last three arguments to the verbose handlers, leaving
only the string itself because they aren't needed anymore. For example,
ast_verbose had some logic for telling the verbose handler to add
a newline if the buffer was completely full. Now that the buffer can grow
as needed, this doesn't matter anymore.
- remove unused function, ast_verbose_dmesg() which was to dispatch the
message queue
- Convert the list of verbose handlers to use the linked list macros.
- add missing newline characters to a few ast_verbose() calls
- convert the list of log channels to use the linked list macros in logger.c
- fix close_logger() to close all of the files it opened for logging
- update ast_log() to use a thread local dynamic string for its workspace
for preparing log messages instead of a buffer of size BUFSIZ (8kB on my
system) allocated on the stack. The dynamic string in this case is limited
to only growing to a maximum size of BUFSIZ.
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@39272 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2006-08-08 06:32:04 +00:00
|
|
|
return;
|
|
|
|
|
2011-02-08 21:24:57 +00:00
|
|
|
if (level != __LOG_VERBOSE && AST_RWLIST_EMPTY(&logchannels)) {
|
2006-09-07 03:35:42 +00:00
|
|
|
/*
|
|
|
|
* we don't have the logger chain configured yet,
|
|
|
|
* so just log to stdout
|
2006-12-21 21:57:16 +00:00
|
|
|
*/
|
2011-02-08 21:24:57 +00:00
|
|
|
int result;
|
|
|
|
result = ast_str_set_va(&buf, BUFSIZ, fmt, ap); /* XXX BUFSIZ ? */
|
|
|
|
if (result != AST_DYNSTR_BUILD_FAILED) {
|
|
|
|
term_filter_escapes(ast_str_buffer(buf));
|
|
|
|
fputs(ast_str_buffer(buf), stdout);
|
2006-09-07 03:35:42 +00:00
|
|
|
}
|
|
|
|
return;
|
|
|
|
}
|
2005-05-20 03:52:27 +00:00
|
|
|
|
2004-10-24 06:12:21 +00:00
|
|
|
/* Ignore anything that never gets logged anywhere */
|
2010-09-21 13:45:30 +00:00
|
|
|
if (level != __LOG_VERBOSE && !(global_logmask & (1 << level)))
|
2004-10-24 06:12:21 +00:00
|
|
|
return;
|
2012-02-14 20:27:16 +00:00
|
|
|
|
2006-12-21 21:57:16 +00:00
|
|
|
/* Build string */
|
|
|
|
res = ast_str_set_va(&buf, BUFSIZ, fmt, ap);
|
2004-01-12 06:32:40 +00:00
|
|
|
|
2006-12-21 21:57:16 +00:00
|
|
|
/* If the build failed, then abort and free this structure */
|
|
|
|
if (res == AST_DYNSTR_BUILD_FAILED)
|
|
|
|
return;
|
2004-01-12 05:05:35 +00:00
|
|
|
|
2006-12-21 21:57:16 +00:00
|
|
|
/* Create a new logging message */
|
2009-05-15 13:13:47 +00:00
|
|
|
if (!(logmsg = ast_calloc_with_stringfields(1, struct logmsg, res + 128)))
|
2004-06-29 04:42:19 +00:00
|
|
|
return;
|
2008-06-03 13:29:16 +00:00
|
|
|
|
2006-12-21 21:57:16 +00:00
|
|
|
/* Copy string over */
|
2009-05-15 13:13:47 +00:00
|
|
|
ast_string_field_set(logmsg, message, ast_str_buffer(buf));
|
2004-06-29 04:42:19 +00:00
|
|
|
|
2010-09-20 21:25:01 +00:00
|
|
|
/* Set type */
|
|
|
|
if (level == __LOG_VERBOSE) {
|
|
|
|
logmsg->type = LOGMSG_VERBOSE;
|
|
|
|
} else {
|
|
|
|
logmsg->type = LOGMSG_NORMAL;
|
|
|
|
}
|
2004-01-12 05:05:35 +00:00
|
|
|
|
2012-03-29 20:01:20 +00:00
|
|
|
if (display_callids && callid) {
|
|
|
|
logmsg->callid = ast_callid_ref(callid);
|
|
|
|
/* callid will be unreffed at logmsg destruction */
|
|
|
|
}
|
|
|
|
|
2006-12-21 21:57:16 +00:00
|
|
|
/* Create our date/time */
|
2008-08-10 20:23:50 +00:00
|
|
|
ast_localtime(&now, &tm, NULL);
|
2009-05-15 13:13:47 +00:00
|
|
|
ast_strftime(datestring, sizeof(datestring), dateformat, &tm);
|
|
|
|
ast_string_field_set(logmsg, date, datestring);
|
2006-12-21 21:57:16 +00:00
|
|
|
|
|
|
|
/* Copy over data */
|
|
|
|
logmsg->level = level;
|
|
|
|
logmsg->line = line;
|
2009-05-15 13:13:47 +00:00
|
|
|
ast_string_field_set(logmsg, level_name, levels[level]);
|
|
|
|
ast_string_field_set(logmsg, file, file);
|
|
|
|
ast_string_field_set(logmsg, function, function);
|
2010-12-12 03:58:33 +00:00
|
|
|
logmsg->lwp = ast_get_tid();
|
2006-12-21 21:57:16 +00:00
|
|
|
|
|
|
|
/* If the logger thread is active, append it to the tail end of the list - otherwise skip that step */
|
|
|
|
if (logthread != AST_PTHREADT_NULL) {
|
|
|
|
AST_LIST_LOCK(&logmsgs);
|
2012-03-30 21:38:16 +00:00
|
|
|
if (close_logger_thread) {
|
|
|
|
/* Logger is either closing or closed. We cannot log this message. */
|
2013-03-07 15:09:01 +00:00
|
|
|
logmsg_free(logmsg);
|
2012-03-30 21:38:16 +00:00
|
|
|
} else {
|
|
|
|
AST_LIST_INSERT_TAIL(&logmsgs, logmsg, list);
|
|
|
|
ast_cond_signal(&logcond);
|
|
|
|
}
|
2006-12-21 21:57:16 +00:00
|
|
|
AST_LIST_UNLOCK(&logmsgs);
|
|
|
|
} else {
|
|
|
|
logger_print_normal(logmsg);
|
2012-03-29 20:01:20 +00:00
|
|
|
logmsg_free(logmsg);
|
2004-03-30 16:16:05 +00:00
|
|
|
}
|
1999-12-05 07:28:29 +00:00
|
|
|
}
|
|
|
|
|
2012-03-29 20:01:20 +00:00
|
|
|
void ast_log(int level, const char *file, int line, const char *function, const char *fmt, ...)
|
|
|
|
{
|
|
|
|
struct ast_callid *callid;
|
|
|
|
va_list ap;
|
|
|
|
|
|
|
|
callid = ast_read_threadstorage_callid();
|
|
|
|
|
|
|
|
va_start(ap, fmt);
|
|
|
|
ast_log_full(level, file, line, function, callid, fmt, ap);
|
|
|
|
va_end(ap);
|
|
|
|
|
|
|
|
if (callid) {
|
|
|
|
ast_callid_unref(callid);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void ast_log_callid(int level, const char *file, int line, const char *function, struct ast_callid *callid, const char *fmt, ...)
|
|
|
|
{
|
|
|
|
va_list ap;
|
|
|
|
va_start(ap, fmt);
|
|
|
|
ast_log_full(level, file, line, function, callid, fmt, ap);
|
|
|
|
va_end(ap);
|
|
|
|
}
|
|
|
|
|
2008-05-23 22:35:50 +00:00
|
|
|
|
2013-06-08 22:09:07 +00:00
|
|
|
void ast_log_backtrace(void)
|
2005-12-27 06:24:28 +00:00
|
|
|
{
|
2008-01-28 18:27:29 +00:00
|
|
|
#ifdef HAVE_BKTR
|
2008-08-10 20:23:50 +00:00
|
|
|
struct ast_bt *bt;
|
2008-05-23 22:35:50 +00:00
|
|
|
int i = 0;
|
2005-12-27 06:24:28 +00:00
|
|
|
char **strings;
|
|
|
|
|
2008-08-10 20:23:50 +00:00
|
|
|
if (!(bt = ast_bt_create())) {
|
2008-05-23 22:35:50 +00:00
|
|
|
ast_log(LOG_WARNING, "Unable to allocate space for backtrace structure\n");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2010-12-18 00:08:13 +00:00
|
|
|
if ((strings = ast_bt_get_symbols(bt->addresses, bt->num_frames))) {
|
2008-08-10 20:23:50 +00:00
|
|
|
ast_debug(1, "Got %d backtrace record%c\n", bt->num_frames, bt->num_frames != 1 ? 's' : ' ');
|
2010-06-11 18:04:54 +00:00
|
|
|
for (i = 3; i < bt->num_frames - 2; i++) {
|
2011-02-04 16:55:39 +00:00
|
|
|
ast_debug(1, "#%d: [%p] %s\n", i - 3, bt->addresses[i], strings[i]);
|
2005-12-27 06:24:28 +00:00
|
|
|
}
|
2009-05-13 00:13:43 +00:00
|
|
|
|
|
|
|
/* MALLOC_DEBUG will erroneously report an error here, unless we undef the macro. */
|
|
|
|
#undef free
|
2008-05-23 22:35:50 +00:00
|
|
|
free(strings);
|
|
|
|
} else {
|
|
|
|
ast_debug(1, "Could not allocate memory for backtrace\n");
|
2005-12-27 06:24:28 +00:00
|
|
|
}
|
2008-08-10 20:23:50 +00:00
|
|
|
ast_bt_destroy(bt);
|
2005-12-27 06:24:28 +00:00
|
|
|
#else
|
2008-01-28 18:27:29 +00:00
|
|
|
ast_log(LOG_WARNING, "Must run configure with '--with-execinfo' for stack backtraces.\n");
|
2010-12-18 00:08:13 +00:00
|
|
|
#endif /* defined(HAVE_BKTR) */
|
2005-12-27 06:24:28 +00:00
|
|
|
}
|
|
|
|
|
2012-06-26 21:45:22 +00:00
|
|
|
void __ast_verbose_ap(const char *file, int line, const char *func, int level, struct ast_callid *callid, const char *fmt, va_list ap)
|
1999-12-05 07:28:29 +00:00
|
|
|
{
|
2006-12-21 21:57:16 +00:00
|
|
|
struct ast_str *buf = NULL;
|
|
|
|
int res = 0;
|
2012-02-14 20:27:16 +00:00
|
|
|
const char *prefix = level >= 4 ? VERBOSE_PREFIX_4 : level == 3 ? VERBOSE_PREFIX_3 : level == 2 ? VERBOSE_PREFIX_2 : level == 1 ? VERBOSE_PREFIX_1 : "";
|
|
|
|
signed char magic = level > 127 ? -128 : -level - 1; /* 0 => -1, 1 => -2, etc. Can't pass NUL, as it is EOS-delimiter */
|
|
|
|
|
|
|
|
/* For compatibility with modules still calling ast_verbose() directly instead of using ast_verb() */
|
|
|
|
if (level < 0) {
|
|
|
|
if (!strncmp(fmt, VERBOSE_PREFIX_4, strlen(VERBOSE_PREFIX_4))) {
|
|
|
|
magic = -5;
|
|
|
|
} else if (!strncmp(fmt, VERBOSE_PREFIX_3, strlen(VERBOSE_PREFIX_3))) {
|
|
|
|
magic = -4;
|
|
|
|
} else if (!strncmp(fmt, VERBOSE_PREFIX_2, strlen(VERBOSE_PREFIX_2))) {
|
|
|
|
magic = -3;
|
|
|
|
} else if (!strncmp(fmt, VERBOSE_PREFIX_1, strlen(VERBOSE_PREFIX_1))) {
|
|
|
|
magic = -2;
|
|
|
|
} else {
|
|
|
|
magic = -1;
|
|
|
|
}
|
|
|
|
}
|
2005-03-11 07:24:10 +00:00
|
|
|
|
2012-02-14 20:27:16 +00:00
|
|
|
if (!(buf = ast_str_thread_get(&verbose_buf, VERBOSE_BUF_INIT_SIZE))) {
|
2006-12-21 21:57:16 +00:00
|
|
|
return;
|
2012-02-14 20:27:16 +00:00
|
|
|
}
|
2006-12-21 21:57:16 +00:00
|
|
|
|
2008-03-04 23:04:29 +00:00
|
|
|
if (ast_opt_timestamp) {
|
2008-08-10 20:23:50 +00:00
|
|
|
struct timeval now;
|
2008-03-04 23:04:29 +00:00
|
|
|
struct ast_tm tm;
|
|
|
|
char date[40];
|
|
|
|
char *datefmt;
|
2007-06-27 19:57:36 +00:00
|
|
|
|
2008-08-10 20:23:50 +00:00
|
|
|
now = ast_tvnow();
|
|
|
|
ast_localtime(&now, &tm, NULL);
|
2008-03-04 23:04:29 +00:00
|
|
|
ast_strftime(date, sizeof(date), dateformat, &tm);
|
2012-07-31 20:21:43 +00:00
|
|
|
datefmt = ast_alloca(strlen(date) + 3 + strlen(prefix) + strlen(fmt) + 1);
|
2012-02-14 20:27:16 +00:00
|
|
|
sprintf(datefmt, "%c[%s] %s%s", (char) magic, date, prefix, fmt);
|
2008-03-04 23:04:29 +00:00
|
|
|
fmt = datefmt;
|
2008-05-05 23:00:31 +00:00
|
|
|
} else {
|
2012-07-31 20:21:43 +00:00
|
|
|
char *tmp = ast_alloca(strlen(prefix) + strlen(fmt) + 2);
|
2012-02-14 20:27:16 +00:00
|
|
|
sprintf(tmp, "%c%s%s", (char) magic, prefix, fmt);
|
2008-05-05 23:00:31 +00:00
|
|
|
fmt = tmp;
|
2008-03-04 23:04:29 +00:00
|
|
|
}
|
2007-06-27 19:57:36 +00:00
|
|
|
|
2006-12-21 21:57:16 +00:00
|
|
|
/* Build string */
|
|
|
|
res = ast_str_set_va(&buf, 0, fmt, ap);
|
|
|
|
|
|
|
|
/* If the build failed then we can drop this allocated message */
|
2012-02-14 20:27:16 +00:00
|
|
|
if (res == AST_DYNSTR_BUILD_FAILED) {
|
2006-12-21 21:57:16 +00:00
|
|
|
return;
|
2012-02-14 20:27:16 +00:00
|
|
|
}
|
2006-12-21 21:57:16 +00:00
|
|
|
|
2012-06-26 21:45:22 +00:00
|
|
|
ast_log_callid(__LOG_VERBOSE, file, line, func, callid, "%s", ast_str_buffer(buf));
|
Merge team/russell/ast_verbose_threadstorage
- instead of defining a free() wrapper in a bunch of files, define it as
ast_free() in utils.h and remove the copies from all the files.
- centralize and abstract the code used for doing thread storage. The code
lives in threadstorage.h, with one function being implemented in utils.c.
This new API includes generic thread storage as well as special functions
for handling thread local dynamic length string buffers.
- update ast_inet_ntoa() to use the new threadstorage API
- update ast_state2str() to use the new threadstorage API
- update ast_cli() to use the new threadstorage API
- Modify manager_event() to use thread storage. Instead of using a buffer of
4096 characters as the workspace for building the manager event, use a thread
local dynamic string. Now there is no length limitation on the length of the
body of a manager event.
- Significantly simplify the handling of ast_verbose() ...
- Instead of using a static char buffer and a lock to make sure only one
thread can be using ast_verbose() at a time, use a thread local dynamic
string as the workspace for preparing the verbose message. Instead of
locking around the entire function, the only locking done now is when the
message has been built and is being deliviered to the list of registered
verbose message handlers.
- This function was doing a strdup() on every message passed to it and
keeping a queue of the last 200 messages in memory. This has been
completely removed. The only place this was used was that if there were
any messages in the verbose queue when a verbose handler was registered,
all of the messages in the queue would be fed to it. So, I just made sure
that the console verbose handler and the network verbose handler (for
remote asterisk consoles) were registered before any verbose messages.
pbx_gtkconsole and pbx_kdeconsole will now lose a few verbose messages at
startup, but I didn't feel the performance hit of this message queue was
worth saving the initial verbose output for these very rarely used modules.
- I have removed the last three arguments to the verbose handlers, leaving
only the string itself because they aren't needed anymore. For example,
ast_verbose had some logic for telling the verbose handler to add
a newline if the buffer was completely full. Now that the buffer can grow
as needed, this doesn't matter anymore.
- remove unused function, ast_verbose_dmesg() which was to dispatch the
message queue
- Convert the list of verbose handlers to use the linked list macros.
- add missing newline characters to a few ast_verbose() calls
- convert the list of log channels to use the linked list macros in logger.c
- fix close_logger() to close all of the files it opened for logging
- update ast_log() to use a thread local dynamic string for its workspace
for preparing log messages instead of a buffer of size BUFSIZ (8kB on my
system) allocated on the stack. The dynamic string in this case is limited
to only growing to a maximum size of BUFSIZ.
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@39272 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2006-08-08 06:32:04 +00:00
|
|
|
}
|
2005-09-14 23:56:50 +00:00
|
|
|
|
2012-02-14 20:27:16 +00:00
|
|
|
void __ast_verbose(const char *file, int line, const char *func, int level, const char *fmt, ...)
|
2008-11-19 01:02:45 +00:00
|
|
|
{
|
2012-06-26 21:45:22 +00:00
|
|
|
struct ast_callid *callid;
|
2008-11-19 01:02:45 +00:00
|
|
|
va_list ap;
|
2009-05-15 13:13:47 +00:00
|
|
|
|
2012-06-26 21:45:22 +00:00
|
|
|
callid = ast_read_threadstorage_callid();
|
|
|
|
|
|
|
|
va_start(ap, fmt);
|
|
|
|
__ast_verbose_ap(file, line, func, level, callid, fmt, ap);
|
|
|
|
va_end(ap);
|
|
|
|
|
|
|
|
if (callid) {
|
|
|
|
ast_callid_unref(callid);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void __ast_verbose_callid(const char *file, int line, const char *func, int level, struct ast_callid *callid, const char *fmt, ...)
|
|
|
|
{
|
|
|
|
va_list ap;
|
2008-11-19 01:02:45 +00:00
|
|
|
va_start(ap, fmt);
|
2012-06-26 21:45:22 +00:00
|
|
|
__ast_verbose_ap(file, line, func, level, callid, fmt, ap);
|
2008-11-19 01:02:45 +00:00
|
|
|
va_end(ap);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* No new code should use this directly, but we have the ABI for backwards compat */
|
|
|
|
#undef ast_verbose
|
2008-11-29 17:57:39 +00:00
|
|
|
void __attribute__((format(printf, 1,2))) ast_verbose(const char *fmt, ...);
|
2008-11-19 01:02:45 +00:00
|
|
|
void ast_verbose(const char *fmt, ...)
|
|
|
|
{
|
2012-06-26 21:45:22 +00:00
|
|
|
struct ast_callid *callid;
|
2008-11-19 01:02:45 +00:00
|
|
|
va_list ap;
|
2009-05-15 13:13:47 +00:00
|
|
|
|
2012-06-26 21:45:22 +00:00
|
|
|
callid = ast_read_threadstorage_callid();
|
|
|
|
|
2008-11-19 01:02:45 +00:00
|
|
|
va_start(ap, fmt);
|
2012-06-26 21:45:22 +00:00
|
|
|
__ast_verbose_ap("", 0, "", 0, callid, fmt, ap);
|
2008-11-19 01:02:45 +00:00
|
|
|
va_end(ap);
|
2012-06-26 21:45:22 +00:00
|
|
|
|
|
|
|
if (callid) {
|
|
|
|
ast_callid_unref(callid);
|
|
|
|
}
|
2008-11-19 01:02:45 +00:00
|
|
|
}
|
|
|
|
|
2012-03-22 19:51:16 +00:00
|
|
|
int ast_register_verbose(void (*v)(const char *string))
|
Merge team/russell/ast_verbose_threadstorage
- instead of defining a free() wrapper in a bunch of files, define it as
ast_free() in utils.h and remove the copies from all the files.
- centralize and abstract the code used for doing thread storage. The code
lives in threadstorage.h, with one function being implemented in utils.c.
This new API includes generic thread storage as well as special functions
for handling thread local dynamic length string buffers.
- update ast_inet_ntoa() to use the new threadstorage API
- update ast_state2str() to use the new threadstorage API
- update ast_cli() to use the new threadstorage API
- Modify manager_event() to use thread storage. Instead of using a buffer of
4096 characters as the workspace for building the manager event, use a thread
local dynamic string. Now there is no length limitation on the length of the
body of a manager event.
- Significantly simplify the handling of ast_verbose() ...
- Instead of using a static char buffer and a lock to make sure only one
thread can be using ast_verbose() at a time, use a thread local dynamic
string as the workspace for preparing the verbose message. Instead of
locking around the entire function, the only locking done now is when the
message has been built and is being deliviered to the list of registered
verbose message handlers.
- This function was doing a strdup() on every message passed to it and
keeping a queue of the last 200 messages in memory. This has been
completely removed. The only place this was used was that if there were
any messages in the verbose queue when a verbose handler was registered,
all of the messages in the queue would be fed to it. So, I just made sure
that the console verbose handler and the network verbose handler (for
remote asterisk consoles) were registered before any verbose messages.
pbx_gtkconsole and pbx_kdeconsole will now lose a few verbose messages at
startup, but I didn't feel the performance hit of this message queue was
worth saving the initial verbose output for these very rarely used modules.
- I have removed the last three arguments to the verbose handlers, leaving
only the string itself because they aren't needed anymore. For example,
ast_verbose had some logic for telling the verbose handler to add
a newline if the buffer was completely full. Now that the buffer can grow
as needed, this doesn't matter anymore.
- remove unused function, ast_verbose_dmesg() which was to dispatch the
message queue
- Convert the list of verbose handlers to use the linked list macros.
- add missing newline characters to a few ast_verbose() calls
- convert the list of log channels to use the linked list macros in logger.c
- fix close_logger() to close all of the files it opened for logging
- update ast_log() to use a thread local dynamic string for its workspace
for preparing log messages instead of a buffer of size BUFSIZ (8kB on my
system) allocated on the stack. The dynamic string in this case is limited
to only growing to a maximum size of BUFSIZ.
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@39272 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2006-08-08 06:32:04 +00:00
|
|
|
{
|
|
|
|
struct verb *verb;
|
2005-09-14 23:56:50 +00:00
|
|
|
|
Merge team/russell/ast_verbose_threadstorage
- instead of defining a free() wrapper in a bunch of files, define it as
ast_free() in utils.h and remove the copies from all the files.
- centralize and abstract the code used for doing thread storage. The code
lives in threadstorage.h, with one function being implemented in utils.c.
This new API includes generic thread storage as well as special functions
for handling thread local dynamic length string buffers.
- update ast_inet_ntoa() to use the new threadstorage API
- update ast_state2str() to use the new threadstorage API
- update ast_cli() to use the new threadstorage API
- Modify manager_event() to use thread storage. Instead of using a buffer of
4096 characters as the workspace for building the manager event, use a thread
local dynamic string. Now there is no length limitation on the length of the
body of a manager event.
- Significantly simplify the handling of ast_verbose() ...
- Instead of using a static char buffer and a lock to make sure only one
thread can be using ast_verbose() at a time, use a thread local dynamic
string as the workspace for preparing the verbose message. Instead of
locking around the entire function, the only locking done now is when the
message has been built and is being deliviered to the list of registered
verbose message handlers.
- This function was doing a strdup() on every message passed to it and
keeping a queue of the last 200 messages in memory. This has been
completely removed. The only place this was used was that if there were
any messages in the verbose queue when a verbose handler was registered,
all of the messages in the queue would be fed to it. So, I just made sure
that the console verbose handler and the network verbose handler (for
remote asterisk consoles) were registered before any verbose messages.
pbx_gtkconsole and pbx_kdeconsole will now lose a few verbose messages at
startup, but I didn't feel the performance hit of this message queue was
worth saving the initial verbose output for these very rarely used modules.
- I have removed the last three arguments to the verbose handlers, leaving
only the string itself because they aren't needed anymore. For example,
ast_verbose had some logic for telling the verbose handler to add
a newline if the buffer was completely full. Now that the buffer can grow
as needed, this doesn't matter anymore.
- remove unused function, ast_verbose_dmesg() which was to dispatch the
message queue
- Convert the list of verbose handlers to use the linked list macros.
- add missing newline characters to a few ast_verbose() calls
- convert the list of log channels to use the linked list macros in logger.c
- fix close_logger() to close all of the files it opened for logging
- update ast_log() to use a thread local dynamic string for its workspace
for preparing log messages instead of a buffer of size BUFSIZ (8kB on my
system) allocated on the stack. The dynamic string in this case is limited
to only growing to a maximum size of BUFSIZ.
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@39272 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2006-08-08 06:32:04 +00:00
|
|
|
if (!(verb = ast_malloc(sizeof(*verb))))
|
|
|
|
return -1;
|
2004-01-12 05:05:35 +00:00
|
|
|
|
Merge team/russell/ast_verbose_threadstorage
- instead of defining a free() wrapper in a bunch of files, define it as
ast_free() in utils.h and remove the copies from all the files.
- centralize and abstract the code used for doing thread storage. The code
lives in threadstorage.h, with one function being implemented in utils.c.
This new API includes generic thread storage as well as special functions
for handling thread local dynamic length string buffers.
- update ast_inet_ntoa() to use the new threadstorage API
- update ast_state2str() to use the new threadstorage API
- update ast_cli() to use the new threadstorage API
- Modify manager_event() to use thread storage. Instead of using a buffer of
4096 characters as the workspace for building the manager event, use a thread
local dynamic string. Now there is no length limitation on the length of the
body of a manager event.
- Significantly simplify the handling of ast_verbose() ...
- Instead of using a static char buffer and a lock to make sure only one
thread can be using ast_verbose() at a time, use a thread local dynamic
string as the workspace for preparing the verbose message. Instead of
locking around the entire function, the only locking done now is when the
message has been built and is being deliviered to the list of registered
verbose message handlers.
- This function was doing a strdup() on every message passed to it and
keeping a queue of the last 200 messages in memory. This has been
completely removed. The only place this was used was that if there were
any messages in the verbose queue when a verbose handler was registered,
all of the messages in the queue would be fed to it. So, I just made sure
that the console verbose handler and the network verbose handler (for
remote asterisk consoles) were registered before any verbose messages.
pbx_gtkconsole and pbx_kdeconsole will now lose a few verbose messages at
startup, but I didn't feel the performance hit of this message queue was
worth saving the initial verbose output for these very rarely used modules.
- I have removed the last three arguments to the verbose handlers, leaving
only the string itself because they aren't needed anymore. For example,
ast_verbose had some logic for telling the verbose handler to add
a newline if the buffer was completely full. Now that the buffer can grow
as needed, this doesn't matter anymore.
- remove unused function, ast_verbose_dmesg() which was to dispatch the
message queue
- Convert the list of verbose handlers to use the linked list macros.
- add missing newline characters to a few ast_verbose() calls
- convert the list of log channels to use the linked list macros in logger.c
- fix close_logger() to close all of the files it opened for logging
- update ast_log() to use a thread local dynamic string for its workspace
for preparing log messages instead of a buffer of size BUFSIZ (8kB on my
system) allocated on the stack. The dynamic string in this case is limited
to only growing to a maximum size of BUFSIZ.
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@39272 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2006-08-08 06:32:04 +00:00
|
|
|
verb->verboser = v;
|
1999-12-05 07:28:29 +00:00
|
|
|
|
2007-07-20 01:54:52 +00:00
|
|
|
AST_RWLIST_WRLOCK(&verbosers);
|
|
|
|
AST_RWLIST_INSERT_HEAD(&verbosers, verb, list);
|
|
|
|
AST_RWLIST_UNLOCK(&verbosers);
|
2012-03-22 19:51:16 +00:00
|
|
|
|
2001-04-30 17:39:02 +00:00
|
|
|
return 0;
|
|
|
|
}
|
1999-12-05 07:28:29 +00:00
|
|
|
|
Merge team/russell/ast_verbose_threadstorage
- instead of defining a free() wrapper in a bunch of files, define it as
ast_free() in utils.h and remove the copies from all the files.
- centralize and abstract the code used for doing thread storage. The code
lives in threadstorage.h, with one function being implemented in utils.c.
This new API includes generic thread storage as well as special functions
for handling thread local dynamic length string buffers.
- update ast_inet_ntoa() to use the new threadstorage API
- update ast_state2str() to use the new threadstorage API
- update ast_cli() to use the new threadstorage API
- Modify manager_event() to use thread storage. Instead of using a buffer of
4096 characters as the workspace for building the manager event, use a thread
local dynamic string. Now there is no length limitation on the length of the
body of a manager event.
- Significantly simplify the handling of ast_verbose() ...
- Instead of using a static char buffer and a lock to make sure only one
thread can be using ast_verbose() at a time, use a thread local dynamic
string as the workspace for preparing the verbose message. Instead of
locking around the entire function, the only locking done now is when the
message has been built and is being deliviered to the list of registered
verbose message handlers.
- This function was doing a strdup() on every message passed to it and
keeping a queue of the last 200 messages in memory. This has been
completely removed. The only place this was used was that if there were
any messages in the verbose queue when a verbose handler was registered,
all of the messages in the queue would be fed to it. So, I just made sure
that the console verbose handler and the network verbose handler (for
remote asterisk consoles) were registered before any verbose messages.
pbx_gtkconsole and pbx_kdeconsole will now lose a few verbose messages at
startup, but I didn't feel the performance hit of this message queue was
worth saving the initial verbose output for these very rarely used modules.
- I have removed the last three arguments to the verbose handlers, leaving
only the string itself because they aren't needed anymore. For example,
ast_verbose had some logic for telling the verbose handler to add
a newline if the buffer was completely full. Now that the buffer can grow
as needed, this doesn't matter anymore.
- remove unused function, ast_verbose_dmesg() which was to dispatch the
message queue
- Convert the list of verbose handlers to use the linked list macros.
- add missing newline characters to a few ast_verbose() calls
- convert the list of log channels to use the linked list macros in logger.c
- fix close_logger() to close all of the files it opened for logging
- update ast_log() to use a thread local dynamic string for its workspace
for preparing log messages instead of a buffer of size BUFSIZ (8kB on my
system) allocated on the stack. The dynamic string in this case is limited
to only growing to a maximum size of BUFSIZ.
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@39272 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2006-08-08 06:32:04 +00:00
|
|
|
int ast_unregister_verbose(void (*v)(const char *string))
|
1999-12-05 07:28:29 +00:00
|
|
|
{
|
Merge team/russell/ast_verbose_threadstorage
- instead of defining a free() wrapper in a bunch of files, define it as
ast_free() in utils.h and remove the copies from all the files.
- centralize and abstract the code used for doing thread storage. The code
lives in threadstorage.h, with one function being implemented in utils.c.
This new API includes generic thread storage as well as special functions
for handling thread local dynamic length string buffers.
- update ast_inet_ntoa() to use the new threadstorage API
- update ast_state2str() to use the new threadstorage API
- update ast_cli() to use the new threadstorage API
- Modify manager_event() to use thread storage. Instead of using a buffer of
4096 characters as the workspace for building the manager event, use a thread
local dynamic string. Now there is no length limitation on the length of the
body of a manager event.
- Significantly simplify the handling of ast_verbose() ...
- Instead of using a static char buffer and a lock to make sure only one
thread can be using ast_verbose() at a time, use a thread local dynamic
string as the workspace for preparing the verbose message. Instead of
locking around the entire function, the only locking done now is when the
message has been built and is being deliviered to the list of registered
verbose message handlers.
- This function was doing a strdup() on every message passed to it and
keeping a queue of the last 200 messages in memory. This has been
completely removed. The only place this was used was that if there were
any messages in the verbose queue when a verbose handler was registered,
all of the messages in the queue would be fed to it. So, I just made sure
that the console verbose handler and the network verbose handler (for
remote asterisk consoles) were registered before any verbose messages.
pbx_gtkconsole and pbx_kdeconsole will now lose a few verbose messages at
startup, but I didn't feel the performance hit of this message queue was
worth saving the initial verbose output for these very rarely used modules.
- I have removed the last three arguments to the verbose handlers, leaving
only the string itself because they aren't needed anymore. For example,
ast_verbose had some logic for telling the verbose handler to add
a newline if the buffer was completely full. Now that the buffer can grow
as needed, this doesn't matter anymore.
- remove unused function, ast_verbose_dmesg() which was to dispatch the
message queue
- Convert the list of verbose handlers to use the linked list macros.
- add missing newline characters to a few ast_verbose() calls
- convert the list of log channels to use the linked list macros in logger.c
- fix close_logger() to close all of the files it opened for logging
- update ast_log() to use a thread local dynamic string for its workspace
for preparing log messages instead of a buffer of size BUFSIZ (8kB on my
system) allocated on the stack. The dynamic string in this case is limited
to only growing to a maximum size of BUFSIZ.
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@39272 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2006-08-08 06:32:04 +00:00
|
|
|
struct verb *cur;
|
1999-12-05 07:28:29 +00:00
|
|
|
|
2007-07-20 01:54:52 +00:00
|
|
|
AST_RWLIST_WRLOCK(&verbosers);
|
|
|
|
AST_RWLIST_TRAVERSE_SAFE_BEGIN(&verbosers, cur, list) {
|
Merge team/russell/ast_verbose_threadstorage
- instead of defining a free() wrapper in a bunch of files, define it as
ast_free() in utils.h and remove the copies from all the files.
- centralize and abstract the code used for doing thread storage. The code
lives in threadstorage.h, with one function being implemented in utils.c.
This new API includes generic thread storage as well as special functions
for handling thread local dynamic length string buffers.
- update ast_inet_ntoa() to use the new threadstorage API
- update ast_state2str() to use the new threadstorage API
- update ast_cli() to use the new threadstorage API
- Modify manager_event() to use thread storage. Instead of using a buffer of
4096 characters as the workspace for building the manager event, use a thread
local dynamic string. Now there is no length limitation on the length of the
body of a manager event.
- Significantly simplify the handling of ast_verbose() ...
- Instead of using a static char buffer and a lock to make sure only one
thread can be using ast_verbose() at a time, use a thread local dynamic
string as the workspace for preparing the verbose message. Instead of
locking around the entire function, the only locking done now is when the
message has been built and is being deliviered to the list of registered
verbose message handlers.
- This function was doing a strdup() on every message passed to it and
keeping a queue of the last 200 messages in memory. This has been
completely removed. The only place this was used was that if there were
any messages in the verbose queue when a verbose handler was registered,
all of the messages in the queue would be fed to it. So, I just made sure
that the console verbose handler and the network verbose handler (for
remote asterisk consoles) were registered before any verbose messages.
pbx_gtkconsole and pbx_kdeconsole will now lose a few verbose messages at
startup, but I didn't feel the performance hit of this message queue was
worth saving the initial verbose output for these very rarely used modules.
- I have removed the last three arguments to the verbose handlers, leaving
only the string itself because they aren't needed anymore. For example,
ast_verbose had some logic for telling the verbose handler to add
a newline if the buffer was completely full. Now that the buffer can grow
as needed, this doesn't matter anymore.
- remove unused function, ast_verbose_dmesg() which was to dispatch the
message queue
- Convert the list of verbose handlers to use the linked list macros.
- add missing newline characters to a few ast_verbose() calls
- convert the list of log channels to use the linked list macros in logger.c
- fix close_logger() to close all of the files it opened for logging
- update ast_log() to use a thread local dynamic string for its workspace
for preparing log messages instead of a buffer of size BUFSIZ (8kB on my
system) allocated on the stack. The dynamic string in this case is limited
to only growing to a maximum size of BUFSIZ.
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@39272 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2006-08-08 06:32:04 +00:00
|
|
|
if (cur->verboser == v) {
|
2007-11-08 05:28:47 +00:00
|
|
|
AST_RWLIST_REMOVE_CURRENT(list);
|
2007-12-12 20:05:13 +00:00
|
|
|
ast_free(cur);
|
1999-12-05 07:28:29 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2007-11-08 05:28:47 +00:00
|
|
|
AST_RWLIST_TRAVERSE_SAFE_END;
|
2007-07-20 01:54:52 +00:00
|
|
|
AST_RWLIST_UNLOCK(&verbosers);
|
2012-03-22 19:51:16 +00:00
|
|
|
|
Merge team/russell/ast_verbose_threadstorage
- instead of defining a free() wrapper in a bunch of files, define it as
ast_free() in utils.h and remove the copies from all the files.
- centralize and abstract the code used for doing thread storage. The code
lives in threadstorage.h, with one function being implemented in utils.c.
This new API includes generic thread storage as well as special functions
for handling thread local dynamic length string buffers.
- update ast_inet_ntoa() to use the new threadstorage API
- update ast_state2str() to use the new threadstorage API
- update ast_cli() to use the new threadstorage API
- Modify manager_event() to use thread storage. Instead of using a buffer of
4096 characters as the workspace for building the manager event, use a thread
local dynamic string. Now there is no length limitation on the length of the
body of a manager event.
- Significantly simplify the handling of ast_verbose() ...
- Instead of using a static char buffer and a lock to make sure only one
thread can be using ast_verbose() at a time, use a thread local dynamic
string as the workspace for preparing the verbose message. Instead of
locking around the entire function, the only locking done now is when the
message has been built and is being deliviered to the list of registered
verbose message handlers.
- This function was doing a strdup() on every message passed to it and
keeping a queue of the last 200 messages in memory. This has been
completely removed. The only place this was used was that if there were
any messages in the verbose queue when a verbose handler was registered,
all of the messages in the queue would be fed to it. So, I just made sure
that the console verbose handler and the network verbose handler (for
remote asterisk consoles) were registered before any verbose messages.
pbx_gtkconsole and pbx_kdeconsole will now lose a few verbose messages at
startup, but I didn't feel the performance hit of this message queue was
worth saving the initial verbose output for these very rarely used modules.
- I have removed the last three arguments to the verbose handlers, leaving
only the string itself because they aren't needed anymore. For example,
ast_verbose had some logic for telling the verbose handler to add
a newline if the buffer was completely full. Now that the buffer can grow
as needed, this doesn't matter anymore.
- remove unused function, ast_verbose_dmesg() which was to dispatch the
message queue
- Convert the list of verbose handlers to use the linked list macros.
- add missing newline characters to a few ast_verbose() calls
- convert the list of log channels to use the linked list macros in logger.c
- fix close_logger() to close all of the files it opened for logging
- update ast_log() to use a thread local dynamic string for its workspace
for preparing log messages instead of a buffer of size BUFSIZ (8kB on my
system) allocated on the stack. The dynamic string in this case is limited
to only growing to a maximum size of BUFSIZ.
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@39272 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2006-08-08 06:32:04 +00:00
|
|
|
return cur ? 0 : -1;
|
1999-12-05 07:28:29 +00:00
|
|
|
}
|
2009-05-15 13:13:47 +00:00
|
|
|
|
|
|
|
static void update_logchannels(void)
|
|
|
|
{
|
|
|
|
struct logchannel *cur;
|
|
|
|
|
|
|
|
AST_RWLIST_WRLOCK(&logchannels);
|
|
|
|
|
|
|
|
global_logmask = 0;
|
|
|
|
|
|
|
|
AST_RWLIST_TRAVERSE(&logchannels, cur, list) {
|
2012-02-14 20:27:16 +00:00
|
|
|
cur->logmask = make_components(cur->components, cur->lineno, &cur->verbosity);
|
2009-05-15 13:13:47 +00:00
|
|
|
global_logmask |= cur->logmask;
|
|
|
|
}
|
|
|
|
|
|
|
|
AST_RWLIST_UNLOCK(&logchannels);
|
|
|
|
}
|
|
|
|
|
|
|
|
int ast_logger_register_level(const char *name)
|
|
|
|
{
|
|
|
|
unsigned int level;
|
|
|
|
unsigned int available = 0;
|
|
|
|
|
|
|
|
AST_RWLIST_WRLOCK(&logchannels);
|
|
|
|
|
|
|
|
for (level = 0; level < ARRAY_LEN(levels); level++) {
|
|
|
|
if ((level >= 16) && !available && !levels[level]) {
|
|
|
|
available = level;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (levels[level] && !strcasecmp(levels[level], name)) {
|
|
|
|
ast_log(LOG_WARNING,
|
|
|
|
"Unable to register dynamic logger level '%s': a standard logger level uses that name.\n",
|
|
|
|
name);
|
|
|
|
AST_RWLIST_UNLOCK(&logchannels);
|
|
|
|
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!available) {
|
|
|
|
ast_log(LOG_WARNING,
|
|
|
|
"Unable to register dynamic logger level '%s'; maximum number of levels registered.\n",
|
|
|
|
name);
|
|
|
|
AST_RWLIST_UNLOCK(&logchannels);
|
|
|
|
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
levels[available] = ast_strdup(name);
|
|
|
|
|
|
|
|
AST_RWLIST_UNLOCK(&logchannels);
|
|
|
|
|
|
|
|
ast_debug(1, "Registered dynamic logger level '%s' with index %d.\n", name, available);
|
|
|
|
|
|
|
|
update_logchannels();
|
|
|
|
|
|
|
|
return available;
|
|
|
|
}
|
|
|
|
|
|
|
|
void ast_logger_unregister_level(const char *name)
|
|
|
|
{
|
|
|
|
unsigned int found = 0;
|
|
|
|
unsigned int x;
|
|
|
|
|
|
|
|
AST_RWLIST_WRLOCK(&logchannels);
|
|
|
|
|
|
|
|
for (x = 16; x < ARRAY_LEN(levels); x++) {
|
|
|
|
if (!levels[x]) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (strcasecmp(levels[x], name)) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
found = 1;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (found) {
|
|
|
|
/* take this level out of the global_logmask, to ensure that no new log messages
|
|
|
|
* will be queued for it
|
|
|
|
*/
|
|
|
|
|
|
|
|
global_logmask &= ~(1 << x);
|
|
|
|
|
2011-09-08 22:30:42 +00:00
|
|
|
ast_free(levels[x]);
|
2009-05-15 13:13:47 +00:00
|
|
|
levels[x] = NULL;
|
|
|
|
AST_RWLIST_UNLOCK(&logchannels);
|
|
|
|
|
|
|
|
ast_debug(1, "Unregistered dynamic logger level '%s' with index %d.\n", name, x);
|
|
|
|
|
|
|
|
update_logchannels();
|
|
|
|
} else {
|
|
|
|
AST_RWLIST_UNLOCK(&logchannels);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|