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
|
2005-09-14 20:46:50 +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
|
|
|
*/
|
|
|
|
|
2006-06-07 18:54:56 +00:00
|
|
|
#include "asterisk.h"
|
|
|
|
|
|
|
|
ASTERISK_FILE_VERSION(__FILE__, "$Revision$")
|
|
|
|
|
2003-11-26 22:00:07 +00:00
|
|
|
#include <signal.h>
|
1999-12-05 07:28:29 +00:00
|
|
|
#include <stdarg.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <unistd.h>
|
|
|
|
#include <time.h>
|
2005-04-22 13:11:34 +00:00
|
|
|
#include <string.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <errno.h>
|
|
|
|
#include <sys/stat.h>
|
2007-07-26 19:33:47 +00:00
|
|
|
#if ((defined(AST_DEVMODE)) && (defined(linux)))
|
2005-12-27 06:24:28 +00:00
|
|
|
#include <execinfo.h>
|
2006-02-22 21:53:56 +00:00
|
|
|
#define MAX_BACKTRACE_FRAMES 20
|
2005-12-27 06:24:28 +00:00
|
|
|
#endif
|
2005-04-22 13:11:34 +00:00
|
|
|
|
|
|
|
#define SYSLOG_NAMES /* so we can map syslog facilities names to their numeric values,
|
|
|
|
from <syslog.h> which is included by logger.h */
|
|
|
|
#include <syslog.h>
|
|
|
|
|
2004-01-12 05:05:35 +00:00
|
|
|
static int syslog_level_map[] = {
|
|
|
|
LOG_DEBUG,
|
|
|
|
LOG_INFO, /* arbitrary equivalent of LOG_EVENT */
|
|
|
|
LOG_NOTICE,
|
|
|
|
LOG_WARNING,
|
2004-01-27 00:23:39 +00:00
|
|
|
LOG_ERR,
|
2005-08-22 21:19:59 +00:00
|
|
|
LOG_DEBUG,
|
2004-06-29 04:42:19 +00:00
|
|
|
LOG_DEBUG
|
2004-01-12 05:05:35 +00:00
|
|
|
};
|
2004-06-29 04:42:19 +00:00
|
|
|
|
2006-02-26 16:40:39 +00:00
|
|
|
#define SYSLOG_NLEVELS sizeof(syslog_level_map) / sizeof(int)
|
2004-01-12 05:05:35 +00:00
|
|
|
|
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/options.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"
|
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"
|
1999-12-05 07:28:29 +00:00
|
|
|
|
2005-10-05 00:21:56 +00:00
|
|
|
#if defined(__linux__) && !defined(__NR_gettid)
|
2004-11-01 16:26:32 +00:00
|
|
|
#include <asm/unistd.h>
|
2005-10-05 00:21:56 +00:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#if defined(__linux__) && defined(__NR_gettid)
|
2004-11-01 16:26:32 +00:00
|
|
|
#define GETTID() syscall(__NR_gettid)
|
|
|
|
#else
|
|
|
|
#define GETTID() getpid()
|
|
|
|
#endif
|
|
|
|
|
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;
|
|
|
|
|
2006-12-27 22:14:33 +00:00
|
|
|
static int filesize_reload_needed;
|
2004-11-01 01:48:35 +00:00
|
|
|
static int global_logmask = -1;
|
2006-12-27 22:14:33 +00:00
|
|
|
static int rotatetimestamp;
|
1999-12-05 07:28:29 +00:00
|
|
|
|
2005-03-11 08:49:01 +00:00
|
|
|
static struct {
|
|
|
|
unsigned int queue_log:1;
|
|
|
|
unsigned int event_log:1;
|
|
|
|
} logfiles = { 1, 1 };
|
|
|
|
|
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 {
|
2005-03-31 19:08:51 +00:00
|
|
|
int logmask; /* What to log to this channel */
|
|
|
|
int disabled; /* If this channel is disabled or not */
|
|
|
|
int facility; /* syslog facility */
|
|
|
|
enum logtypes type; /* Type of log channel */
|
|
|
|
FILE *fileptr; /* logfile logging file pointer */
|
|
|
|
char filename[256]; /* Filename */
|
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;
|
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;
|
|
|
|
char date[256];
|
|
|
|
int level;
|
|
|
|
const char *file;
|
|
|
|
int line;
|
|
|
|
const char *function;
|
|
|
|
AST_LIST_ENTRY(logmsg) list;
|
|
|
|
char str[0];
|
|
|
|
};
|
|
|
|
|
|
|
|
static AST_LIST_HEAD_STATIC(logmsgs, logmsg);
|
|
|
|
static pthread_t logthread = AST_PTHREADT_NULL;
|
|
|
|
static ast_cond_t logcond;
|
2006-12-27 22:14:33 +00:00
|
|
|
static int close_logger_thread;
|
2006-12-21 21:57:16 +00:00
|
|
|
|
2006-12-27 22:14:33 +00:00
|
|
|
static FILE *eventlog;
|
|
|
|
static FILE *qlog;
|
1999-12-05 07:28:29 +00:00
|
|
|
|
|
|
|
static char *levels[] = {
|
2004-06-29 04:42:19 +00:00
|
|
|
"DEBUG",
|
|
|
|
"EVENT",
|
|
|
|
"NOTICE",
|
|
|
|
"WARNING",
|
|
|
|
"ERROR",
|
2005-08-22 21:19:59 +00:00
|
|
|
"VERBOSE",
|
|
|
|
"DTMF"
|
1999-12-05 07:28:29 +00:00
|
|
|
};
|
|
|
|
|
2002-06-21 01:40:13 +00:00
|
|
|
static int colors[] = {
|
2004-06-29 04:42:19 +00:00
|
|
|
COLOR_BRGREEN,
|
|
|
|
COLOR_BRBLUE,
|
|
|
|
COLOR_YELLOW,
|
|
|
|
COLOR_BRRED,
|
|
|
|
COLOR_RED,
|
2005-08-22 21:19:59 +00:00
|
|
|
COLOR_GREEN,
|
|
|
|
COLOR_BRGREEN
|
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
|
|
|
|
2002-02-11 04:25:04 +00:00
|
|
|
static int make_components(char *s, int lineno)
|
|
|
|
{
|
|
|
|
char *w;
|
|
|
|
int res = 0;
|
2006-07-21 23:58:14 +00:00
|
|
|
char *stringp = s;
|
|
|
|
|
|
|
|
while ((w = strsep(&stringp, ","))) {
|
|
|
|
w = ast_skip_blanks(w);
|
2005-03-31 19:08:51 +00:00
|
|
|
if (!strcasecmp(w, "error"))
|
|
|
|
res |= (1 << __LOG_ERROR);
|
|
|
|
else if (!strcasecmp(w, "warning"))
|
|
|
|
res |= (1 << __LOG_WARNING);
|
|
|
|
else if (!strcasecmp(w, "notice"))
|
|
|
|
res |= (1 << __LOG_NOTICE);
|
|
|
|
else if (!strcasecmp(w, "event"))
|
|
|
|
res |= (1 << __LOG_EVENT);
|
|
|
|
else if (!strcasecmp(w, "debug"))
|
|
|
|
res |= (1 << __LOG_DEBUG);
|
|
|
|
else if (!strcasecmp(w, "verbose"))
|
|
|
|
res |= (1 << __LOG_VERBOSE);
|
2005-08-22 21:19:59 +00:00
|
|
|
else if (!strcasecmp(w, "dtmf"))
|
|
|
|
res |= (1 << __LOG_DTMF);
|
2005-03-31 19:08:51 +00:00
|
|
|
else {
|
|
|
|
fprintf(stderr, "Logfile Warning: Unknown keyword '%s' at line %d of logger.conf\n", w, lineno);
|
|
|
|
}
|
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;
|
|
|
|
}
|
|
|
|
|
2004-01-12 05:05:35 +00:00
|
|
|
static struct logchannel *make_logchannel(char *channel, 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;
|
2004-12-14 23:36:30 +00:00
|
|
|
#ifndef SOLARIS
|
2004-01-12 05:05:35 +00:00
|
|
|
CODE *cptr;
|
2004-12-14 23:36:30 +00:00
|
|
|
#endif
|
2004-01-12 05:05:35 +00:00
|
|
|
|
2006-02-27 01:43:42 +00:00
|
|
|
if (ast_strlen_zero(channel) || !(chan = ast_calloc(1, sizeof(*chan))))
|
2002-02-11 04:25:04 +00:00
|
|
|
return NULL;
|
2004-01-12 05:05:35 +00:00
|
|
|
|
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
|
|
|
|
|
|
|
#ifndef SOLARIS
|
2005-04-01 16:09:21 +00:00
|
|
|
/*
|
|
|
|
* Walk through the list of facilitynames (defined in sys/syslog.h)
|
|
|
|
* to see if we can find the one we have been given
|
|
|
|
*/
|
|
|
|
chan->facility = -1;
|
|
|
|
cptr = facilitynames;
|
|
|
|
while (cptr->c_name) {
|
|
|
|
if (!strcasecmp(facility, cptr->c_name)) {
|
|
|
|
chan->facility = cptr->c_val;
|
|
|
|
break;
|
2004-01-12 05:05:35 +00:00
|
|
|
}
|
2005-04-01 16:09:21 +00:00
|
|
|
cptr++;
|
|
|
|
}
|
2004-12-14 23:36:30 +00:00
|
|
|
#else
|
2005-04-01 16:09:21 +00:00
|
|
|
chan->facility = -1;
|
|
|
|
if (!strcasecmp(facility, "kern"))
|
|
|
|
chan->facility = LOG_KERN;
|
|
|
|
else if (!strcasecmp(facility, "USER"))
|
|
|
|
chan->facility = LOG_USER;
|
|
|
|
else if (!strcasecmp(facility, "MAIL"))
|
|
|
|
chan->facility = LOG_MAIL;
|
|
|
|
else if (!strcasecmp(facility, "DAEMON"))
|
|
|
|
chan->facility = LOG_DAEMON;
|
|
|
|
else if (!strcasecmp(facility, "AUTH"))
|
|
|
|
chan->facility = LOG_AUTH;
|
|
|
|
else if (!strcasecmp(facility, "SYSLOG"))
|
|
|
|
chan->facility = LOG_SYSLOG;
|
|
|
|
else if (!strcasecmp(facility, "LPR"))
|
|
|
|
chan->facility = LOG_LPR;
|
|
|
|
else if (!strcasecmp(facility, "NEWS"))
|
|
|
|
chan->facility = LOG_NEWS;
|
|
|
|
else if (!strcasecmp(facility, "UUCP"))
|
|
|
|
chan->facility = LOG_UUCP;
|
|
|
|
else if (!strcasecmp(facility, "CRON"))
|
|
|
|
chan->facility = LOG_CRON;
|
|
|
|
else if (!strcasecmp(facility, "LOCAL0"))
|
|
|
|
chan->facility = LOG_LOCAL0;
|
|
|
|
else if (!strcasecmp(facility, "LOCAL1"))
|
|
|
|
chan->facility = LOG_LOCAL1;
|
|
|
|
else if (!strcasecmp(facility, "LOCAL2"))
|
|
|
|
chan->facility = LOG_LOCAL2;
|
|
|
|
else if (!strcasecmp(facility, "LOCAL3"))
|
|
|
|
chan->facility = LOG_LOCAL3;
|
|
|
|
else if (!strcasecmp(facility, "LOCAL4"))
|
|
|
|
chan->facility = LOG_LOCAL4;
|
|
|
|
else if (!strcasecmp(facility, "LOCAL5"))
|
|
|
|
chan->facility = LOG_LOCAL5;
|
|
|
|
else if (!strcasecmp(facility, "LOCAL6"))
|
|
|
|
chan->facility = LOG_LOCAL6;
|
|
|
|
else if (!strcasecmp(facility, "LOCAL7"))
|
|
|
|
chan->facility = LOG_LOCAL7;
|
2005-03-31 19:08:51 +00:00
|
|
|
#endif /* Solaris */
|
|
|
|
|
2005-04-01 16:09:21 +00:00
|
|
|
if (0 > chan->facility) {
|
|
|
|
fprintf(stderr, "Logger Warning: bad syslog facility in logger.conf\n");
|
|
|
|
free(chan);
|
|
|
|
return NULL;
|
|
|
|
}
|
2004-01-12 05:05:35 +00:00
|
|
|
|
2005-04-01 16:09:21 +00:00
|
|
|
chan->type = LOGTYPE_SYSLOG;
|
|
|
|
snprintf(chan->filename, sizeof(chan->filename), "%s", channel);
|
|
|
|
openlog("asterisk", LOG_PID, chan->facility);
|
|
|
|
} else {
|
|
|
|
if (channel[0] == '/') {
|
2007-01-23 00:11:32 +00:00
|
|
|
if (!ast_strlen_zero(hostname)) {
|
2005-04-01 16:09:21 +00:00
|
|
|
snprintf(chan->filename, sizeof(chan->filename) - 1,"%s.%s", channel, hostname);
|
2004-09-05 03:48:05 +00:00
|
|
|
} else {
|
2005-07-10 22:56:21 +00:00
|
|
|
ast_copy_string(chan->filename, channel, sizeof(chan->filename));
|
2004-09-05 03:48:05 +00:00
|
|
|
}
|
2005-04-01 16:09:21 +00:00
|
|
|
}
|
|
|
|
|
2007-01-23 00:11:32 +00:00
|
|
|
if (!ast_strlen_zero(hostname)) {
|
2006-11-04 01:34:59 +00:00
|
|
|
snprintf(chan->filename, sizeof(chan->filename), "%s/%s.%s", ast_config_AST_LOG_DIR, channel, hostname);
|
2005-04-01 16:09:21 +00:00
|
|
|
} else {
|
2006-11-04 01:34:59 +00:00
|
|
|
snprintf(chan->filename, sizeof(chan->filename), "%s/%s", ast_config_AST_LOG_DIR, channel);
|
2002-02-11 04:25:04 +00:00
|
|
|
}
|
2005-04-01 16:09:21 +00:00
|
|
|
chan->fileptr = fopen(chan->filename, "a");
|
|
|
|
if (!chan->fileptr) {
|
|
|
|
/* Can't log here, since we're called with a lock */
|
|
|
|
fprintf(stderr, "Logger Warning: Unable to open log file '%s': %s\n", chan->filename, strerror(errno));
|
|
|
|
}
|
|
|
|
chan->type = LOGTYPE_FILE;
|
2002-02-11 04:25:04 +00:00
|
|
|
}
|
2005-04-01 16:09:21 +00:00
|
|
|
chan->logmask = make_components(components, lineno);
|
2004-01-12 05:05:35 +00:00
|
|
|
return chan;
|
2002-02-11 04:25:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void init_logger_chain(void)
|
|
|
|
{
|
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;
|
2002-02-11 04:25:04 +00:00
|
|
|
|
2004-01-12 05:05:35 +00:00
|
|
|
/* delete our list of log channels */
|
2007-07-20 01:54:52 +00:00
|
|
|
AST_RWLIST_WRLOCK(&logchannels);
|
|
|
|
while ((chan = AST_RWLIST_REMOVE_HEAD(&logchannels, list)))
|
2005-03-31 19:08:51 +00:00
|
|
|
free(chan);
|
2007-07-20 01:54:52 +00:00
|
|
|
AST_RWLIST_UNLOCK(&logchannels);
|
2004-09-05 03:48:05 +00:00
|
|
|
|
2004-10-24 06:12:21 +00:00
|
|
|
global_logmask = 0;
|
2006-09-07 03:35:42 +00:00
|
|
|
errno = 0;
|
2004-01-12 05:05:35 +00:00
|
|
|
/* close syslog */
|
|
|
|
closelog();
|
2004-09-05 03:48:05 +00:00
|
|
|
|
2005-01-25 06:10:20 +00:00
|
|
|
cfg = ast_config_load("logger.conf");
|
2002-02-11 04:25:04 +00:00
|
|
|
|
2006-02-08 23:14:17 +00:00
|
|
|
/* If no config file, we're fine, set default options. */
|
|
|
|
if (!cfg) {
|
2006-09-07 03:35:42 +00:00
|
|
|
if (errno)
|
|
|
|
fprintf(stderr, "Unable to open logger.conf: %s; default settings will be used.\n", strerror(errno));
|
|
|
|
else
|
|
|
|
fprintf(stderr, "Errors detected in logger.conf: see above; default settings will be used.\n");
|
2006-02-27 01:43:42 +00:00
|
|
|
if (!(chan = ast_calloc(1, sizeof(*chan))))
|
|
|
|
return;
|
2006-02-08 23:14:17 +00:00
|
|
|
chan->type = LOGTYPE_CONSOLE;
|
|
|
|
chan->logmask = 28; /*warning,notice,error */
|
2007-07-20 01:54:52 +00:00
|
|
|
AST_RWLIST_WRLOCK(&logchannels);
|
|
|
|
AST_RWLIST_INSERT_HEAD(&logchannels, chan, list);
|
|
|
|
AST_RWLIST_UNLOCK(&logchannels);
|
2006-02-08 23:14:17 +00:00
|
|
|
global_logmask |= chan->logmask;
|
2005-03-31 19:08:51 +00:00
|
|
|
return;
|
2006-02-08 23:14:17 +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));
|
2004-09-05 03:48:05 +00:00
|
|
|
ast_log(LOG_WARNING, "What box has no hostname???\n");
|
|
|
|
}
|
|
|
|
} else
|
|
|
|
hostname[0] = '\0';
|
|
|
|
} else
|
|
|
|
hostname[0] = '\0';
|
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));
|
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", "queue_log")))
|
2005-03-11 08:49:01 +00:00
|
|
|
logfiles.queue_log = 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", "event_log")))
|
2005-03-11 08:49:01 +00:00
|
|
|
logfiles.event_log = ast_true(s);
|
2006-09-26 17:09:01 +00:00
|
|
|
if ((s = ast_variable_retrieve(cfg, "general", "queue_log_name")))
|
|
|
|
ast_copy_string(queue_log_name, s, sizeof(queue_log_name));
|
2006-10-02 17:54:21 +00:00
|
|
|
if ((s = ast_variable_retrieve(cfg, "general", "rotatetimestamp")))
|
|
|
|
rotatetimestamp = ast_true(s);
|
2005-03-11 08:49:01 +00:00
|
|
|
|
2007-07-20 01:54:52 +00:00
|
|
|
AST_RWLIST_WRLOCK(&logchannels);
|
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) {
|
|
|
|
if (!(chan = make_logchannel(var->name, var->value, var->lineno)))
|
|
|
|
continue;
|
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
|
|
|
}
|
2007-07-20 01:54:52 +00:00
|
|
|
AST_RWLIST_UNLOCK(&logchannels);
|
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
|
|
|
}
|
|
|
|
|
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;
|
2007-07-20 01:54:52 +00:00
|
|
|
char qlog_msg[8192];
|
|
|
|
int qlog_len;
|
2004-02-12 22:11:02 +00:00
|
|
|
if (qlog) {
|
|
|
|
va_start(ap, fmt);
|
2007-07-20 01:54:52 +00:00
|
|
|
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);
|
2004-02-12 22:11:02 +00:00
|
|
|
va_end(ap);
|
2007-07-20 01:54:52 +00:00
|
|
|
}
|
|
|
|
AST_RWLIST_RDLOCK(&logchannels);
|
|
|
|
if (qlog) {
|
|
|
|
fprintf(qlog, "%s\n", qlog_msg);
|
2004-02-12 22:11:02 +00:00
|
|
|
fflush(qlog);
|
|
|
|
}
|
2007-07-20 01:54:52 +00:00
|
|
|
AST_RWLIST_UNLOCK(&logchannels);
|
2004-02-12 22:11:02 +00:00
|
|
|
}
|
|
|
|
|
2003-11-26 22:00:07 +00:00
|
|
|
int reload_logger(int rotate)
|
1999-12-05 07:28:29 +00:00
|
|
|
{
|
2006-06-09 20:40:10 +00:00
|
|
|
char old[PATH_MAX] = "";
|
|
|
|
char new[PATH_MAX];
|
2006-02-26 16:40:39 +00:00
|
|
|
int event_rotate = rotate, queue_rotate = rotate;
|
2004-01-12 05:05:35 +00:00
|
|
|
struct logchannel *f;
|
2003-12-05 00:50:42 +00:00
|
|
|
FILE *myf;
|
2006-02-26 16:40:39 +00:00
|
|
|
int x, 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
|
|
|
|
2003-11-26 22:00:07 +00:00
|
|
|
if (eventlog)
|
2004-01-12 05:05:35 +00:00
|
|
|
fclose(eventlog);
|
2003-11-26 22:00:07 +00:00
|
|
|
else
|
2006-02-26 16:40:39 +00:00
|
|
|
event_rotate = 0;
|
2003-12-05 00:50:42 +00:00
|
|
|
eventlog = NULL;
|
2003-11-26 22:00:07 +00:00
|
|
|
|
2006-02-26 16:40:39 +00:00
|
|
|
if (qlog)
|
|
|
|
fclose(qlog);
|
|
|
|
else
|
|
|
|
queue_rotate = 0;
|
|
|
|
qlog = NULL;
|
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 */
|
|
|
|
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)) {
|
2005-03-31 19:08:51 +00:00
|
|
|
fclose(f->fileptr); /* Close file */
|
2004-01-12 05:05:35 +00:00
|
|
|
f->fileptr = NULL;
|
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 (rotate) {
|
2005-07-10 22:56:21 +00:00
|
|
|
ast_copy_string(old, f->filename, sizeof(old));
|
2006-10-02 17:54:21 +00:00
|
|
|
|
|
|
|
if (!rotatetimestamp) {
|
|
|
|
for (x = 0; ; x++) {
|
|
|
|
snprintf(new, sizeof(new), "%s.%d", f->filename, x);
|
2006-11-04 01:34:59 +00:00
|
|
|
myf = fopen(new, "r");
|
2006-10-02 17:54:21 +00:00
|
|
|
if (myf)
|
|
|
|
fclose(myf);
|
|
|
|
else
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
} else
|
|
|
|
snprintf(new, sizeof(new), "%s.%ld", f->filename, (long)time(NULL));
|
|
|
|
|
2004-01-12 05:05:35 +00:00
|
|
|
/* do it */
|
|
|
|
if (rename(old,new))
|
|
|
|
fprintf(stderr, "Unable to rename file '%s' to '%s'\n", old, new);
|
|
|
|
}
|
|
|
|
}
|
2003-11-26 22:00:07 +00:00
|
|
|
}
|
|
|
|
|
2005-07-05 20:31:34 +00:00
|
|
|
filesize_reload_needed = 0;
|
2006-01-17 16:58:09 +00:00
|
|
|
|
2002-02-11 04:25:04 +00:00
|
|
|
init_logger_chain();
|
2005-03-11 08:49:01 +00:00
|
|
|
|
|
|
|
if (logfiles.event_log) {
|
2006-11-04 01:34:59 +00:00
|
|
|
snprintf(old, sizeof(old), "%s/%s", ast_config_AST_LOG_DIR, EVENTLOG);
|
2006-02-26 16:40:39 +00:00
|
|
|
if (event_rotate) {
|
2006-10-02 17:54:21 +00:00
|
|
|
if (!rotatetimestamp) {
|
|
|
|
for (x=0;;x++) {
|
2006-11-04 01:34:59 +00:00
|
|
|
snprintf(new, sizeof(new), "%s/%s.%d", ast_config_AST_LOG_DIR, EVENTLOG,x);
|
|
|
|
myf = fopen(new, "r");
|
2006-10-02 17:54:21 +00:00
|
|
|
if (myf) /* File exists */
|
|
|
|
fclose(myf);
|
|
|
|
else
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
} else
|
2006-11-04 01:34:59 +00:00
|
|
|
snprintf(new, sizeof(new), "%s/%s.%ld", ast_config_AST_LOG_DIR, EVENTLOG,(long)time(NULL));
|
2006-02-26 16:40:39 +00:00
|
|
|
|
|
|
|
/* do it */
|
|
|
|
if (rename(old,new))
|
|
|
|
ast_log(LOG_ERROR, "Unable to rename file '%s' to '%s'\n", old, new);
|
|
|
|
}
|
|
|
|
|
|
|
|
eventlog = fopen(old, "a");
|
2005-03-11 08:49:01 +00:00
|
|
|
if (eventlog) {
|
|
|
|
ast_log(LOG_EVENT, "Restarted Asterisk Event Logger\n");
|
|
|
|
if (option_verbose)
|
|
|
|
ast_verbose("Asterisk Event Logger restarted\n");
|
2006-02-26 16:40:39 +00:00
|
|
|
} else {
|
2005-03-11 08:49:01 +00:00
|
|
|
ast_log(LOG_ERROR, "Unable to create event log: %s\n", strerror(errno));
|
2006-02-26 16:40:39 +00:00
|
|
|
res = -1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (logfiles.queue_log) {
|
2006-11-04 01:34:59 +00:00
|
|
|
snprintf(old, sizeof(old), "%s/%s", ast_config_AST_LOG_DIR, queue_log_name);
|
2006-02-26 16:40:39 +00:00
|
|
|
if (queue_rotate) {
|
2006-10-02 17:54:21 +00:00
|
|
|
if (!rotatetimestamp) {
|
|
|
|
for (x = 0; ; x++) {
|
2006-11-04 01:34:59 +00:00
|
|
|
snprintf(new, sizeof(new), "%s/%s.%d", ast_config_AST_LOG_DIR, queue_log_name, x);
|
|
|
|
myf = fopen(new, "r");
|
2006-10-02 17:54:21 +00:00
|
|
|
if (myf) /* File exists */
|
|
|
|
fclose(myf);
|
|
|
|
else
|
|
|
|
break;
|
|
|
|
}
|
2006-02-26 16:40:39 +00:00
|
|
|
|
2006-10-02 17:54:21 +00:00
|
|
|
} else
|
2006-11-04 01:34:59 +00:00
|
|
|
snprintf(new, sizeof(new), "%s/%s.%ld", ast_config_AST_LOG_DIR, queue_log_name,(long)time(NULL));
|
2006-02-26 16:40:39 +00:00
|
|
|
/* do it */
|
|
|
|
if (rename(old, new))
|
|
|
|
ast_log(LOG_ERROR, "Unable to rename file '%s' to '%s'\n", old, new);
|
|
|
|
}
|
|
|
|
|
|
|
|
qlog = fopen(old, "a");
|
|
|
|
if (qlog) {
|
|
|
|
ast_queue_log("NONE", "NONE", "NONE", "CONFIGRELOAD", "%s", "");
|
|
|
|
ast_log(LOG_EVENT, "Restarted Asterisk Queue Logger\n");
|
|
|
|
if (option_verbose)
|
|
|
|
ast_verbose("Asterisk Queue Logger restarted\n");
|
|
|
|
} else {
|
|
|
|
ast_log(LOG_ERROR, "Unable to create queue log: %s\n", strerror(errno));
|
|
|
|
res = -1;
|
|
|
|
}
|
|
|
|
}
|
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-07-20 01:54:52 +00:00
|
|
|
AST_RWLIST_UNLOCK(&logchannels);
|
2006-02-26 16:40:39 +00:00
|
|
|
|
|
|
|
return res;
|
2002-02-11 04:25:04 +00:00
|
|
|
}
|
|
|
|
|
2003-10-02 06:40:10 +00:00
|
|
|
static int handle_logger_reload(int fd, int argc, char *argv[])
|
|
|
|
{
|
2007-01-23 00:11:32 +00:00
|
|
|
if (reload_logger(0)) {
|
2004-12-18 22:04:07 +00:00
|
|
|
ast_cli(fd, "Failed to reload the logger\n");
|
2003-11-26 22:00:07 +00:00
|
|
|
return RESULT_FAILURE;
|
2005-03-31 19:08:51 +00:00
|
|
|
} else
|
2003-11-26 22:00:07 +00:00
|
|
|
return RESULT_SUCCESS;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int handle_logger_rotate(int fd, int argc, char *argv[])
|
|
|
|
{
|
2007-01-23 00:11:32 +00:00
|
|
|
if (reload_logger(1)) {
|
2004-12-18 22:04:07 +00:00
|
|
|
ast_cli(fd, "Failed to reload the logger and rotate log files\n");
|
2003-10-02 06:40:10 +00:00
|
|
|
return RESULT_FAILURE;
|
2005-03-31 19:08:51 +00:00
|
|
|
} else
|
2003-10-02 06:40:10 +00:00
|
|
|
return RESULT_SUCCESS;
|
|
|
|
}
|
|
|
|
|
2006-01-20 00:18:42 +00:00
|
|
|
/*! \brief CLI command to show logging system configuration */
|
2005-03-31 19:08:51 +00:00
|
|
|
static int handle_logger_show_channels(int fd, int argc, char *argv[])
|
|
|
|
{
|
|
|
|
#define FORMATL "%-35.35s %-8.8s %-9.9s "
|
|
|
|
struct logchannel *chan;
|
|
|
|
|
|
|
|
ast_cli(fd,FORMATL, "Channel", "Type", "Status");
|
|
|
|
ast_cli(fd, "Configuration\n");
|
|
|
|
ast_cli(fd,FORMATL, "-------", "----", "------");
|
|
|
|
ast_cli(fd, "-------------\n");
|
2007-07-20 01:54:52 +00:00
|
|
|
AST_RWLIST_RDLOCK(&logchannels);
|
|
|
|
AST_RWLIST_TRAVERSE(&logchannels, chan, list) {
|
2005-03-31 19:08:51 +00:00
|
|
|
ast_cli(fd, FORMATL, chan->filename, chan->type==LOGTYPE_CONSOLE ? "Console" : (chan->type==LOGTYPE_SYSLOG ? "Syslog" : "File"),
|
|
|
|
chan->disabled ? "Disabled" : "Enabled");
|
|
|
|
ast_cli(fd, " - ");
|
|
|
|
if (chan->logmask & (1 << __LOG_DEBUG))
|
|
|
|
ast_cli(fd, "Debug ");
|
2005-08-22 21:19:59 +00:00
|
|
|
if (chan->logmask & (1 << __LOG_DTMF))
|
|
|
|
ast_cli(fd, "DTMF ");
|
2005-03-31 19:08:51 +00:00
|
|
|
if (chan->logmask & (1 << __LOG_VERBOSE))
|
|
|
|
ast_cli(fd, "Verbose ");
|
|
|
|
if (chan->logmask & (1 << __LOG_WARNING))
|
|
|
|
ast_cli(fd, "Warning ");
|
|
|
|
if (chan->logmask & (1 << __LOG_NOTICE))
|
|
|
|
ast_cli(fd, "Notice ");
|
|
|
|
if (chan->logmask & (1 << __LOG_ERROR))
|
|
|
|
ast_cli(fd, "Error ");
|
|
|
|
if (chan->logmask & (1 << __LOG_EVENT))
|
|
|
|
ast_cli(fd, "Event ");
|
|
|
|
ast_cli(fd, "\n");
|
|
|
|
}
|
2007-07-20 01:54:52 +00:00
|
|
|
AST_RWLIST_UNLOCK(&logchannels);
|
2005-03-31 19:08:51 +00:00
|
|
|
ast_cli(fd, "\n");
|
|
|
|
|
|
|
|
return RESULT_SUCCESS;
|
|
|
|
}
|
|
|
|
|
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
|
|
|
|
|
|
|
static char logger_reload_help[] =
|
|
|
|
"Usage: logger reload\n"
|
2005-03-31 19:08:51 +00:00
|
|
|
" Reloads the logger subsystem state. Use after restarting syslogd(8) if you are using syslog logging.\n";
|
2003-11-26 22:00:07 +00:00
|
|
|
|
|
|
|
static char logger_rotate_help[] =
|
2004-04-22 02:57:10 +00:00
|
|
|
"Usage: logger rotate\n"
|
2003-11-26 22:00:07 +00:00
|
|
|
" Rotates and Reopens the log files.\n";
|
|
|
|
|
2005-03-31 19:08:51 +00:00
|
|
|
static char logger_show_channels_help[] =
|
2006-11-02 23:16:09 +00:00
|
|
|
"Usage: logger show channels\n"
|
2006-09-18 19:54:18 +00:00
|
|
|
" List configured logger channels.\n";
|
2005-03-31 19:08:51 +00:00
|
|
|
|
2006-09-18 19:54:18 +00:00
|
|
|
static struct ast_cli_entry cli_logger[] = {
|
2006-11-02 23:16:09 +00:00
|
|
|
{ { "logger", "show", "channels", NULL },
|
2005-03-31 19:08:51 +00:00
|
|
|
handle_logger_show_channels, "List configured log channels",
|
2006-09-21 21:17:39 +00:00
|
|
|
logger_show_channels_help },
|
2005-03-31 19:08:51 +00:00
|
|
|
|
2003-10-02 06:40:10 +00:00
|
|
|
{ { "logger", "reload", NULL },
|
|
|
|
handle_logger_reload, "Reopens the log files",
|
2006-09-18 19:54:18 +00:00
|
|
|
logger_reload_help },
|
2003-10-02 06:40:10 +00:00
|
|
|
|
2003-11-26 22:00:07 +00:00
|
|
|
{ { "logger", "rotate", NULL },
|
2004-01-26 05:32:30 +00:00
|
|
|
handle_logger_rotate, "Rotates and reopens the log files",
|
2006-09-18 19:54:18 +00:00
|
|
|
logger_rotate_help },
|
|
|
|
};
|
2003-11-26 22:00:07 +00:00
|
|
|
|
2004-06-29 04:42:19 +00:00
|
|
|
static int handle_SIGXFSZ(int sig)
|
|
|
|
{
|
2004-03-30 16:16:05 +00:00
|
|
|
/* Indicate need to reload */
|
2005-07-05 20:31:34 +00:00
|
|
|
filesize_reload_needed = 1;
|
2004-06-29 04:42:19 +00:00
|
|
|
return 0;
|
2003-11-26 22:00:07 +00:00
|
|
|
}
|
|
|
|
|
2006-12-21 21:57:16 +00:00
|
|
|
static void ast_log_vsyslog(int level, const char *file, int line, const char *function, char *str)
|
|
|
|
{
|
|
|
|
char buf[BUFSIZ];
|
|
|
|
|
|
|
|
if (level >= SYSLOG_NLEVELS) {
|
|
|
|
/* we are locked here, so cannot ast_log() */
|
|
|
|
fprintf(stderr, "ast_log_vsyslog called with bogus level: %d\n", level);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (level == __LOG_VERBOSE) {
|
|
|
|
snprintf(buf, sizeof(buf), "VERBOSE[%ld]: %s", (long)GETTID(), str);
|
|
|
|
level = __LOG_DEBUG;
|
|
|
|
} else if (level == __LOG_DTMF) {
|
|
|
|
snprintf(buf, sizeof(buf), "DTMF[%ld]: %s", (long)GETTID(), str);
|
|
|
|
level = __LOG_DEBUG;
|
|
|
|
} else {
|
|
|
|
snprintf(buf, sizeof(buf), "%s[%ld]: %s:%d in %s: %s",
|
|
|
|
levels[level], (long)GETTID(), file, line, function, str);
|
|
|
|
}
|
|
|
|
|
|
|
|
term_strip(buf, buf, strlen(buf) + 1);
|
|
|
|
syslog(syslog_level_map[level], "%s", buf);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Print a normal log message to the channels */
|
|
|
|
static void logger_print_normal(struct logmsg *logmsg)
|
|
|
|
{
|
|
|
|
struct logchannel *chan = NULL;
|
|
|
|
char buf[BUFSIZ];
|
|
|
|
|
2007-07-20 01:54:52 +00:00
|
|
|
AST_RWLIST_RDLOCK(&logchannels);
|
2006-12-21 21:57:16 +00:00
|
|
|
|
|
|
|
if (logfiles.event_log && logmsg->level == __LOG_EVENT) {
|
|
|
|
fprintf(eventlog, "%s asterisk[%ld]: %s", logmsg->date, (long)getpid(), logmsg->str);
|
|
|
|
fflush(eventlog);
|
2007-07-20 01:54:52 +00:00
|
|
|
AST_RWLIST_UNLOCK(&logchannels);
|
2006-12-21 21:57:16 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2007-07-20 01:54:52 +00:00
|
|
|
if (!AST_RWLIST_EMPTY(&logchannels)) {
|
|
|
|
AST_RWLIST_TRAVERSE(&logchannels, chan, list) {
|
2006-12-21 21:57:16 +00:00
|
|
|
/* If the channel is disabled, then move on to the next one */
|
|
|
|
if (chan->disabled)
|
|
|
|
continue;
|
|
|
|
/* Check syslog channels */
|
|
|
|
if (chan->type == LOGTYPE_SYSLOG && (chan->logmask & (1 << logmsg->level))) {
|
|
|
|
ast_log_vsyslog(logmsg->level, logmsg->file, logmsg->line, logmsg->function, logmsg->str);
|
|
|
|
/* Console channels */
|
|
|
|
} else if (chan->type == LOGTYPE_CONSOLE && (chan->logmask & (1 << logmsg->level))) {
|
|
|
|
char linestr[128];
|
|
|
|
char tmp1[80], tmp2[80], tmp3[80], tmp4[80];
|
|
|
|
|
|
|
|
/* 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 */
|
|
|
|
snprintf(buf, sizeof(buf), "[%s] %s[%ld]: %s:%s %s: %s",
|
|
|
|
logmsg->date,
|
|
|
|
term_color(tmp1, levels[logmsg->level], colors[logmsg->level], 0, sizeof(tmp1)),
|
|
|
|
(long)GETTID(),
|
|
|
|
term_color(tmp2, logmsg->file, COLOR_BRWHITE, 0, sizeof(tmp2)),
|
|
|
|
term_color(tmp3, linestr, COLOR_BRWHITE, 0, sizeof(tmp3)),
|
|
|
|
term_color(tmp4, logmsg->function, COLOR_BRWHITE, 0, sizeof(tmp4)),
|
|
|
|
logmsg->str);
|
|
|
|
/* Print out */
|
|
|
|
ast_console_puts_mutable(buf);
|
|
|
|
/* File channels */
|
|
|
|
} else if (chan->type == LOGTYPE_FILE && (chan->logmask & (1 << logmsg->level))) {
|
|
|
|
int res = 0;
|
|
|
|
|
|
|
|
/* If no file pointer exists, skip it */
|
|
|
|
if (!chan->fileptr)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
/* Print out to the file */
|
|
|
|
res = fprintf(chan->fileptr, "[%s] %s[%ld] %s: %s",
|
|
|
|
logmsg->date, levels[logmsg->level], (long)GETTID(), logmsg->file, logmsg->str);
|
|
|
|
if (res <= 0 && !ast_strlen_zero(logmsg->str)) {
|
|
|
|
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));
|
|
|
|
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) {
|
|
|
|
fputs(logmsg->str, stdout);
|
|
|
|
}
|
|
|
|
|
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) {
|
|
|
|
reload_logger(1);
|
|
|
|
ast_log(LOG_EVENT, "Rotated Logs Per SIGXFSZ (Exceeded file size limit)\n");
|
|
|
|
if (option_verbose)
|
|
|
|
ast_verbose("Rotated Logs Per SIGXFSZ (Exceeded file size limit)\n");
|
|
|
|
}
|
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Print a verbose message to the verbosers */
|
|
|
|
static void logger_print_verbose(struct logmsg *logmsg)
|
|
|
|
{
|
|
|
|
struct verb *v = NULL;
|
|
|
|
|
|
|
|
/* Iterate through the list of verbosers and pass them the log message string */
|
2007-07-20 01:54:52 +00:00
|
|
|
AST_RWLIST_RDLOCK(&verbosers);
|
|
|
|
AST_RWLIST_TRAVERSE(&verbosers, v, list)
|
2006-12-21 21:57:16 +00:00
|
|
|
v->verboser(logmsg->str);
|
2007-07-20 01:54:52 +00:00
|
|
|
AST_RWLIST_UNLOCK(&verbosers);
|
2006-12-21 21:57:16 +00:00
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Actual logging thread */
|
|
|
|
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);
|
|
|
|
if (AST_LIST_EMPTY(&logmsgs))
|
|
|
|
ast_cond_wait(&logcond, &logmsgs.lock);
|
|
|
|
next = AST_LIST_FIRST(&logmsgs);
|
|
|
|
AST_LIST_HEAD_INIT_NOLOCK(&logmsgs);
|
|
|
|
AST_LIST_UNLOCK(&logmsgs);
|
|
|
|
|
|
|
|
/* If we should stop, then stop */
|
|
|
|
if (close_logger_thread)
|
|
|
|
break;
|
|
|
|
|
|
|
|
/* 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 */
|
|
|
|
if (msg->type == LOGMSG_NORMAL)
|
|
|
|
logger_print_normal(msg);
|
|
|
|
else if (msg->type == LOGMSG_VERBOSE)
|
|
|
|
logger_print_verbose(msg);
|
|
|
|
|
|
|
|
/* Free the data since we are done */
|
|
|
|
free(msg);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2003-10-02 06:40:10 +00:00
|
|
|
int init_logger(void)
|
2002-02-11 04:25:04 +00:00
|
|
|
{
|
2004-01-12 05:05:35 +00:00
|
|
|
char tmp[256];
|
2006-02-26 16:40:39 +00:00
|
|
|
int res = 0;
|
2003-11-26 22:00:07 +00:00
|
|
|
|
|
|
|
/* auto rotate if sig SIGXFSZ comes a-knockin */
|
|
|
|
(void) signal(SIGXFSZ,(void *) handle_SIGXFSZ);
|
|
|
|
|
2006-12-21 21:57:16 +00:00
|
|
|
/* start logger thread */
|
|
|
|
ast_cond_init(&logcond, NULL);
|
|
|
|
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 */
|
|
|
|
ast_cli_register_multiple(cli_logger, sizeof(cli_logger) / sizeof(struct ast_cli_entry));
|
2004-01-12 05:05:35 +00:00
|
|
|
|
2007-06-22 04:35:12 +00:00
|
|
|
ast_mkdir(ast_config_AST_LOG_DIR, 0777);
|
2006-02-26 16:40:39 +00:00
|
|
|
|
2004-01-12 05:05:35 +00:00
|
|
|
/* create log channels */
|
2002-02-11 04:25:04 +00:00
|
|
|
init_logger_chain();
|
2005-03-11 08:49:01 +00:00
|
|
|
|
|
|
|
/* create the eventlog */
|
|
|
|
if (logfiles.event_log) {
|
2006-11-04 01:34:59 +00:00
|
|
|
snprintf(tmp, sizeof(tmp), "%s/%s", ast_config_AST_LOG_DIR, EVENTLOG);
|
|
|
|
eventlog = fopen(tmp, "a");
|
2005-03-11 08:49:01 +00:00
|
|
|
if (eventlog) {
|
|
|
|
ast_log(LOG_EVENT, "Started Asterisk Event Logger\n");
|
|
|
|
if (option_verbose)
|
2006-11-04 01:34:59 +00:00
|
|
|
ast_verbose("Asterisk Event Logger Started %s\n", tmp);
|
2006-02-26 16:40:39 +00:00
|
|
|
} else {
|
2005-03-11 08:49:01 +00:00
|
|
|
ast_log(LOG_ERROR, "Unable to create event log: %s\n", strerror(errno));
|
2006-02-26 16:40:39 +00:00
|
|
|
res = -1;
|
|
|
|
}
|
|
|
|
}
|
2005-03-11 08:49:01 +00:00
|
|
|
|
2006-02-26 16:40:39 +00:00
|
|
|
if (logfiles.queue_log) {
|
2006-11-04 01:34:59 +00:00
|
|
|
snprintf(tmp, sizeof(tmp), "%s/%s", ast_config_AST_LOG_DIR, queue_log_name);
|
2006-02-26 16:40:39 +00:00
|
|
|
qlog = fopen(tmp, "a");
|
|
|
|
ast_queue_log("NONE", "NONE", "NONE", "QUEUESTART", "%s", "");
|
|
|
|
}
|
|
|
|
return res;
|
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;
|
|
|
|
|
|
|
|
/* 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-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 (eventlog) {
|
|
|
|
fclose(eventlog);
|
|
|
|
eventlog = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (qlog) {
|
|
|
|
fclose(qlog);
|
|
|
|
qlog = NULL;
|
|
|
|
}
|
|
|
|
|
2007-07-20 01:54:52 +00:00
|
|
|
AST_RWLIST_TRAVERSE(&logchannels, f, 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
|
|
|
}
|
|
|
|
}
|
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);
|
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
|
|
|
|
2004-06-17 01:13:10 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
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
|
|
|
*/
|
|
|
|
void ast_log(int level, const char *file, int line, const char *function, const char *fmt, ...)
|
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;
|
|
|
|
struct timeval tv = ast_tvnow();
|
2006-12-21 21:57:16 +00:00
|
|
|
int res = 0;
|
2004-06-29 04:42:19 +00:00
|
|
|
va_list ap;
|
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;
|
|
|
|
|
2007-07-20 01:54:52 +00:00
|
|
|
if (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
|
|
|
*/
|
2006-09-07 03:35:42 +00:00
|
|
|
if (level != __LOG_VERBOSE) {
|
|
|
|
int res;
|
|
|
|
va_start(ap, fmt);
|
2006-12-15 23:10:42 +00:00
|
|
|
res = ast_str_set_va(&buf, BUFSIZ, fmt, ap); /* XXX BUFSIZ ? */
|
2006-09-07 03:35:42 +00:00
|
|
|
va_end(ap);
|
2006-11-11 02:12:27 +00:00
|
|
|
if (res != AST_DYNSTR_BUILD_FAILED) {
|
|
|
|
term_filter_escapes(buf->str);
|
2006-09-07 03:35:42 +00:00
|
|
|
fputs(buf->str, stdout);
|
2006-11-11 02:12:27 +00:00
|
|
|
}
|
2006-09-07 03:35:42 +00:00
|
|
|
}
|
|
|
|
return;
|
|
|
|
}
|
2006-12-21 21:57:16 +00:00
|
|
|
|
2005-05-20 13:58:39 +00:00
|
|
|
/* don't display LOG_DEBUG messages unless option_verbose _or_ option_debug
|
|
|
|
are non-zero; LOG_DEBUG messages can still be displayed if option_debug
|
|
|
|
is zero, if option_verbose is non-zero (this allows for 'level zero'
|
|
|
|
LOG_DEBUG messages to be displayed, if the logmask on any channel
|
|
|
|
allows it)
|
|
|
|
*/
|
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 (!option_verbose && !option_debug && (level == __LOG_DEBUG))
|
2004-06-29 04:42:19 +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 */
|
|
|
|
if (!(global_logmask & (1 << level)))
|
|
|
|
return;
|
2005-03-05 04:04:55 +00:00
|
|
|
|
2006-12-21 21:57:16 +00:00
|
|
|
/* Build string */
|
|
|
|
va_start(ap, fmt);
|
|
|
|
res = ast_str_set_va(&buf, BUFSIZ, fmt, ap);
|
|
|
|
va_end(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 */
|
|
|
|
if (!(logmsg = ast_calloc(1, sizeof(*logmsg) + res + 1)))
|
2004-06-29 04:42:19 +00:00
|
|
|
return;
|
2006-12-21 21:57:16 +00:00
|
|
|
|
|
|
|
/* Copy string over */
|
|
|
|
strcpy(logmsg->str, buf->str);
|
2004-06-29 04:42:19 +00:00
|
|
|
|
2006-12-21 21:57:16 +00:00
|
|
|
/* Set type to be normal */
|
|
|
|
logmsg->type = LOGMSG_NORMAL;
|
2004-01-12 05:05:35 +00:00
|
|
|
|
2006-12-21 21:57:16 +00:00
|
|
|
/* Create our date/time */
|
2007-07-18 19:47:20 +00:00
|
|
|
ast_localtime(&tv, &tm, NULL);
|
|
|
|
ast_strftime(logmsg->date, sizeof(logmsg->date), dateformat, &tm);
|
2006-12-21 21:57:16 +00:00
|
|
|
|
|
|
|
/* Copy over data */
|
|
|
|
logmsg->level = level;
|
|
|
|
logmsg->file = file;
|
|
|
|
logmsg->line = line;
|
|
|
|
logmsg->function = function;
|
|
|
|
|
|
|
|
/* 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);
|
|
|
|
AST_LIST_INSERT_TAIL(&logmsgs, logmsg, list);
|
|
|
|
ast_cond_signal(&logcond);
|
|
|
|
AST_LIST_UNLOCK(&logmsgs);
|
|
|
|
} else {
|
|
|
|
logger_print_normal(logmsg);
|
|
|
|
free(logmsg);
|
2004-03-30 16:16:05 +00:00
|
|
|
}
|
2006-12-21 21:57:16 +00:00
|
|
|
|
|
|
|
return;
|
1999-12-05 07:28:29 +00:00
|
|
|
}
|
|
|
|
|
2005-12-27 06:24:28 +00:00
|
|
|
void ast_backtrace(void)
|
|
|
|
{
|
2007-07-26 19:29:12 +00:00
|
|
|
#ifdef linux
|
2007-03-20 21:06:11 +00:00
|
|
|
#ifdef AST_DEVMODE
|
2005-12-27 06:24:28 +00:00
|
|
|
int count=0, i=0;
|
|
|
|
void **addresses;
|
|
|
|
char **strings;
|
|
|
|
|
2006-02-27 01:43:42 +00:00
|
|
|
if ((addresses = ast_calloc(MAX_BACKTRACE_FRAMES, sizeof(*addresses)))) {
|
2006-02-22 21:53:56 +00:00
|
|
|
count = backtrace(addresses, MAX_BACKTRACE_FRAMES);
|
2006-02-27 01:43:42 +00:00
|
|
|
if ((strings = backtrace_symbols(addresses, count))) {
|
2007-06-24 18:51:41 +00:00
|
|
|
ast_debug(1, "Got %d backtrace record%c\n", count, count != 1 ? 's' : ' ');
|
2005-12-27 06:24:28 +00:00
|
|
|
for (i=0; i < count ; i++) {
|
2007-07-26 20:39:46 +00:00
|
|
|
#if __WORDSIZE == 32
|
|
|
|
ast_log(LOG_DEBUG, "#%d: [%08X] %s\n", i, (unsigned int)addresses[i], strings[i]);
|
|
|
|
#elif __WORDSIZE == 64
|
|
|
|
ast_log(LOG_DEBUG, "#%d: [%016lX] %s\n", i, (unsigned long)addresses[i], strings[i]);
|
|
|
|
#endif
|
2005-12-27 06:24:28 +00:00
|
|
|
}
|
|
|
|
free(strings);
|
|
|
|
} else {
|
2007-06-24 18:51:41 +00:00
|
|
|
ast_debug(1, "Could not allocate memory for backtrace\n");
|
2005-12-27 06:24:28 +00:00
|
|
|
}
|
|
|
|
free(addresses);
|
|
|
|
}
|
|
|
|
#else
|
2007-03-20 21:06:11 +00:00
|
|
|
ast_log(LOG_WARNING, "Must run configure with '--enable-dev-mode' for stack backtraces.\n");
|
2005-12-27 06:24:28 +00:00
|
|
|
#endif
|
2007-07-26 19:29:12 +00:00
|
|
|
#else /* ndef linux */
|
2007-03-20 21:06:11 +00:00
|
|
|
ast_log(LOG_WARNING, "Inline stack backtraces are only available on the Linux platform.\n");
|
2005-12-27 06:24:28 +00:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2005-09-14 23:56:50 +00:00
|
|
|
void ast_verbose(const char *fmt, ...)
|
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;
|
|
|
|
int res = 0;
|
1999-12-05 07:28:29 +00:00
|
|
|
va_list ap;
|
2005-03-11 07:24:10 +00:00
|
|
|
|
2006-12-21 21:57:16 +00:00
|
|
|
if (!(buf = ast_str_thread_get(&verbose_buf, VERBOSE_BUF_INIT_SIZE)))
|
|
|
|
return;
|
|
|
|
|
2007-06-27 19:57:36 +00:00
|
|
|
if (ast_opt_timestamp) {
|
2007-07-18 19:47:20 +00:00
|
|
|
struct timeval tv;
|
|
|
|
struct ast_tm tm;
|
2007-06-27 19:57:36 +00:00
|
|
|
char date[40];
|
|
|
|
char *datefmt;
|
|
|
|
|
2007-07-18 19:47:20 +00:00
|
|
|
tv = ast_tvnow();
|
|
|
|
ast_localtime(&tv, &tm, NULL);
|
|
|
|
ast_strftime(date, sizeof(date), dateformat, &tm);
|
2007-06-27 19:57:36 +00:00
|
|
|
datefmt = alloca(strlen(date) + 3 + strlen(fmt) + 1);
|
|
|
|
sprintf(datefmt, "[%s] %s", date, fmt);
|
|
|
|
fmt = datefmt;
|
|
|
|
}
|
|
|
|
|
2006-12-21 21:57:16 +00:00
|
|
|
/* Build string */
|
|
|
|
va_start(ap, fmt);
|
|
|
|
res = ast_str_set_va(&buf, 0, fmt, ap);
|
|
|
|
va_end(ap);
|
|
|
|
|
|
|
|
/* If the build failed then we can drop this allocated message */
|
|
|
|
if (res == AST_DYNSTR_BUILD_FAILED)
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (!(logmsg = ast_calloc(1, sizeof(*logmsg) + res + 1)))
|
|
|
|
return;
|
|
|
|
|
|
|
|
strcpy(logmsg->str, buf->str);
|
|
|
|
|
2007-04-11 17:07:17 +00:00
|
|
|
ast_log(LOG_VERBOSE, logmsg->str);
|
|
|
|
|
2006-12-21 21:57:16 +00:00
|
|
|
/* Set type */
|
|
|
|
logmsg->type = LOGMSG_VERBOSE;
|
|
|
|
|
|
|
|
/* Add to the list and poke the thread if possible */
|
|
|
|
if (logthread != AST_PTHREADT_NULL) {
|
|
|
|
AST_LIST_LOCK(&logmsgs);
|
|
|
|
AST_LIST_INSERT_TAIL(&logmsgs, logmsg, list);
|
|
|
|
ast_cond_signal(&logcond);
|
|
|
|
AST_LIST_UNLOCK(&logmsgs);
|
|
|
|
} else {
|
|
|
|
logger_print_verbose(logmsg);
|
|
|
|
free(logmsg);
|
|
|
|
}
|
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
|
|
|
|
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_register_verbose(void (*v)(const char *string))
|
|
|
|
{
|
|
|
|
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);
|
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
|
|
|
|
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-07-20 01:54:52 +00:00
|
|
|
AST_RWLIST_REMOVE_CURRENT(&verbosers, 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
|
|
|
free(cur);
|
1999-12-05 07:28:29 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2007-07-20 01:54:52 +00:00
|
|
|
AST_RWLIST_TRAVERSE_SAFE_END
|
|
|
|
AST_RWLIST_UNLOCK(&verbosers);
|
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
|
|
|
}
|