1999-10-27 00:56:38 +00:00
|
|
|
/*
|
2005-08-30 18:32:10 +00:00
|
|
|
* Asterisk -- An open source telephony toolkit.
|
|
|
|
|
*
|
|
|
|
|
* Copyright (C) 1999 - 2005, Digium, Inc.
|
1999-10-27 00:56:38 +00:00
|
|
|
*
|
2005-08-30 18:32:10 +00:00
|
|
|
* Mark Spencer <markster@digium.com>
|
1999-10-27 00:56:38 +00:00
|
|
|
*
|
2005-08-30 18:32:10 +00:00
|
|
|
* 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-10-27 00:56:38 +00:00
|
|
|
*
|
2005-08-30 18:32:10 +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.
|
1999-10-27 00:56:38 +00:00
|
|
|
*/
|
2005-08-30 18:32:10 +00:00
|
|
|
|
2005-08-25 23:21:01 +00:00
|
|
|
/*!
|
2021-11-12 19:41:09 +01:00
|
|
|
* \file
|
|
|
|
|
*
|
|
|
|
|
* \brief Support for logging to various files, console and syslog
|
|
|
|
|
* Configuration in file logger.conf
|
|
|
|
|
*/
|
1999-10-27 00:56:38 +00:00
|
|
|
|
2005-08-30 18:32:10 +00:00
|
|
|
#ifndef _ASTERISK_LOGGER_H
|
|
|
|
|
#define _ASTERISK_LOGGER_H
|
|
|
|
|
|
2007-11-19 14:36:12 +00:00
|
|
|
#include "asterisk/options.h" /* need option_debug */
|
|
|
|
|
|
1999-10-27 00:56:38 +00:00
|
|
|
#if defined(__cplusplus) || defined(c_plusplus)
|
|
|
|
|
extern "C" {
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
#define EVENTLOG "event_log"
|
2006-02-26 16:40:39 +00:00
|
|
|
#define QUEUELOG "queue_log"
|
1999-10-27 00:56:38 +00:00
|
|
|
|
|
|
|
|
#define DEBUG_M(a) { \
|
|
|
|
|
a; \
|
|
|
|
|
}
|
|
|
|
|
|
2021-10-28 09:28:57 +02:00
|
|
|
#define _A_ __FILE__, __LINE__, __FUNCTION__
|
|
|
|
|
|
2005-12-04 20:40:46 +00:00
|
|
|
#define VERBOSE_PREFIX_1 " "
|
|
|
|
|
#define VERBOSE_PREFIX_2 " == "
|
|
|
|
|
#define VERBOSE_PREFIX_3 " -- "
|
2006-03-31 10:35:25 +00:00
|
|
|
#define VERBOSE_PREFIX_4 " > "
|
2005-12-04 20:40:46 +00:00
|
|
|
|
2012-06-26 21:45:22 +00:00
|
|
|
#define AST_CALLID_BUFFER_LENGTH 13
|
|
|
|
|
|
2015-08-06 15:18:04 -05:00
|
|
|
enum ast_logger_results {
|
|
|
|
|
AST_LOGGER_SUCCESS = 0, /*!< Log channel was created or deleted successfully*/
|
|
|
|
|
AST_LOGGER_FAILURE = 1, /*!< Log channel already exists for create or doesn't exist for deletion of log channel */
|
|
|
|
|
AST_LOGGER_DECLINE = -1, /*!< Log channel request was not accepted */
|
|
|
|
|
AST_LOGGER_ALLOC_ERROR = -2 /*!< filename allocation error */
|
|
|
|
|
};
|
|
|
|
|
|
2009-03-09 20:58:17 +00:00
|
|
|
/*! \brief Used for sending a log message
|
2007-12-11 14:17:29 +00:00
|
|
|
This is the standard logger function. Probably the only way you will invoke it would be something like this:
|
Round 2 of IMAP_STORAGE app_voicemail.c fixes:
This fixes a bug that was thought to be fixed already.
app_voicemail, if using IMAP_STORAGE, has a problem because
the IMAP header files include syslog.h, which define LOG_WARNING
and LOG_DEBUG to be different than what Asterisk uses for those
same macros. This was "fixed" in the past by including all the
IMAP header files prior to including asterisk.h. This fix worked...
unless you were to try to compile with MALLOC_DEBUG. MALLOC_DEBUG
prepends the inclusion of astmm.h to every file, which means that no
matter what order the includes are in in app_voicemail, the unexpected
values for LOG_WARNING and LOG_DEBUG will be in place.
The action taken for this fix was to define AST_LOG_* macros in addition
to the LOG_* macros already defined. These new macros are used in app_voicemail.c,
logger.h, and astobj.h right now, and their use will be encouraged in the future.
In consideration of those who have written third-party modules which use
the LOG_* macros, these will NOT be removed from the source, however future use
of these macros is discouraged.
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@114577 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2008-04-23 00:58:49 +00:00
|
|
|
ast_log(AST_LOG_WHATEVER, "Problem with the %s Captain. We should get some more. Will %d be enough?\n", "flux capacitor", 10);
|
2005-08-25 23:21:01 +00:00
|
|
|
where WHATEVER is one of ERROR, DEBUG, EVENT, NOTICE, or WARNING depending
|
|
|
|
|
on which log you wish to output to. These are implemented as macros, that
|
|
|
|
|
will provide the function with the needed arguments.
|
|
|
|
|
|
|
|
|
|
\param level Type of log event
|
Round 2 of IMAP_STORAGE app_voicemail.c fixes:
This fixes a bug that was thought to be fixed already.
app_voicemail, if using IMAP_STORAGE, has a problem because
the IMAP header files include syslog.h, which define LOG_WARNING
and LOG_DEBUG to be different than what Asterisk uses for those
same macros. This was "fixed" in the past by including all the
IMAP header files prior to including asterisk.h. This fix worked...
unless you were to try to compile with MALLOC_DEBUG. MALLOC_DEBUG
prepends the inclusion of astmm.h to every file, which means that no
matter what order the includes are in in app_voicemail, the unexpected
values for LOG_WARNING and LOG_DEBUG will be in place.
The action taken for this fix was to define AST_LOG_* macros in addition
to the LOG_* macros already defined. These new macros are used in app_voicemail.c,
logger.h, and astobj.h right now, and their use will be encouraged in the future.
In consideration of those who have written third-party modules which use
the LOG_* macros, these will NOT be removed from the source, however future use
of these macros is discouraged.
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@114577 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2008-04-23 00:58:49 +00:00
|
|
|
\param file Will be provided by the AST_LOG_* macro
|
|
|
|
|
\param line Will be provided by the AST_LOG_* macro
|
|
|
|
|
\param function Will be provided by the AST_LOG_* macro
|
2005-08-25 23:21:01 +00:00
|
|
|
\param fmt This is what is important. The format is the same as your favorite breed of printf. You know how that works, right? :-)
|
2001-11-01 14:03:04 +00:00
|
|
|
*/
|
2007-07-23 14:21:41 +00:00
|
|
|
|
2006-03-31 10:35:25 +00:00
|
|
|
void ast_log(int level, const char *file, int line, const char *function, const char *fmt, ...)
|
2008-11-29 17:57:39 +00:00
|
|
|
__attribute__((format(printf, 5, 6)));
|
2001-11-01 14:03:04 +00:00
|
|
|
|
2018-09-28 11:13:39 -04:00
|
|
|
void ast_log_ap(int level, const char *file, int line, const char *function, const char *fmt, va_list ap)
|
|
|
|
|
__attribute__((format(printf, 5, 0)));
|
|
|
|
|
|
2015-03-27 07:12:25 +00:00
|
|
|
/*!
|
|
|
|
|
* \brief Used for sending a log message with protection against recursion.
|
|
|
|
|
*
|
|
|
|
|
* \note This function should be used by all error messages that might be directly
|
|
|
|
|
* or indirectly caused by logging.
|
|
|
|
|
*
|
|
|
|
|
* \see ast_log for documentation on the parameters.
|
|
|
|
|
*/
|
|
|
|
|
void ast_log_safe(int level, const char *file, int line, const char *function, const char *fmt, ...)
|
|
|
|
|
__attribute__((format(printf, 5, 6)));
|
|
|
|
|
|
2012-03-29 20:01:20 +00:00
|
|
|
/* XXX needs documentation */
|
2015-03-13 01:12:35 +00:00
|
|
|
typedef unsigned int ast_callid;
|
2012-03-29 20:01:20 +00:00
|
|
|
|
|
|
|
|
/*! \brief Used for sending a log message with a known call_id
|
|
|
|
|
This is a modified logger function which is functionally identical to the above logger function,
|
|
|
|
|
it just include a call_id argument as well. If NULL is specified here, no attempt will be made to
|
|
|
|
|
join the log message with a call_id.
|
|
|
|
|
|
|
|
|
|
\param level Type of log event
|
|
|
|
|
\param file Will be provided by the AST_LOG_* macro
|
|
|
|
|
\param line Will be provided by the AST_LOG_* macro
|
|
|
|
|
\param function Will be provided by the AST_LOG_* macro
|
|
|
|
|
\param callid This is the ast_callid that is associated with the log message. May be NULL.
|
|
|
|
|
\param fmt This is what is important. The format is the same as your favorite breed of printf. You know how that works, right? :-)
|
|
|
|
|
*/
|
2015-03-13 01:12:35 +00:00
|
|
|
void ast_log_callid(int level, const char *file, int line, const char *function, ast_callid callid, const char *fmt, ...)
|
2012-03-29 20:01:20 +00:00
|
|
|
__attribute__((format(printf, 6, 7)));
|
|
|
|
|
|
2015-08-07 14:20:29 -05:00
|
|
|
/*!
|
|
|
|
|
* \brief Retrieve the existing log channels
|
|
|
|
|
* \param logentry A callback to an updater function
|
|
|
|
|
* \param data Data passed into the callback for manipulation
|
|
|
|
|
*
|
|
|
|
|
* For each of the logging channels, logentry will be executed with the
|
|
|
|
|
* channel file name, log type, status of the log, and configuration levels.
|
|
|
|
|
*
|
|
|
|
|
* \retval 0 on success
|
|
|
|
|
* \retval 1 on failure
|
|
|
|
|
* \retval -2 on allocation error
|
|
|
|
|
*/
|
|
|
|
|
int ast_logger_get_channels(int (*logentry)(const char *channel, const char *type,
|
|
|
|
|
const char *status, const char *configuration, void *data), void *data);
|
|
|
|
|
|
2015-08-07 11:14:06 -05:00
|
|
|
/*!
|
|
|
|
|
* \brief Create a log channel
|
|
|
|
|
*
|
|
|
|
|
* \param log_channel Log channel to create
|
|
|
|
|
* \param components Logging config levels to add to the log channel
|
|
|
|
|
*/
|
|
|
|
|
int ast_logger_create_channel(const char *log_channel, const char *components);
|
|
|
|
|
|
2015-08-06 15:18:04 -05:00
|
|
|
/*!
|
|
|
|
|
* \brief Delete the specified log channel
|
|
|
|
|
*
|
|
|
|
|
* \param log_channel The log channel to delete
|
|
|
|
|
*/
|
|
|
|
|
int ast_logger_remove_channel(const char *log_channel);
|
|
|
|
|
|
2013-06-08 22:09:07 +00:00
|
|
|
/*!
|
|
|
|
|
* \brief Log a backtrace of the current thread's execution stack to the Asterisk log
|
|
|
|
|
*/
|
|
|
|
|
void ast_log_backtrace(void);
|
2005-12-27 06:24:28 +00:00
|
|
|
|
2014-06-20 20:29:45 +00:00
|
|
|
/*! \brief Reload logger while rotating log files */
|
|
|
|
|
int ast_logger_rotate(void);
|
|
|
|
|
|
2015-07-29 14:17:09 -05:00
|
|
|
/*!
|
|
|
|
|
* \brief Rotate the specified log channel.
|
|
|
|
|
*
|
|
|
|
|
* \param log_channel The log channel to rotate
|
|
|
|
|
*/
|
|
|
|
|
int ast_logger_rotate_channel(const char *log_channel);
|
|
|
|
|
|
2008-11-29 17:57:39 +00:00
|
|
|
void __attribute__((format(printf, 5, 6))) ast_queue_log(const char *queuename, const char *callid, const char *agent, const char *event, const char *fmt, ...);
|
2004-02-12 22:11:02 +00:00
|
|
|
|
2014-01-14 18:14:02 +00:00
|
|
|
/*!
|
|
|
|
|
* \brief Send a verbose message (based on verbose level)
|
|
|
|
|
*
|
|
|
|
|
* \details This works like ast_log, but prints verbose messages to the console depending on verbosity level set.
|
|
|
|
|
*
|
|
|
|
|
* ast_verbose(VERBOSE_PREFIX_3 "Whatever %s is happening\n", "nothing");
|
|
|
|
|
*
|
|
|
|
|
* This will print the message to the console if the verbose level is set to a level >= 3
|
|
|
|
|
*
|
|
|
|
|
* Note the absence of a comma after the VERBOSE_PREFIX_3. This is important.
|
|
|
|
|
* VERBOSE_PREFIX_1 through VERBOSE_PREFIX_4 are defined.
|
|
|
|
|
*
|
|
|
|
|
* \version 11 added level parameter
|
2001-11-01 14:03:04 +00:00
|
|
|
*/
|
2012-02-14 20:27:16 +00:00
|
|
|
void __attribute__((format(printf, 5, 6))) __ast_verbose(const char *file, int line, const char *func, int level, const char *fmt, ...);
|
2008-05-21 22:34:27 +00:00
|
|
|
|
2014-01-14 18:14:02 +00:00
|
|
|
/*!
|
|
|
|
|
* \brief Send a verbose message (based on verbose level) with deliberately specified callid
|
|
|
|
|
*
|
|
|
|
|
* \details just like __ast_verbose, only __ast_verbose_callid allows you to specify which callid is being used
|
|
|
|
|
* for the log without needing to bind it to a thread. NULL is a valid argument for this function and will
|
|
|
|
|
* allow you to specify that a log will never display a call id even when there is a call id bound to the
|
|
|
|
|
* thread.
|
2012-06-26 21:45:22 +00:00
|
|
|
*/
|
2015-03-13 01:12:35 +00:00
|
|
|
void __attribute__((format(printf, 6, 7))) __ast_verbose_callid(const char *file, int line, const char *func, int level, ast_callid callid, const char *fmt, ...);
|
1999-10-27 00:56:38 +00:00
|
|
|
|
2021-10-28 09:28:57 +02:00
|
|
|
#define ast_verbose(...) __ast_verbose(_A_, -1, __VA_ARGS__)
|
|
|
|
|
#define ast_verbose_callid(callid, ...) __ast_verbose_callid(_A_, -1, callid, __VA_ARGS__)
|
2008-11-19 01:02:45 +00:00
|
|
|
|
2015-03-13 01:12:35 +00:00
|
|
|
void __attribute__((format(printf, 6, 0))) __ast_verbose_ap(const char *file, int line, const char *func, int level, ast_callid callid, const char *fmt, va_list ap);
|
2008-11-19 01:02:45 +00:00
|
|
|
|
2008-11-29 17:57:39 +00:00
|
|
|
void __attribute__((format(printf, 2, 3))) ast_child_verbose(int level, const char *fmt, ...);
|
2008-04-16 22:57:54 +00:00
|
|
|
|
2008-06-19 17:55:34 +00:00
|
|
|
int ast_register_verbose(void (*verboser)(const char *string)) attribute_warn_unused_result;
|
|
|
|
|
int ast_unregister_verbose(void (*verboser)(const char *string)) attribute_warn_unused_result;
|
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
|
|
|
|
2014-01-14 18:14:02 +00:00
|
|
|
/*
|
|
|
|
|
* These gymnastics are due to platforms which designate char as unsigned by
|
|
|
|
|
* default. Level is the negative character -- offset by 1, because \0 is
|
|
|
|
|
* the string terminator.
|
|
|
|
|
*/
|
|
|
|
|
#define VERBOSE_MAGIC2LEVEL(x) (((char) -*(signed char *) (x)) - 1)
|
|
|
|
|
#define VERBOSE_HASMAGIC(x) (*(signed char *) (x) < 0)
|
|
|
|
|
|
2006-03-31 10:35:25 +00:00
|
|
|
void ast_console_puts(const char *string);
|
2004-01-12 05:05:35 +00:00
|
|
|
|
2009-03-09 20:58:17 +00:00
|
|
|
/*!
|
logger: Support JSON logging with Verbose messages
When 2d7a4a3357 was merged, it missed the fact that Verbose log messages
are formatted and handled by 'verbosers'. Verbosers are registered
functions that handle verbose messages only; they exist as a separate
class of callbacks. This was done to handle the 'magic' that must be
inserted into Verbose messages sent to remote consoles, so that the
consoles can format the messages correctly, i.e., the leading
tabs/characters.
In reality, verbosers are a weird appendage: they're a separate class of
formatters/message handlers outside of what handles all other log
messages in Asterisk. After some code inspection, it became clear that
simply passing a Verbose message along with its 'sublevel' importance
through the normal logging mechanisms removes the need for verbosers
altogether.
This patch removes the verbosers, and makes the default log formatter
aware that, if the log channel is a console log, it should simply insert
the 'verbose magic' into the log messages itself. This allows the
console handlers to interpret and format the verbose message
themselves.
This simplifies the code quite a lot, and should improve the performance
of printing verbose messages by a reasonable factor:
(1) It removes a number of memory allocations that were done on each
verobse message
(2) It removes the need to strip the verbose magic out of the verbose
log messages before passing them to non-console log channels
(3) It now performs fewer iterations over lists when handling verbose
messages
Since verbose messages are now handled like other log messages (for the
most part), the JSON formatting of the messages works as well.
ASTERISK-25425
Change-Id: I21bf23f0a1e489b5102f8a035fe8871552ce4f96
2016-05-14 07:24:07 -05:00
|
|
|
* \brief log the string to the console, and all attached console clients
|
|
|
|
|
*
|
|
|
|
|
* \param string The message to write to the console
|
|
|
|
|
* \param level The log level of the message
|
|
|
|
|
*
|
2009-03-09 20:58:17 +00:00
|
|
|
* \version 1.6.1 added level parameter
|
|
|
|
|
*/
|
2008-05-29 21:30:37 +00:00
|
|
|
void ast_console_puts_mutable(const char *string, int level);
|
logger: Support JSON logging with Verbose messages
When 2d7a4a3357 was merged, it missed the fact that Verbose log messages
are formatted and handled by 'verbosers'. Verbosers are registered
functions that handle verbose messages only; they exist as a separate
class of callbacks. This was done to handle the 'magic' that must be
inserted into Verbose messages sent to remote consoles, so that the
consoles can format the messages correctly, i.e., the leading
tabs/characters.
In reality, verbosers are a weird appendage: they're a separate class of
formatters/message handlers outside of what handles all other log
messages in Asterisk. After some code inspection, it became clear that
simply passing a Verbose message along with its 'sublevel' importance
through the normal logging mechanisms removes the need for verbosers
altogether.
This patch removes the verbosers, and makes the default log formatter
aware that, if the log channel is a console log, it should simply insert
the 'verbose magic' into the log messages itself. This allows the
console handlers to interpret and format the verbose message
themselves.
This simplifies the code quite a lot, and should improve the performance
of printing verbose messages by a reasonable factor:
(1) It removes a number of memory allocations that were done on each
verobse message
(2) It removes the need to strip the verbose magic out of the verbose
log messages before passing them to non-console log channels
(3) It now performs fewer iterations over lists when handling verbose
messages
Since verbose messages are now handled like other log messages (for the
most part), the JSON formatting of the messages works as well.
ASTERISK-25425
Change-Id: I21bf23f0a1e489b5102f8a035fe8871552ce4f96
2016-05-14 07:24:07 -05:00
|
|
|
|
|
|
|
|
/*!
|
|
|
|
|
* \brief log the string to the console, and all attached console clients
|
|
|
|
|
* \since 14.0.0
|
|
|
|
|
*
|
|
|
|
|
* \param message The message to write to the console
|
|
|
|
|
* \param sublevel If the log level supports it, the sub-level of the message
|
|
|
|
|
* \param level The log level of the message
|
|
|
|
|
*/
|
|
|
|
|
void ast_console_puts_mutable_full(const char *message, int level, int sublevel);
|
|
|
|
|
|
2007-10-13 05:53:19 +00:00
|
|
|
void ast_console_toggle_mute(int fd, int silent);
|
2009-03-09 20:58:17 +00:00
|
|
|
|
|
|
|
|
/*!
|
2011-06-06 19:15:10 +00:00
|
|
|
* \brief enables or disables logging of a specified level to the console
|
|
|
|
|
* fd specifies the index of the console receiving the level change
|
|
|
|
|
* level specifies the index of the logging level being toggled
|
|
|
|
|
* state indicates whether logging will be on or off (0 for off, 1 for on)
|
2009-03-09 20:58:17 +00:00
|
|
|
*/
|
|
|
|
|
void ast_console_toggle_loglevel(int fd, int level, int state);
|
2006-05-26 19:48:17 +00:00
|
|
|
|
Round 2 of IMAP_STORAGE app_voicemail.c fixes:
This fixes a bug that was thought to be fixed already.
app_voicemail, if using IMAP_STORAGE, has a problem because
the IMAP header files include syslog.h, which define LOG_WARNING
and LOG_DEBUG to be different than what Asterisk uses for those
same macros. This was "fixed" in the past by including all the
IMAP header files prior to including asterisk.h. This fix worked...
unless you were to try to compile with MALLOC_DEBUG. MALLOC_DEBUG
prepends the inclusion of astmm.h to every file, which means that no
matter what order the includes are in in app_voicemail, the unexpected
values for LOG_WARNING and LOG_DEBUG will be in place.
The action taken for this fix was to define AST_LOG_* macros in addition
to the LOG_* macros already defined. These new macros are used in app_voicemail.c,
logger.h, and astobj.h right now, and their use will be encouraged in the future.
In consideration of those who have written third-party modules which use
the LOG_* macros, these will NOT be removed from the source, however future use
of these macros is discouraged.
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@114577 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2008-04-23 00:58:49 +00:00
|
|
|
/* Note: The AST_LOG_* macros below are the same as
|
|
|
|
|
* the LOG_* macros and are intended to eventually replace
|
2011-11-22 20:32:51 +00:00
|
|
|
* the LOG_* macros to avoid name collisions with the syslog(3)
|
|
|
|
|
* log levels. However, please do NOT remove
|
Round 2 of IMAP_STORAGE app_voicemail.c fixes:
This fixes a bug that was thought to be fixed already.
app_voicemail, if using IMAP_STORAGE, has a problem because
the IMAP header files include syslog.h, which define LOG_WARNING
and LOG_DEBUG to be different than what Asterisk uses for those
same macros. This was "fixed" in the past by including all the
IMAP header files prior to including asterisk.h. This fix worked...
unless you were to try to compile with MALLOC_DEBUG. MALLOC_DEBUG
prepends the inclusion of astmm.h to every file, which means that no
matter what order the includes are in in app_voicemail, the unexpected
values for LOG_WARNING and LOG_DEBUG will be in place.
The action taken for this fix was to define AST_LOG_* macros in addition
to the LOG_* macros already defined. These new macros are used in app_voicemail.c,
logger.h, and astobj.h right now, and their use will be encouraged in the future.
In consideration of those who have written third-party modules which use
the LOG_* macros, these will NOT be removed from the source, however future use
of these macros is discouraged.
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@114577 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2008-04-23 00:58:49 +00:00
|
|
|
* the LOG_* macros from the source since these may be still
|
|
|
|
|
* needed for third-party modules
|
|
|
|
|
*/
|
|
|
|
|
|
2004-01-12 05:05:35 +00:00
|
|
|
#ifdef LOG_DEBUG
|
|
|
|
|
#undef LOG_DEBUG
|
|
|
|
|
#endif
|
|
|
|
|
#define __LOG_DEBUG 0
|
|
|
|
|
#define LOG_DEBUG __LOG_DEBUG, _A_
|
|
|
|
|
|
Round 2 of IMAP_STORAGE app_voicemail.c fixes:
This fixes a bug that was thought to be fixed already.
app_voicemail, if using IMAP_STORAGE, has a problem because
the IMAP header files include syslog.h, which define LOG_WARNING
and LOG_DEBUG to be different than what Asterisk uses for those
same macros. This was "fixed" in the past by including all the
IMAP header files prior to including asterisk.h. This fix worked...
unless you were to try to compile with MALLOC_DEBUG. MALLOC_DEBUG
prepends the inclusion of astmm.h to every file, which means that no
matter what order the includes are in in app_voicemail, the unexpected
values for LOG_WARNING and LOG_DEBUG will be in place.
The action taken for this fix was to define AST_LOG_* macros in addition
to the LOG_* macros already defined. These new macros are used in app_voicemail.c,
logger.h, and astobj.h right now, and their use will be encouraged in the future.
In consideration of those who have written third-party modules which use
the LOG_* macros, these will NOT be removed from the source, however future use
of these macros is discouraged.
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@114577 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2008-04-23 00:58:49 +00:00
|
|
|
#ifdef AST_LOG_DEBUG
|
|
|
|
|
#undef AST_LOG_DEBUG
|
|
|
|
|
#endif
|
|
|
|
|
#define AST_LOG_DEBUG __LOG_DEBUG, _A_
|
|
|
|
|
|
2020-05-14 12:24:19 -06:00
|
|
|
#ifdef LOG_TRACE
|
|
|
|
|
#undef LOG_TRACE
|
|
|
|
|
#endif
|
|
|
|
|
#define __LOG_TRACE 1
|
|
|
|
|
#define LOG_TRACE __LOG_TRACE, _A_
|
|
|
|
|
|
|
|
|
|
#ifdef AST_LOG_TRACE
|
|
|
|
|
#undef AST_LOG_TRACE
|
|
|
|
|
#endif
|
|
|
|
|
#define AST_LOG_TRACE __LOG_TRACE, _A_
|
|
|
|
|
|
2004-01-12 05:05:35 +00:00
|
|
|
#ifdef LOG_NOTICE
|
|
|
|
|
#undef LOG_NOTICE
|
|
|
|
|
#endif
|
|
|
|
|
#define __LOG_NOTICE 2
|
|
|
|
|
#define LOG_NOTICE __LOG_NOTICE, _A_
|
|
|
|
|
|
Round 2 of IMAP_STORAGE app_voicemail.c fixes:
This fixes a bug that was thought to be fixed already.
app_voicemail, if using IMAP_STORAGE, has a problem because
the IMAP header files include syslog.h, which define LOG_WARNING
and LOG_DEBUG to be different than what Asterisk uses for those
same macros. This was "fixed" in the past by including all the
IMAP header files prior to including asterisk.h. This fix worked...
unless you were to try to compile with MALLOC_DEBUG. MALLOC_DEBUG
prepends the inclusion of astmm.h to every file, which means that no
matter what order the includes are in in app_voicemail, the unexpected
values for LOG_WARNING and LOG_DEBUG will be in place.
The action taken for this fix was to define AST_LOG_* macros in addition
to the LOG_* macros already defined. These new macros are used in app_voicemail.c,
logger.h, and astobj.h right now, and their use will be encouraged in the future.
In consideration of those who have written third-party modules which use
the LOG_* macros, these will NOT be removed from the source, however future use
of these macros is discouraged.
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@114577 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2008-04-23 00:58:49 +00:00
|
|
|
#ifdef AST_LOG_NOTICE
|
|
|
|
|
#undef AST_LOG_NOTICE
|
|
|
|
|
#endif
|
|
|
|
|
#define AST_LOG_NOTICE __LOG_NOTICE, _A_
|
|
|
|
|
|
2004-01-12 05:05:35 +00:00
|
|
|
#ifdef LOG_WARNING
|
|
|
|
|
#undef LOG_WARNING
|
|
|
|
|
#endif
|
|
|
|
|
#define __LOG_WARNING 3
|
|
|
|
|
#define LOG_WARNING __LOG_WARNING, _A_
|
|
|
|
|
|
Round 2 of IMAP_STORAGE app_voicemail.c fixes:
This fixes a bug that was thought to be fixed already.
app_voicemail, if using IMAP_STORAGE, has a problem because
the IMAP header files include syslog.h, which define LOG_WARNING
and LOG_DEBUG to be different than what Asterisk uses for those
same macros. This was "fixed" in the past by including all the
IMAP header files prior to including asterisk.h. This fix worked...
unless you were to try to compile with MALLOC_DEBUG. MALLOC_DEBUG
prepends the inclusion of astmm.h to every file, which means that no
matter what order the includes are in in app_voicemail, the unexpected
values for LOG_WARNING and LOG_DEBUG will be in place.
The action taken for this fix was to define AST_LOG_* macros in addition
to the LOG_* macros already defined. These new macros are used in app_voicemail.c,
logger.h, and astobj.h right now, and their use will be encouraged in the future.
In consideration of those who have written third-party modules which use
the LOG_* macros, these will NOT be removed from the source, however future use
of these macros is discouraged.
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@114577 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2008-04-23 00:58:49 +00:00
|
|
|
#ifdef AST_LOG_WARNING
|
|
|
|
|
#undef AST_LOG_WARNING
|
|
|
|
|
#endif
|
|
|
|
|
#define AST_LOG_WARNING __LOG_WARNING, _A_
|
|
|
|
|
|
2004-01-12 05:05:35 +00:00
|
|
|
#ifdef LOG_ERROR
|
|
|
|
|
#undef LOG_ERROR
|
|
|
|
|
#endif
|
|
|
|
|
#define __LOG_ERROR 4
|
|
|
|
|
#define LOG_ERROR __LOG_ERROR, _A_
|
1999-10-27 00:56:38 +00:00
|
|
|
|
Round 2 of IMAP_STORAGE app_voicemail.c fixes:
This fixes a bug that was thought to be fixed already.
app_voicemail, if using IMAP_STORAGE, has a problem because
the IMAP header files include syslog.h, which define LOG_WARNING
and LOG_DEBUG to be different than what Asterisk uses for those
same macros. This was "fixed" in the past by including all the
IMAP header files prior to including asterisk.h. This fix worked...
unless you were to try to compile with MALLOC_DEBUG. MALLOC_DEBUG
prepends the inclusion of astmm.h to every file, which means that no
matter what order the includes are in in app_voicemail, the unexpected
values for LOG_WARNING and LOG_DEBUG will be in place.
The action taken for this fix was to define AST_LOG_* macros in addition
to the LOG_* macros already defined. These new macros are used in app_voicemail.c,
logger.h, and astobj.h right now, and their use will be encouraged in the future.
In consideration of those who have written third-party modules which use
the LOG_* macros, these will NOT be removed from the source, however future use
of these macros is discouraged.
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@114577 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2008-04-23 00:58:49 +00:00
|
|
|
#ifdef AST_LOG_ERROR
|
|
|
|
|
#undef AST_LOG_ERROR
|
|
|
|
|
#endif
|
|
|
|
|
#define AST_LOG_ERROR __LOG_ERROR, _A_
|
|
|
|
|
|
2004-01-27 00:23:39 +00:00
|
|
|
#ifdef LOG_VERBOSE
|
|
|
|
|
#undef LOG_VERBOSE
|
|
|
|
|
#endif
|
|
|
|
|
#define __LOG_VERBOSE 5
|
|
|
|
|
#define LOG_VERBOSE __LOG_VERBOSE, _A_
|
|
|
|
|
|
Round 2 of IMAP_STORAGE app_voicemail.c fixes:
This fixes a bug that was thought to be fixed already.
app_voicemail, if using IMAP_STORAGE, has a problem because
the IMAP header files include syslog.h, which define LOG_WARNING
and LOG_DEBUG to be different than what Asterisk uses for those
same macros. This was "fixed" in the past by including all the
IMAP header files prior to including asterisk.h. This fix worked...
unless you were to try to compile with MALLOC_DEBUG. MALLOC_DEBUG
prepends the inclusion of astmm.h to every file, which means that no
matter what order the includes are in in app_voicemail, the unexpected
values for LOG_WARNING and LOG_DEBUG will be in place.
The action taken for this fix was to define AST_LOG_* macros in addition
to the LOG_* macros already defined. These new macros are used in app_voicemail.c,
logger.h, and astobj.h right now, and their use will be encouraged in the future.
In consideration of those who have written third-party modules which use
the LOG_* macros, these will NOT be removed from the source, however future use
of these macros is discouraged.
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@114577 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2008-04-23 00:58:49 +00:00
|
|
|
#ifdef AST_LOG_VERBOSE
|
|
|
|
|
#undef AST_LOG_VERBOSE
|
|
|
|
|
#endif
|
2011-09-28 21:30:14 +00:00
|
|
|
#define AST_LOG_VERBOSE __LOG_VERBOSE, _A_
|
Round 2 of IMAP_STORAGE app_voicemail.c fixes:
This fixes a bug that was thought to be fixed already.
app_voicemail, if using IMAP_STORAGE, has a problem because
the IMAP header files include syslog.h, which define LOG_WARNING
and LOG_DEBUG to be different than what Asterisk uses for those
same macros. This was "fixed" in the past by including all the
IMAP header files prior to including asterisk.h. This fix worked...
unless you were to try to compile with MALLOC_DEBUG. MALLOC_DEBUG
prepends the inclusion of astmm.h to every file, which means that no
matter what order the includes are in in app_voicemail, the unexpected
values for LOG_WARNING and LOG_DEBUG will be in place.
The action taken for this fix was to define AST_LOG_* macros in addition
to the LOG_* macros already defined. These new macros are used in app_voicemail.c,
logger.h, and astobj.h right now, and their use will be encouraged in the future.
In consideration of those who have written third-party modules which use
the LOG_* macros, these will NOT be removed from the source, however future use
of these macros is discouraged.
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@114577 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2008-04-23 00:58:49 +00:00
|
|
|
|
2005-08-22 21:19:59 +00:00
|
|
|
#ifdef LOG_DTMF
|
|
|
|
|
#undef LOG_DTMF
|
|
|
|
|
#endif
|
|
|
|
|
#define __LOG_DTMF 6
|
|
|
|
|
#define LOG_DTMF __LOG_DTMF, _A_
|
|
|
|
|
|
Round 2 of IMAP_STORAGE app_voicemail.c fixes:
This fixes a bug that was thought to be fixed already.
app_voicemail, if using IMAP_STORAGE, has a problem because
the IMAP header files include syslog.h, which define LOG_WARNING
and LOG_DEBUG to be different than what Asterisk uses for those
same macros. This was "fixed" in the past by including all the
IMAP header files prior to including asterisk.h. This fix worked...
unless you were to try to compile with MALLOC_DEBUG. MALLOC_DEBUG
prepends the inclusion of astmm.h to every file, which means that no
matter what order the includes are in in app_voicemail, the unexpected
values for LOG_WARNING and LOG_DEBUG will be in place.
The action taken for this fix was to define AST_LOG_* macros in addition
to the LOG_* macros already defined. These new macros are used in app_voicemail.c,
logger.h, and astobj.h right now, and their use will be encouraged in the future.
In consideration of those who have written third-party modules which use
the LOG_* macros, these will NOT be removed from the source, however future use
of these macros is discouraged.
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@114577 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2008-04-23 00:58:49 +00:00
|
|
|
#ifdef AST_LOG_DTMF
|
|
|
|
|
#undef AST_LOG_DTMF
|
|
|
|
|
#endif
|
|
|
|
|
#define AST_LOG_DTMF __LOG_DTMF, _A_
|
|
|
|
|
|
2012-03-14 10:56:53 +00:00
|
|
|
#define NUMLOGLEVELS 32
|
2008-05-29 21:30:37 +00:00
|
|
|
|
2007-07-23 14:21:41 +00:00
|
|
|
/*!
|
2010-03-23 14:22:27 +00:00
|
|
|
* \brief Get the debug level for a module
|
2010-06-08 14:38:18 +00:00
|
|
|
* \param module the name of module
|
2007-07-23 14:21:41 +00:00
|
|
|
* \return the debug level
|
|
|
|
|
*/
|
2010-03-23 14:22:27 +00:00
|
|
|
unsigned int ast_debug_get_by_module(const char *module);
|
2007-07-23 14:21:41 +00:00
|
|
|
|
2009-05-15 13:13:47 +00:00
|
|
|
/*!
|
|
|
|
|
* \brief Register a new logger level
|
|
|
|
|
* \param name The name of the level to be registered
|
|
|
|
|
* \retval -1 if an error occurs
|
|
|
|
|
* \retval non-zero level to be used with ast_log for sending messages to this level
|
2009-12-21 18:51:17 +00:00
|
|
|
* \since 1.8
|
2009-05-15 13:13:47 +00:00
|
|
|
*/
|
|
|
|
|
int ast_logger_register_level(const char *name);
|
|
|
|
|
|
2021-07-25 22:19:08 +00:00
|
|
|
/*!
|
|
|
|
|
* \brief Retrieve dynamic logging level id
|
|
|
|
|
* \param name The name of the level
|
|
|
|
|
* \retval The unique integer id for the given level
|
|
|
|
|
* \retval -1 if level name not found
|
|
|
|
|
*/
|
|
|
|
|
int ast_logger_get_dynamic_level(const char *name);
|
|
|
|
|
|
2009-05-15 13:13:47 +00:00
|
|
|
/*!
|
|
|
|
|
* \brief Unregister a previously registered logger level
|
|
|
|
|
* \param name The name of the level to be unregistered
|
|
|
|
|
* \return nothing
|
2009-12-21 18:51:17 +00:00
|
|
|
* \since 1.8
|
2009-05-15 13:13:47 +00:00
|
|
|
*/
|
|
|
|
|
void ast_logger_unregister_level(const char *name);
|
|
|
|
|
|
2014-05-28 22:54:12 +00:00
|
|
|
/*!
|
|
|
|
|
* \brief Get the logger configured date format
|
|
|
|
|
*
|
|
|
|
|
* \retval The date format string
|
|
|
|
|
*
|
|
|
|
|
* \since 13.0.0
|
|
|
|
|
*/
|
|
|
|
|
const char *ast_logger_get_dateformat(void);
|
|
|
|
|
|
2012-03-29 20:01:20 +00:00
|
|
|
/*!
|
|
|
|
|
* \brief factory function to create a new uniquely identifying callid.
|
|
|
|
|
*
|
2015-03-13 01:12:35 +00:00
|
|
|
* \retval The call id
|
2012-03-29 20:01:20 +00:00
|
|
|
*/
|
2015-03-13 01:12:35 +00:00
|
|
|
ast_callid ast_create_callid(void);
|
2012-03-29 20:01:20 +00:00
|
|
|
|
|
|
|
|
/*!
|
|
|
|
|
* \brief extracts the callerid from the thread
|
|
|
|
|
*
|
2015-03-13 01:12:35 +00:00
|
|
|
* \retval Non-zero Call id related to the thread
|
|
|
|
|
* \retval 0 if no call_id is present in the thread
|
2013-07-19 19:35:21 +00:00
|
|
|
*/
|
2015-03-13 01:12:35 +00:00
|
|
|
ast_callid ast_read_threadstorage_callid(void);
|
2012-03-29 20:01:20 +00:00
|
|
|
|
2013-02-15 17:38:22 +00:00
|
|
|
/*!
|
|
|
|
|
* \brief Sets what is stored in the thread storage to the given
|
|
|
|
|
* callid if it does not match what is already there.
|
|
|
|
|
*
|
|
|
|
|
* \retval 0 - success
|
|
|
|
|
* \retval non-zero - failure
|
|
|
|
|
*/
|
2015-03-13 01:12:35 +00:00
|
|
|
int ast_callid_threadassoc_change(ast_callid callid);
|
2013-02-15 17:38:22 +00:00
|
|
|
|
2012-03-29 20:01:20 +00:00
|
|
|
/*!
|
|
|
|
|
* \brief Adds a known callid to thread storage of the calling thread
|
|
|
|
|
*
|
|
|
|
|
* \retval 0 - success
|
|
|
|
|
* \retval non-zero - failure
|
|
|
|
|
*/
|
2015-03-13 01:12:35 +00:00
|
|
|
int ast_callid_threadassoc_add(ast_callid callid);
|
2012-03-29 20:01:20 +00:00
|
|
|
|
2012-05-17 16:28:20 +00:00
|
|
|
/*!
|
|
|
|
|
* \brief Removes callid from thread storage of the calling thread
|
|
|
|
|
*
|
|
|
|
|
* \retval 0 - success
|
|
|
|
|
* \retval non-zero - failure
|
|
|
|
|
*/
|
|
|
|
|
int ast_callid_threadassoc_remove(void);
|
|
|
|
|
|
|
|
|
|
/*!
|
|
|
|
|
* \brief Checks thread storage for a callid and stores a reference if it exists.
|
|
|
|
|
* If not, then a new one will be created, bound to the thread, and a reference
|
|
|
|
|
* to it will be stored.
|
|
|
|
|
*
|
2015-03-13 01:12:35 +00:00
|
|
|
* \param callid pointer to store the callid
|
2012-05-17 16:28:20 +00:00
|
|
|
* \retval 0 - callid was found
|
|
|
|
|
* \retval 1 - callid was created
|
|
|
|
|
* \retval -1 - the function failed somehow (presumably memory problems)
|
|
|
|
|
*/
|
2015-03-13 01:12:35 +00:00
|
|
|
int ast_callid_threadstorage_auto(ast_callid *callid);
|
2012-05-17 16:28:20 +00:00
|
|
|
|
|
|
|
|
/*!
|
|
|
|
|
* \brief Use in conjunction with ast_callid_threadstorage_auto. Cleans up the
|
|
|
|
|
* references and if the callid was created by threadstorage_auto, unbinds
|
|
|
|
|
* the callid from the threadstorage
|
|
|
|
|
* \param callid The callid set by ast_callid_threadstorage_auto
|
|
|
|
|
* \param callid_created The integer returned through ast_callid_threadstorage_auto
|
|
|
|
|
*/
|
2015-03-13 01:12:35 +00:00
|
|
|
void ast_callid_threadstorage_auto_clean(ast_callid callid, int callid_created);
|
2012-05-17 16:28:20 +00:00
|
|
|
|
|
|
|
|
/*!
|
|
|
|
|
* \brief copy a string representation of the callid into a target string
|
|
|
|
|
*
|
|
|
|
|
* \param buffer destination of callid string (should be able to store 13 characters or more)
|
|
|
|
|
* \param buffer_size maximum writable length of the string (Less than 13 will result in truncation)
|
|
|
|
|
* \param callid Callid for which string is being requested
|
2012-03-29 20:01:20 +00:00
|
|
|
*/
|
2015-03-13 01:12:35 +00:00
|
|
|
void ast_callid_strnprint(char *buffer, size_t buffer_size, ast_callid callid);
|
2012-03-29 20:01:20 +00:00
|
|
|
|
2009-05-15 13:13:47 +00:00
|
|
|
/*!
|
|
|
|
|
* \brief Send a log message to a dynamically registered log level
|
|
|
|
|
* \param level The log level to send the message to
|
|
|
|
|
*
|
|
|
|
|
* Like ast_log, the log message may include printf-style formats, and
|
|
|
|
|
* the data for these must be provided as additional parameters after
|
|
|
|
|
* the log message.
|
|
|
|
|
*
|
|
|
|
|
* \return nothing
|
2009-12-21 18:51:17 +00:00
|
|
|
* \since 1.8
|
2009-05-15 13:13:47 +00:00
|
|
|
*/
|
|
|
|
|
|
2021-10-28 09:28:57 +02:00
|
|
|
#define ast_log_dynamic_level(level, ...) ast_log(level, _A_, __VA_ARGS__)
|
2009-05-15 13:13:47 +00:00
|
|
|
|
2014-07-14 14:55:30 +00:00
|
|
|
#define DEBUG_ATLEAST(level) \
|
|
|
|
|
(option_debug >= (level) \
|
2017-09-27 12:45:21 -06:00
|
|
|
|| (ast_opt_dbg_module \
|
|
|
|
|
&& ((int)ast_debug_get_by_module(AST_MODULE) >= (level) \
|
|
|
|
|
|| (int)ast_debug_get_by_module(__FILE__) >= (level))))
|
2014-07-14 14:55:30 +00:00
|
|
|
|
2007-06-12 16:11:40 +00:00
|
|
|
/*!
|
|
|
|
|
* \brief Log a DEBUG message
|
|
|
|
|
* \param level The minimum value of option_debug for this message
|
|
|
|
|
* to get logged
|
|
|
|
|
*/
|
2014-07-14 14:55:30 +00:00
|
|
|
#define ast_debug(level, ...) \
|
|
|
|
|
do { \
|
|
|
|
|
if (DEBUG_ATLEAST(level)) { \
|
|
|
|
|
ast_log(AST_LOG_DEBUG, __VA_ARGS__); \
|
|
|
|
|
} \
|
|
|
|
|
} while (0)
|
2007-07-23 14:21:41 +00:00
|
|
|
|
2014-01-14 18:14:02 +00:00
|
|
|
extern int ast_verb_sys_level;
|
|
|
|
|
|
|
|
|
|
#define VERBOSITY_ATLEAST(level) ((level) <= ast_verb_sys_level)
|
|
|
|
|
|
|
|
|
|
#define ast_verb(level, ...) \
|
|
|
|
|
do { \
|
|
|
|
|
if (VERBOSITY_ATLEAST(level) ) { \
|
2021-10-28 09:28:57 +02:00
|
|
|
__ast_verbose(_A_, level, __VA_ARGS__); \
|
2014-01-14 18:14:02 +00:00
|
|
|
} \
|
|
|
|
|
} while (0)
|
|
|
|
|
|
|
|
|
|
#define ast_verb_callid(level, callid, ...) \
|
|
|
|
|
do { \
|
|
|
|
|
if (VERBOSITY_ATLEAST(level) ) { \
|
2021-10-28 09:28:57 +02:00
|
|
|
__ast_verbose_callid(_A_, level, callid, __VA_ARGS__); \
|
2014-01-14 18:14:02 +00:00
|
|
|
} \
|
|
|
|
|
} while (0)
|
|
|
|
|
|
|
|
|
|
/*!
|
|
|
|
|
* \brief Re-evaluate the system max verbosity level (ast_verb_sys_level).
|
|
|
|
|
*
|
|
|
|
|
* \return Nothing
|
|
|
|
|
*/
|
|
|
|
|
void ast_verb_update(void);
|
|
|
|
|
|
|
|
|
|
/*!
|
|
|
|
|
* \brief Register this thread's console verbosity level pointer.
|
|
|
|
|
*
|
|
|
|
|
* \param level Where the verbose level value is.
|
|
|
|
|
*
|
|
|
|
|
* \return Nothing
|
|
|
|
|
*/
|
|
|
|
|
void ast_verb_console_register(int *level);
|
|
|
|
|
|
|
|
|
|
/*!
|
|
|
|
|
* \brief Unregister this thread's console verbosity level.
|
|
|
|
|
*
|
|
|
|
|
* \return Nothing
|
|
|
|
|
*/
|
|
|
|
|
void ast_verb_console_unregister(void);
|
|
|
|
|
|
|
|
|
|
/*!
|
|
|
|
|
* \brief Get this thread's console verbosity level.
|
|
|
|
|
*
|
|
|
|
|
* \retval verbosity level of the console.
|
|
|
|
|
*/
|
|
|
|
|
int ast_verb_console_get(void);
|
|
|
|
|
|
|
|
|
|
/*!
|
|
|
|
|
* \brief Set this thread's console verbosity level.
|
|
|
|
|
*
|
|
|
|
|
* \param verb_level New level to set.
|
|
|
|
|
*
|
|
|
|
|
* \return Nothing
|
|
|
|
|
*/
|
|
|
|
|
void ast_verb_console_set(int verb_level);
|
2007-06-12 16:11:40 +00:00
|
|
|
|
2017-04-11 10:07:39 -06:00
|
|
|
/*!
|
|
|
|
|
* \brief Test if logger is initialized
|
|
|
|
|
*
|
|
|
|
|
* \retval true if the logger is initialized
|
|
|
|
|
*/
|
|
|
|
|
int ast_is_logger_initialized(void);
|
|
|
|
|
|
2017-05-08 15:11:19 -06:00
|
|
|
/*!
|
|
|
|
|
* \brief Set the maximum number of messages allowed in the processing queue
|
|
|
|
|
*
|
|
|
|
|
* \param queue_limit
|
|
|
|
|
*
|
|
|
|
|
* \return Nothing
|
|
|
|
|
*/
|
|
|
|
|
void ast_logger_set_queue_limit(int queue_limit);
|
|
|
|
|
|
|
|
|
|
/*!
|
|
|
|
|
* \brief Get the maximum number of messages allowed in the processing queue
|
|
|
|
|
*
|
|
|
|
|
* \return Queue limit
|
|
|
|
|
*/
|
|
|
|
|
int ast_logger_get_queue_limit(void);
|
|
|
|
|
|
2020-05-14 12:24:19 -06:00
|
|
|
|
|
|
|
|
/*!
|
|
|
|
|
\page Scope_Trace Scope Trace
|
|
|
|
|
|
|
|
|
|
The Scope Trace facility allows you to instrument code and output scope entry
|
|
|
|
|
and exit messages with associated data.
|
|
|
|
|
|
|
|
|
|
To start using it:
|
|
|
|
|
* You must have used --enable-dev-mode.
|
|
|
|
|
* In logger.conf, set a logger channel to output the "trace" level.
|
|
|
|
|
* Instrument your code as specified below.
|
|
|
|
|
* Use the cli or cli.conf to enable tracing: CLI> core set trace <trace_level> [ module ]
|
|
|
|
|
|
|
|
|
|
Its simplest usage requires only 1 macro call that...
|
2021-10-30 21:04:30 -04:00
|
|
|
- Registers a destructor for a special variable that gets called when the
|
2020-05-14 12:24:19 -06:00
|
|
|
variable goes out of scope. Uses the same principle as RAII_VAR.
|
|
|
|
|
The destructor prints the name of the function with an "exiting" indicator
|
|
|
|
|
along with an optional message.
|
|
|
|
|
- Prints the name of the function with an "entering" indicator along with
|
|
|
|
|
an optional message.
|
|
|
|
|
|
|
|
|
|
Simple Example:
|
|
|
|
|
The following code...
|
|
|
|
|
\code
|
|
|
|
|
static struct pjmedia_sdp_session *create_local_sdp(pjsip_inv_session *inv,
|
|
|
|
|
struct ast_sip_session *session, const pjmedia_sdp_session *offer)
|
|
|
|
|
{
|
|
|
|
|
SCOPE_TRACE(1, "%s\n", ast_sip_session_get_name(session));
|
|
|
|
|
...
|
|
|
|
|
}
|
|
|
|
|
\endcode
|
|
|
|
|
would produce...
|
|
|
|
|
\b [2020-05-17 15:16:51 -0600] TRACE[953402] : --> res_pjsip_session.c:4283 create_local_sdp PJSIP/1173-00000001
|
|
|
|
|
\b [2020-05-17 15:16:51 -0600] TRACE[953402] : <-- res_pjsip_session.c:4283 create_local_sdp PJSIP/1173-00000001
|
|
|
|
|
|
|
|
|
|
There is one odd bit. There's no way to capture the line number of there the scope exited
|
|
|
|
|
so it's always going to be the line where SCOPE_TRACE is located.
|
|
|
|
|
|
|
|
|
|
Similar to RAII_VAR, any block scope can be traced including "if", "for", "while", etc.
|
|
|
|
|
\note "case" statements don't create a scope block by themselves but you can create
|
|
|
|
|
a block for it, or use the generic trace functions mentioned below.
|
|
|
|
|
|
|
|
|
|
Scope Output and Level:
|
|
|
|
|
|
|
|
|
|
Rather than sending trace messages to the debug facility, a new facility "trace" has been
|
|
|
|
|
added to logger. A corresponding CLI command "core set trace", and a corresponding "trace"
|
|
|
|
|
parameter in asterisk.conf were added. This allows a separate log channel to be created
|
|
|
|
|
just for storing trace messages. The levels are the same as those for debug and verbose.
|
|
|
|
|
|
|
|
|
|
Scope Indenting:
|
|
|
|
|
|
|
|
|
|
Each time SCOPE_TRACE or SCOPE_TRACE is called, a thread-local indent value is
|
|
|
|
|
incremented on scope enter, and decremented on scope exit. This allows output
|
|
|
|
|
like the following (timestamp omitted for brevity):
|
|
|
|
|
|
|
|
|
|
TRACE[953402] : --> res_pjsip_session.c:3940 session_inv_on_tsx_state_changed PJSIP/1173-00000001 TSX State: Proceeding Inv State: CALLING
|
|
|
|
|
TRACE[953402] : --> res_pjsip_session.c:3680 handle_incoming PJSIP/1173-00000001
|
|
|
|
|
TRACE[953402] : --> res_pjsip_session.c:3661 handle_incoming_response PJSIP/1173-00000001 Method: INVITE Status: 100
|
|
|
|
|
TRACE[953402] : --> res_pjsip_session.c:3669 handle_incoming_response PJSIP/1173-00000001 Method: INVITE Status: 100 Supplement: chan_pjsip
|
|
|
|
|
TRACE[953402] : --> chan_pjsip.c:3265 chan_pjsip_incoming_response_after_media PJSIP/1173-00000001 Method: INVITE Status: 100 After Media
|
|
|
|
|
TRACE[953402] : --> chan_pjsip.c:3194 chan_pjsip_incoming_response PJSIP/1173-00000001 Method: INVITE Status: 100
|
|
|
|
|
TRACE[953402] : chan_pjsip.c:3245 chan_pjsip_incoming_response PJSIP/1173-00000001 Method: INVITE Status: 100 Ignored
|
|
|
|
|
TRACE[953402] : <-- chan_pjsip.c:3194 chan_pjsip_incoming_response PJSIP/1173-00000001 Method: INVITE Status: 100
|
|
|
|
|
TRACE[953402] : <-- chan_pjsip.c:3265 chan_pjsip_incoming_response_after_media PJSIP/1173-00000001 Method: INVITE Status: 100 After Media
|
|
|
|
|
TRACE[953402] : <-- res_pjsip_session.c:3669 handle_incoming_response PJSIP/1173-00000001 Method: INVITE Status: 100 Supplement: chan_pjsip
|
|
|
|
|
TRACE[953402] : <-- res_pjsip_session.c:3661 handle_incoming_response PJSIP/1173-00000001 Method: INVITE Status: 100
|
|
|
|
|
TRACE[953402] : <-- res_pjsip_session.c:3680 handle_incoming PJSIP/1173-00000001
|
|
|
|
|
TRACE[953402] : <-- res_pjsip_session.c:3940 session_inv_on_tsx_state_changed PJSIP/1173-00000001 TSX State: Proceeding Inv State: CALLING
|
|
|
|
|
|
|
|
|
|
\note The trace level indicates which messages to print and has no effect on indent.
|
|
|
|
|
|
|
|
|
|
Generic Trace Messages:
|
|
|
|
|
|
|
|
|
|
Sometimes you may just want to print a message to the trace log with the appropriate indent
|
|
|
|
|
such as when executing a "case" clause in a "switch" statement. For example, the deepest
|
|
|
|
|
message in the sample output above (chan_pjsip.c:3245) is just a single message instead of
|
|
|
|
|
an entry/exit message. To do so, you can use the ast_trace macros...
|
|
|
|
|
\code
|
|
|
|
|
ast_trace(1, "%s Method: %.*s Status: %d Ignored\n", ast_sip_session_get_name(session),
|
|
|
|
|
(int)rdata->msg_info.cseq->method.name.slen, rdata->msg_info.cseq->method.name.ptr, status.code);
|
|
|
|
|
\endcode
|
|
|
|
|
|
|
|
|
|
/note Final note: The trace facility, like debug, is only available when AST_DEVMODE is defined.
|
|
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
/*!
|
|
|
|
|
* \brief Get the trace level for a module
|
|
|
|
|
* \param module the name of module
|
|
|
|
|
* \return the trace level
|
|
|
|
|
*/
|
|
|
|
|
unsigned int ast_trace_get_by_module(const char *module);
|
|
|
|
|
|
2021-03-19 10:11:26 -04:00
|
|
|
/*!
|
|
|
|
|
* \brief load logger.conf configuration for console socket connections
|
|
|
|
|
*/
|
|
|
|
|
void ast_init_logger_for_socket_console(void);
|
|
|
|
|
|
2020-05-14 12:24:19 -06:00
|
|
|
#define TRACE_ATLEAST(level) \
|
|
|
|
|
(option_trace >= (level) \
|
|
|
|
|
|| (ast_opt_trace_module \
|
|
|
|
|
&& ((int)ast_trace_get_by_module(AST_MODULE) >= (level) \
|
|
|
|
|
|| (int)ast_trace_get_by_module(__FILE__) >= (level))))
|
|
|
|
|
|
|
|
|
|
/*!
|
|
|
|
|
* \brief Controls if and when indenting is applied.
|
|
|
|
|
*/
|
|
|
|
|
enum ast_trace_indent_type {
|
|
|
|
|
/*! Use the existing indent level */
|
|
|
|
|
AST_TRACE_INDENT_SAME = 0,
|
|
|
|
|
/*! Increment the indent before printing the message */
|
|
|
|
|
AST_TRACE_INDENT_INC_BEFORE,
|
|
|
|
|
/*! Increment the indent after printing the message */
|
|
|
|
|
AST_TRACE_INDENT_INC_AFTER,
|
|
|
|
|
/*! Decrement the indent before printing the message */
|
|
|
|
|
AST_TRACE_INDENT_DEC_BEFORE,
|
|
|
|
|
/*! Decrement the indent after printing the message */
|
|
|
|
|
AST_TRACE_INDENT_DEC_AFTER,
|
2020-07-05 17:51:04 -06:00
|
|
|
/*! Set the indent to the one provided */
|
|
|
|
|
AST_TRACE_INDENT_PROVIDED,
|
2020-05-14 12:24:19 -06:00
|
|
|
/*! Don't use or alter the level */
|
|
|
|
|
AST_TRACE_INDENT_NONE,
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
#ifdef AST_DEVMODE
|
|
|
|
|
|
2020-07-05 17:51:04 -06:00
|
|
|
void __attribute__((format (printf, 6, 7))) __ast_trace(const char *file, int line, const char *func,
|
|
|
|
|
enum ast_trace_indent_type indent_type, unsigned long indent, const char* format, ...);
|
2020-05-14 12:24:19 -06:00
|
|
|
|
|
|
|
|
/*!
|
|
|
|
|
* \brief Print a trace message
|
|
|
|
|
*
|
|
|
|
|
* \param level The trace level
|
|
|
|
|
* \param indent_type One of the \ref ast_trace_indent_type values
|
|
|
|
|
* \param (optional) A printf style format string
|
|
|
|
|
* \param (optional) Arguments
|
|
|
|
|
*
|
|
|
|
|
*/
|
|
|
|
|
#define ast_trace_raw(level, indent_type, ...) \
|
2020-08-19 06:37:23 -06:00
|
|
|
ast_debug(level < 0 ? __scope_level : level, " " __VA_ARGS__); \
|
2020-09-17 10:40:39 -06:00
|
|
|
if (TRACE_ATLEAST(level < 0 ? __scope_level : level)) { \
|
2021-10-28 09:28:57 +02:00
|
|
|
__ast_trace(_A_, indent_type, 0, " " __VA_ARGS__); \
|
2020-05-14 12:24:19 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*!
|
|
|
|
|
* \brief Print a basic trace message
|
|
|
|
|
*
|
|
|
|
|
* \param level The trace level
|
|
|
|
|
* \param (optional) A printf style format string
|
|
|
|
|
* \param (optional) Arguments
|
|
|
|
|
*
|
|
|
|
|
* This will print the file, line and function at the current indent level
|
|
|
|
|
*/
|
|
|
|
|
#define ast_trace(level, ...) \
|
2020-08-19 06:37:23 -06:00
|
|
|
ast_debug(level < 0 ? __scope_level : level, " " __VA_ARGS__); \
|
2020-09-17 10:40:39 -06:00
|
|
|
if (TRACE_ATLEAST(level < 0 ? __scope_level : level)) { \
|
2021-10-28 09:28:57 +02:00
|
|
|
__ast_trace(_A_, AST_TRACE_INDENT_SAME, 0, " " __VA_ARGS__); \
|
2020-05-14 12:24:19 -06:00
|
|
|
}
|
|
|
|
|
|
2020-07-05 17:51:04 -06:00
|
|
|
/*!
|
|
|
|
|
* \brief Get the current indent level
|
|
|
|
|
*
|
|
|
|
|
* \returns The current indent level
|
|
|
|
|
*/
|
|
|
|
|
unsigned long _ast_trace_get_indent(void);
|
|
|
|
|
#define ast_trace_get_indent() _ast_trace_get_indent()
|
|
|
|
|
|
|
|
|
|
/*!
|
|
|
|
|
* \brief Set the current indent level
|
|
|
|
|
*
|
|
|
|
|
* \param indent The new indent level
|
|
|
|
|
*/
|
|
|
|
|
void _ast_trace_set_indent(unsigned long indent);
|
|
|
|
|
#define ast_trace_set_indent(indent) _ast_trace_set_indent(indent)
|
|
|
|
|
|
|
|
|
|
/*!
|
|
|
|
|
* \brief Increment the indent level
|
|
|
|
|
*
|
|
|
|
|
* \returns The new indent level
|
|
|
|
|
*/
|
|
|
|
|
unsigned long _ast_trace_inc_indent(void);
|
|
|
|
|
#define ast_trace_inc_indent() _ast_trace_inc_indent()
|
|
|
|
|
|
|
|
|
|
/*!
|
|
|
|
|
* \brief Decrement the indent level
|
|
|
|
|
*
|
|
|
|
|
* \returns The new indent level
|
|
|
|
|
*/
|
|
|
|
|
unsigned long _ast_trace_dec_indent(void);
|
|
|
|
|
#define ast_trace_dec_indent() _ast_trace_dec_indent()
|
|
|
|
|
|
2020-05-14 12:24:19 -06:00
|
|
|
/*!
|
|
|
|
|
* \brief Print a trace message with details when a scope is entered or existed.
|
|
|
|
|
*
|
|
|
|
|
* \param level The trace level
|
|
|
|
|
* \param (optional) A printf style format string
|
|
|
|
|
* \param (optional) Arguments
|
|
|
|
|
*
|
|
|
|
|
* This will print the file, line and function plus details at the current indent level.
|
|
|
|
|
* \note Like RAII_VAR, this macro must be called before any code in the scope.
|
|
|
|
|
*
|
|
|
|
|
* \note The variables used to detect scope change will look like
|
|
|
|
|
* __scopevar1234__EXIT and __scopevar1234__ENTER.
|
|
|
|
|
* The ENTER variable and function are needed to prevent mixed code and declaration issues.
|
|
|
|
|
* If we simple called __ast_trace, then this macro would need to be the last line
|
|
|
|
|
* of scope variable declaration. The following would fail.
|
|
|
|
|
*
|
|
|
|
|
* SCOPE_TRACE(1, "Help!\n");
|
|
|
|
|
* int i;
|
|
|
|
|
*/
|
|
|
|
|
#define SCOPE_TRACE(level, ...) \
|
|
|
|
|
const char *__trace_funcname = __PRETTY_FUNCTION__; \
|
|
|
|
|
auto void __scopevar ## __LINE__ ## __EXIT(void * v); \
|
|
|
|
|
void __scopevar ## __LINE__ ## __EXIT(void * v __attribute__((unused))) { \
|
|
|
|
|
if (TRACE_ATLEAST(level)) { \
|
2020-07-05 17:51:04 -06:00
|
|
|
__ast_trace(__FILE__, __LINE__, __trace_funcname, AST_TRACE_INDENT_DEC_BEFORE, 0, " " __VA_ARGS__); \
|
2020-05-14 12:24:19 -06:00
|
|
|
} \
|
|
|
|
|
} \
|
|
|
|
|
void *__scopevar ## __LINE__ ## __TRACER __attribute__((cleanup(__scopevar ## __LINE__ ## __EXIT))) = (void *) __PRETTY_FUNCTION__ ; \
|
|
|
|
|
auto int __scopevar ## __LINE__ ## __ENTER(void); \
|
|
|
|
|
int __scopevar ## __LINE__ ## __ENTER(void) { \
|
|
|
|
|
if (TRACE_ATLEAST(level)) { \
|
2020-07-05 17:51:04 -06:00
|
|
|
__ast_trace(__FILE__, __LINE__, __trace_funcname, AST_TRACE_INDENT_INC_AFTER, 0, " " __VA_ARGS__); \
|
2020-05-14 12:24:19 -06:00
|
|
|
} \
|
|
|
|
|
return 0; \
|
|
|
|
|
} \
|
|
|
|
|
int __scopevar ## __LINE__ ## __RETURN __attribute__((unused)) = __scopevar ## __LINE__ ## __ENTER()
|
|
|
|
|
|
Scope Trace: Add some new tracing macros and an ast_str helper
Created new SCOPE_ functions that don't depend on RAII_VAR. Besides
generating less code, the use of the explicit SCOPE_EXIT macros
capture the line number where the scope exited. The RAII_VAR
versions can't do that.
* SCOPE_ENTER(level, ...): Like SCOPE_TRACE but doesn't use
RAII_VAR and therefore needs needs one of...
* SCOPE_EXIT(...): Decrements the trace stack counter and optionally
prints a message.
* SCOPE_EXIT_EXPR(__expr, ...): Decrements the trace stack counter,
optionally prints a message, then executes the expression.
SCOPE_EXIT_EXPR(break, "My while got broken\n");
* SCOPE_EXIT_RTN(, ...): Decrements the trace stack counter,
optionally prints a message, then returns without a value.
SCOPE_EXIT_RTN("Bye\n");
* SCOPE_EXIT_RTN_VALUE(__return_value, ...): Decrements the trace
stack counter, optionally prints a message, then returns the value
specified.
SCOPE_EXIT_RTN_VALUE(rc, "Returning with RC: %d\n", rc);
Create an ast_str helper ast_str_tmp() that allocates a temporary
ast_str that can be passed to a function that needs it, then frees
it. This makes using the above macros easier. Example:
SCOPE_ENTER(1, Format Caps 1: %s Format Caps 2: %s\n",
ast_str_tmp(32, ast_format_cap_get_names(cap1, &STR_TMP),
ast_str_tmp(32, ast_format_cap_get_names(cap2, &STR_TMP));
The calls to ast_str_tmp create an ast_str of the specified initial
length which can be referenced as STR_TMP. It then calls the
expression, which must return a char *, ast_strdupa's it, frees
STR_TMP, then returns the ast_strdupa'd string. That string is
freed when the function returns.
Change-Id: I44059b20d55a889aa91440d2f8a590865998be51
2020-06-30 07:56:34 -06:00
|
|
|
/*!
|
|
|
|
|
* \brief Non RAII_VAR Scope Trace macros
|
|
|
|
|
* The advantage of these macros is that the EXITs will have the actual
|
|
|
|
|
* line number where the scope exited. Much less code is required as well.
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
/*!
|
|
|
|
|
* \brief Scope Enter
|
|
|
|
|
*
|
|
|
|
|
* \param level The trace level
|
|
|
|
|
* \param (optional) A printf style format string
|
|
|
|
|
* \param (optional) Arguments
|
|
|
|
|
*/
|
|
|
|
|
#define SCOPE_ENTER(level, ...) \
|
|
|
|
|
int __scope_level = level; \
|
2020-07-05 17:51:04 -06:00
|
|
|
int __scope_task = 0; \
|
2020-08-19 06:37:23 -06:00
|
|
|
ast_debug(__scope_level, " " __VA_ARGS__); \
|
2020-07-05 17:51:04 -06:00
|
|
|
if (TRACE_ATLEAST(level)) { \
|
2021-10-28 09:28:57 +02:00
|
|
|
__ast_trace(_A_, AST_TRACE_INDENT_INC_AFTER, 0, " " __VA_ARGS__); \
|
2020-07-05 17:51:04 -06:00
|
|
|
} \
|
|
|
|
|
|
|
|
|
|
#define SCOPE_ENTER_TASK(level, indent, ...) \
|
|
|
|
|
int __scope_level = level; \
|
|
|
|
|
int __scope_task = 1; \
|
2020-08-19 06:37:23 -06:00
|
|
|
ast_debug(__scope_level, " " __VA_ARGS__); \
|
Scope Trace: Add some new tracing macros and an ast_str helper
Created new SCOPE_ functions that don't depend on RAII_VAR. Besides
generating less code, the use of the explicit SCOPE_EXIT macros
capture the line number where the scope exited. The RAII_VAR
versions can't do that.
* SCOPE_ENTER(level, ...): Like SCOPE_TRACE but doesn't use
RAII_VAR and therefore needs needs one of...
* SCOPE_EXIT(...): Decrements the trace stack counter and optionally
prints a message.
* SCOPE_EXIT_EXPR(__expr, ...): Decrements the trace stack counter,
optionally prints a message, then executes the expression.
SCOPE_EXIT_EXPR(break, "My while got broken\n");
* SCOPE_EXIT_RTN(, ...): Decrements the trace stack counter,
optionally prints a message, then returns without a value.
SCOPE_EXIT_RTN("Bye\n");
* SCOPE_EXIT_RTN_VALUE(__return_value, ...): Decrements the trace
stack counter, optionally prints a message, then returns the value
specified.
SCOPE_EXIT_RTN_VALUE(rc, "Returning with RC: %d\n", rc);
Create an ast_str helper ast_str_tmp() that allocates a temporary
ast_str that can be passed to a function that needs it, then frees
it. This makes using the above macros easier. Example:
SCOPE_ENTER(1, Format Caps 1: %s Format Caps 2: %s\n",
ast_str_tmp(32, ast_format_cap_get_names(cap1, &STR_TMP),
ast_str_tmp(32, ast_format_cap_get_names(cap2, &STR_TMP));
The calls to ast_str_tmp create an ast_str of the specified initial
length which can be referenced as STR_TMP. It then calls the
expression, which must return a char *, ast_strdupa's it, frees
STR_TMP, then returns the ast_strdupa'd string. That string is
freed when the function returns.
Change-Id: I44059b20d55a889aa91440d2f8a590865998be51
2020-06-30 07:56:34 -06:00
|
|
|
if (TRACE_ATLEAST(level)) { \
|
2021-10-28 09:28:57 +02:00
|
|
|
__ast_trace(_A_, AST_TRACE_INDENT_PROVIDED, indent, " " __VA_ARGS__); \
|
Scope Trace: Add some new tracing macros and an ast_str helper
Created new SCOPE_ functions that don't depend on RAII_VAR. Besides
generating less code, the use of the explicit SCOPE_EXIT macros
capture the line number where the scope exited. The RAII_VAR
versions can't do that.
* SCOPE_ENTER(level, ...): Like SCOPE_TRACE but doesn't use
RAII_VAR and therefore needs needs one of...
* SCOPE_EXIT(...): Decrements the trace stack counter and optionally
prints a message.
* SCOPE_EXIT_EXPR(__expr, ...): Decrements the trace stack counter,
optionally prints a message, then executes the expression.
SCOPE_EXIT_EXPR(break, "My while got broken\n");
* SCOPE_EXIT_RTN(, ...): Decrements the trace stack counter,
optionally prints a message, then returns without a value.
SCOPE_EXIT_RTN("Bye\n");
* SCOPE_EXIT_RTN_VALUE(__return_value, ...): Decrements the trace
stack counter, optionally prints a message, then returns the value
specified.
SCOPE_EXIT_RTN_VALUE(rc, "Returning with RC: %d\n", rc);
Create an ast_str helper ast_str_tmp() that allocates a temporary
ast_str that can be passed to a function that needs it, then frees
it. This makes using the above macros easier. Example:
SCOPE_ENTER(1, Format Caps 1: %s Format Caps 2: %s\n",
ast_str_tmp(32, ast_format_cap_get_names(cap1, &STR_TMP),
ast_str_tmp(32, ast_format_cap_get_names(cap2, &STR_TMP));
The calls to ast_str_tmp create an ast_str of the specified initial
length which can be referenced as STR_TMP. It then calls the
expression, which must return a char *, ast_strdupa's it, frees
STR_TMP, then returns the ast_strdupa'd string. That string is
freed when the function returns.
Change-Id: I44059b20d55a889aa91440d2f8a590865998be51
2020-06-30 07:56:34 -06:00
|
|
|
} \
|
|
|
|
|
|
|
|
|
|
/*!
|
|
|
|
|
* \brief Scope Exit
|
|
|
|
|
*
|
|
|
|
|
* \param (optional) A printf style format string
|
|
|
|
|
* \param (optional) Arguments
|
|
|
|
|
*
|
|
|
|
|
* \details
|
|
|
|
|
* This macro can be used at the exit points of a statement block since it just prints the message.
|
|
|
|
|
*/
|
|
|
|
|
#define SCOPE_EXIT(...) \
|
2020-08-19 06:37:23 -06:00
|
|
|
ast_debug(__scope_level, " " __VA_ARGS__); \
|
Scope Trace: Add some new tracing macros and an ast_str helper
Created new SCOPE_ functions that don't depend on RAII_VAR. Besides
generating less code, the use of the explicit SCOPE_EXIT macros
capture the line number where the scope exited. The RAII_VAR
versions can't do that.
* SCOPE_ENTER(level, ...): Like SCOPE_TRACE but doesn't use
RAII_VAR and therefore needs needs one of...
* SCOPE_EXIT(...): Decrements the trace stack counter and optionally
prints a message.
* SCOPE_EXIT_EXPR(__expr, ...): Decrements the trace stack counter,
optionally prints a message, then executes the expression.
SCOPE_EXIT_EXPR(break, "My while got broken\n");
* SCOPE_EXIT_RTN(, ...): Decrements the trace stack counter,
optionally prints a message, then returns without a value.
SCOPE_EXIT_RTN("Bye\n");
* SCOPE_EXIT_RTN_VALUE(__return_value, ...): Decrements the trace
stack counter, optionally prints a message, then returns the value
specified.
SCOPE_EXIT_RTN_VALUE(rc, "Returning with RC: %d\n", rc);
Create an ast_str helper ast_str_tmp() that allocates a temporary
ast_str that can be passed to a function that needs it, then frees
it. This makes using the above macros easier. Example:
SCOPE_ENTER(1, Format Caps 1: %s Format Caps 2: %s\n",
ast_str_tmp(32, ast_format_cap_get_names(cap1, &STR_TMP),
ast_str_tmp(32, ast_format_cap_get_names(cap2, &STR_TMP));
The calls to ast_str_tmp create an ast_str of the specified initial
length which can be referenced as STR_TMP. It then calls the
expression, which must return a char *, ast_strdupa's it, frees
STR_TMP, then returns the ast_strdupa'd string. That string is
freed when the function returns.
Change-Id: I44059b20d55a889aa91440d2f8a590865998be51
2020-06-30 07:56:34 -06:00
|
|
|
if (TRACE_ATLEAST(__scope_level)) { \
|
2021-10-28 09:28:57 +02:00
|
|
|
__ast_trace(_A_, AST_TRACE_INDENT_DEC_BEFORE, 0, " " __VA_ARGS__); \
|
2020-07-05 17:51:04 -06:00
|
|
|
if (__scope_task) { \
|
|
|
|
|
_ast_trace_set_indent(0); \
|
|
|
|
|
} \
|
Scope Trace: Add some new tracing macros and an ast_str helper
Created new SCOPE_ functions that don't depend on RAII_VAR. Besides
generating less code, the use of the explicit SCOPE_EXIT macros
capture the line number where the scope exited. The RAII_VAR
versions can't do that.
* SCOPE_ENTER(level, ...): Like SCOPE_TRACE but doesn't use
RAII_VAR and therefore needs needs one of...
* SCOPE_EXIT(...): Decrements the trace stack counter and optionally
prints a message.
* SCOPE_EXIT_EXPR(__expr, ...): Decrements the trace stack counter,
optionally prints a message, then executes the expression.
SCOPE_EXIT_EXPR(break, "My while got broken\n");
* SCOPE_EXIT_RTN(, ...): Decrements the trace stack counter,
optionally prints a message, then returns without a value.
SCOPE_EXIT_RTN("Bye\n");
* SCOPE_EXIT_RTN_VALUE(__return_value, ...): Decrements the trace
stack counter, optionally prints a message, then returns the value
specified.
SCOPE_EXIT_RTN_VALUE(rc, "Returning with RC: %d\n", rc);
Create an ast_str helper ast_str_tmp() that allocates a temporary
ast_str that can be passed to a function that needs it, then frees
it. This makes using the above macros easier. Example:
SCOPE_ENTER(1, Format Caps 1: %s Format Caps 2: %s\n",
ast_str_tmp(32, ast_format_cap_get_names(cap1, &STR_TMP),
ast_str_tmp(32, ast_format_cap_get_names(cap2, &STR_TMP));
The calls to ast_str_tmp create an ast_str of the specified initial
length which can be referenced as STR_TMP. It then calls the
expression, which must return a char *, ast_strdupa's it, frees
STR_TMP, then returns the ast_strdupa'd string. That string is
freed when the function returns.
Change-Id: I44059b20d55a889aa91440d2f8a590865998be51
2020-06-30 07:56:34 -06:00
|
|
|
} \
|
|
|
|
|
|
|
|
|
|
/*!
|
|
|
|
|
* \brief Scope Exit with expression
|
|
|
|
|
*
|
|
|
|
|
* \param __expr An expression to execute after printing the message
|
|
|
|
|
* \param (optional) A printf style format string
|
|
|
|
|
* \param (optional) Arguments
|
|
|
|
|
*
|
|
|
|
|
* \details
|
|
|
|
|
* Handy for getting out of or continuing loops.
|
|
|
|
|
*
|
2021-11-12 20:17:20 +01:00
|
|
|
* \code
|
Scope Trace: Add some new tracing macros and an ast_str helper
Created new SCOPE_ functions that don't depend on RAII_VAR. Besides
generating less code, the use of the explicit SCOPE_EXIT macros
capture the line number where the scope exited. The RAII_VAR
versions can't do that.
* SCOPE_ENTER(level, ...): Like SCOPE_TRACE but doesn't use
RAII_VAR and therefore needs needs one of...
* SCOPE_EXIT(...): Decrements the trace stack counter and optionally
prints a message.
* SCOPE_EXIT_EXPR(__expr, ...): Decrements the trace stack counter,
optionally prints a message, then executes the expression.
SCOPE_EXIT_EXPR(break, "My while got broken\n");
* SCOPE_EXIT_RTN(, ...): Decrements the trace stack counter,
optionally prints a message, then returns without a value.
SCOPE_EXIT_RTN("Bye\n");
* SCOPE_EXIT_RTN_VALUE(__return_value, ...): Decrements the trace
stack counter, optionally prints a message, then returns the value
specified.
SCOPE_EXIT_RTN_VALUE(rc, "Returning with RC: %d\n", rc);
Create an ast_str helper ast_str_tmp() that allocates a temporary
ast_str that can be passed to a function that needs it, then frees
it. This makes using the above macros easier. Example:
SCOPE_ENTER(1, Format Caps 1: %s Format Caps 2: %s\n",
ast_str_tmp(32, ast_format_cap_get_names(cap1, &STR_TMP),
ast_str_tmp(32, ast_format_cap_get_names(cap2, &STR_TMP));
The calls to ast_str_tmp create an ast_str of the specified initial
length which can be referenced as STR_TMP. It then calls the
expression, which must return a char *, ast_strdupa's it, frees
STR_TMP, then returns the ast_strdupa'd string. That string is
freed when the function returns.
Change-Id: I44059b20d55a889aa91440d2f8a590865998be51
2020-06-30 07:56:34 -06:00
|
|
|
* while(something) {
|
|
|
|
|
* SCOPE_ENTER(2, "In a while\n");
|
|
|
|
|
* if (something) {
|
|
|
|
|
* SCOPE_EXIT_EXPR(break, "Somethiung broke me\n");
|
|
|
|
|
* } else {
|
2021-10-30 21:04:30 -04:00
|
|
|
* SCOPE_EXIT_EXPR(continue, "Somethiung continued me\n");
|
Scope Trace: Add some new tracing macros and an ast_str helper
Created new SCOPE_ functions that don't depend on RAII_VAR. Besides
generating less code, the use of the explicit SCOPE_EXIT macros
capture the line number where the scope exited. The RAII_VAR
versions can't do that.
* SCOPE_ENTER(level, ...): Like SCOPE_TRACE but doesn't use
RAII_VAR and therefore needs needs one of...
* SCOPE_EXIT(...): Decrements the trace stack counter and optionally
prints a message.
* SCOPE_EXIT_EXPR(__expr, ...): Decrements the trace stack counter,
optionally prints a message, then executes the expression.
SCOPE_EXIT_EXPR(break, "My while got broken\n");
* SCOPE_EXIT_RTN(, ...): Decrements the trace stack counter,
optionally prints a message, then returns without a value.
SCOPE_EXIT_RTN("Bye\n");
* SCOPE_EXIT_RTN_VALUE(__return_value, ...): Decrements the trace
stack counter, optionally prints a message, then returns the value
specified.
SCOPE_EXIT_RTN_VALUE(rc, "Returning with RC: %d\n", rc);
Create an ast_str helper ast_str_tmp() that allocates a temporary
ast_str that can be passed to a function that needs it, then frees
it. This makes using the above macros easier. Example:
SCOPE_ENTER(1, Format Caps 1: %s Format Caps 2: %s\n",
ast_str_tmp(32, ast_format_cap_get_names(cap1, &STR_TMP),
ast_str_tmp(32, ast_format_cap_get_names(cap2, &STR_TMP));
The calls to ast_str_tmp create an ast_str of the specified initial
length which can be referenced as STR_TMP. It then calls the
expression, which must return a char *, ast_strdupa's it, frees
STR_TMP, then returns the ast_strdupa'd string. That string is
freed when the function returns.
Change-Id: I44059b20d55a889aa91440d2f8a590865998be51
2020-06-30 07:56:34 -06:00
|
|
|
* }
|
|
|
|
|
* }
|
2021-11-12 20:17:20 +01:00
|
|
|
* \endcode
|
Scope Trace: Add some new tracing macros and an ast_str helper
Created new SCOPE_ functions that don't depend on RAII_VAR. Besides
generating less code, the use of the explicit SCOPE_EXIT macros
capture the line number where the scope exited. The RAII_VAR
versions can't do that.
* SCOPE_ENTER(level, ...): Like SCOPE_TRACE but doesn't use
RAII_VAR and therefore needs needs one of...
* SCOPE_EXIT(...): Decrements the trace stack counter and optionally
prints a message.
* SCOPE_EXIT_EXPR(__expr, ...): Decrements the trace stack counter,
optionally prints a message, then executes the expression.
SCOPE_EXIT_EXPR(break, "My while got broken\n");
* SCOPE_EXIT_RTN(, ...): Decrements the trace stack counter,
optionally prints a message, then returns without a value.
SCOPE_EXIT_RTN("Bye\n");
* SCOPE_EXIT_RTN_VALUE(__return_value, ...): Decrements the trace
stack counter, optionally prints a message, then returns the value
specified.
SCOPE_EXIT_RTN_VALUE(rc, "Returning with RC: %d\n", rc);
Create an ast_str helper ast_str_tmp() that allocates a temporary
ast_str that can be passed to a function that needs it, then frees
it. This makes using the above macros easier. Example:
SCOPE_ENTER(1, Format Caps 1: %s Format Caps 2: %s\n",
ast_str_tmp(32, ast_format_cap_get_names(cap1, &STR_TMP),
ast_str_tmp(32, ast_format_cap_get_names(cap2, &STR_TMP));
The calls to ast_str_tmp create an ast_str of the specified initial
length which can be referenced as STR_TMP. It then calls the
expression, which must return a char *, ast_strdupa's it, frees
STR_TMP, then returns the ast_strdupa'd string. That string is
freed when the function returns.
Change-Id: I44059b20d55a889aa91440d2f8a590865998be51
2020-06-30 07:56:34 -06:00
|
|
|
*/
|
|
|
|
|
#define SCOPE_EXIT_EXPR(__expr, ...) \
|
2020-08-19 06:37:23 -06:00
|
|
|
ast_debug(__scope_level, " " __VA_ARGS__); \
|
Scope Trace: Add some new tracing macros and an ast_str helper
Created new SCOPE_ functions that don't depend on RAII_VAR. Besides
generating less code, the use of the explicit SCOPE_EXIT macros
capture the line number where the scope exited. The RAII_VAR
versions can't do that.
* SCOPE_ENTER(level, ...): Like SCOPE_TRACE but doesn't use
RAII_VAR and therefore needs needs one of...
* SCOPE_EXIT(...): Decrements the trace stack counter and optionally
prints a message.
* SCOPE_EXIT_EXPR(__expr, ...): Decrements the trace stack counter,
optionally prints a message, then executes the expression.
SCOPE_EXIT_EXPR(break, "My while got broken\n");
* SCOPE_EXIT_RTN(, ...): Decrements the trace stack counter,
optionally prints a message, then returns without a value.
SCOPE_EXIT_RTN("Bye\n");
* SCOPE_EXIT_RTN_VALUE(__return_value, ...): Decrements the trace
stack counter, optionally prints a message, then returns the value
specified.
SCOPE_EXIT_RTN_VALUE(rc, "Returning with RC: %d\n", rc);
Create an ast_str helper ast_str_tmp() that allocates a temporary
ast_str that can be passed to a function that needs it, then frees
it. This makes using the above macros easier. Example:
SCOPE_ENTER(1, Format Caps 1: %s Format Caps 2: %s\n",
ast_str_tmp(32, ast_format_cap_get_names(cap1, &STR_TMP),
ast_str_tmp(32, ast_format_cap_get_names(cap2, &STR_TMP));
The calls to ast_str_tmp create an ast_str of the specified initial
length which can be referenced as STR_TMP. It then calls the
expression, which must return a char *, ast_strdupa's it, frees
STR_TMP, then returns the ast_strdupa'd string. That string is
freed when the function returns.
Change-Id: I44059b20d55a889aa91440d2f8a590865998be51
2020-06-30 07:56:34 -06:00
|
|
|
if (TRACE_ATLEAST(__scope_level)) { \
|
2021-10-28 09:28:57 +02:00
|
|
|
__ast_trace(_A_, AST_TRACE_INDENT_DEC_BEFORE, 0, " " __VA_ARGS__); \
|
2020-07-05 17:51:04 -06:00
|
|
|
if (__scope_task) { \
|
|
|
|
|
_ast_trace_set_indent(0); \
|
|
|
|
|
} \
|
Scope Trace: Add some new tracing macros and an ast_str helper
Created new SCOPE_ functions that don't depend on RAII_VAR. Besides
generating less code, the use of the explicit SCOPE_EXIT macros
capture the line number where the scope exited. The RAII_VAR
versions can't do that.
* SCOPE_ENTER(level, ...): Like SCOPE_TRACE but doesn't use
RAII_VAR and therefore needs needs one of...
* SCOPE_EXIT(...): Decrements the trace stack counter and optionally
prints a message.
* SCOPE_EXIT_EXPR(__expr, ...): Decrements the trace stack counter,
optionally prints a message, then executes the expression.
SCOPE_EXIT_EXPR(break, "My while got broken\n");
* SCOPE_EXIT_RTN(, ...): Decrements the trace stack counter,
optionally prints a message, then returns without a value.
SCOPE_EXIT_RTN("Bye\n");
* SCOPE_EXIT_RTN_VALUE(__return_value, ...): Decrements the trace
stack counter, optionally prints a message, then returns the value
specified.
SCOPE_EXIT_RTN_VALUE(rc, "Returning with RC: %d\n", rc);
Create an ast_str helper ast_str_tmp() that allocates a temporary
ast_str that can be passed to a function that needs it, then frees
it. This makes using the above macros easier. Example:
SCOPE_ENTER(1, Format Caps 1: %s Format Caps 2: %s\n",
ast_str_tmp(32, ast_format_cap_get_names(cap1, &STR_TMP),
ast_str_tmp(32, ast_format_cap_get_names(cap2, &STR_TMP));
The calls to ast_str_tmp create an ast_str of the specified initial
length which can be referenced as STR_TMP. It then calls the
expression, which must return a char *, ast_strdupa's it, frees
STR_TMP, then returns the ast_strdupa'd string. That string is
freed when the function returns.
Change-Id: I44059b20d55a889aa91440d2f8a590865998be51
2020-06-30 07:56:34 -06:00
|
|
|
} \
|
|
|
|
|
__expr
|
|
|
|
|
|
|
|
|
|
/*!
|
|
|
|
|
* \brief Scope Exit with return
|
|
|
|
|
*
|
|
|
|
|
* \param (optional) A printf style format string
|
|
|
|
|
* \param (optional) Arguments
|
|
|
|
|
*
|
|
|
|
|
* \details
|
|
|
|
|
* This macro can be used at the exit points of a function when no value
|
|
|
|
|
* needs to be returned.
|
|
|
|
|
*/
|
|
|
|
|
#define SCOPE_EXIT_RTN(...) \
|
2020-08-19 06:37:23 -06:00
|
|
|
ast_debug(__scope_level, " " __VA_ARGS__); \
|
Scope Trace: Add some new tracing macros and an ast_str helper
Created new SCOPE_ functions that don't depend on RAII_VAR. Besides
generating less code, the use of the explicit SCOPE_EXIT macros
capture the line number where the scope exited. The RAII_VAR
versions can't do that.
* SCOPE_ENTER(level, ...): Like SCOPE_TRACE but doesn't use
RAII_VAR and therefore needs needs one of...
* SCOPE_EXIT(...): Decrements the trace stack counter and optionally
prints a message.
* SCOPE_EXIT_EXPR(__expr, ...): Decrements the trace stack counter,
optionally prints a message, then executes the expression.
SCOPE_EXIT_EXPR(break, "My while got broken\n");
* SCOPE_EXIT_RTN(, ...): Decrements the trace stack counter,
optionally prints a message, then returns without a value.
SCOPE_EXIT_RTN("Bye\n");
* SCOPE_EXIT_RTN_VALUE(__return_value, ...): Decrements the trace
stack counter, optionally prints a message, then returns the value
specified.
SCOPE_EXIT_RTN_VALUE(rc, "Returning with RC: %d\n", rc);
Create an ast_str helper ast_str_tmp() that allocates a temporary
ast_str that can be passed to a function that needs it, then frees
it. This makes using the above macros easier. Example:
SCOPE_ENTER(1, Format Caps 1: %s Format Caps 2: %s\n",
ast_str_tmp(32, ast_format_cap_get_names(cap1, &STR_TMP),
ast_str_tmp(32, ast_format_cap_get_names(cap2, &STR_TMP));
The calls to ast_str_tmp create an ast_str of the specified initial
length which can be referenced as STR_TMP. It then calls the
expression, which must return a char *, ast_strdupa's it, frees
STR_TMP, then returns the ast_strdupa'd string. That string is
freed when the function returns.
Change-Id: I44059b20d55a889aa91440d2f8a590865998be51
2020-06-30 07:56:34 -06:00
|
|
|
if (TRACE_ATLEAST(__scope_level)) { \
|
2021-10-28 09:28:57 +02:00
|
|
|
__ast_trace(_A_, AST_TRACE_INDENT_DEC_BEFORE, 0, " " __VA_ARGS__); \
|
2020-07-05 17:51:04 -06:00
|
|
|
if (__scope_task) { \
|
|
|
|
|
_ast_trace_set_indent(0); \
|
|
|
|
|
} \
|
Scope Trace: Add some new tracing macros and an ast_str helper
Created new SCOPE_ functions that don't depend on RAII_VAR. Besides
generating less code, the use of the explicit SCOPE_EXIT macros
capture the line number where the scope exited. The RAII_VAR
versions can't do that.
* SCOPE_ENTER(level, ...): Like SCOPE_TRACE but doesn't use
RAII_VAR and therefore needs needs one of...
* SCOPE_EXIT(...): Decrements the trace stack counter and optionally
prints a message.
* SCOPE_EXIT_EXPR(__expr, ...): Decrements the trace stack counter,
optionally prints a message, then executes the expression.
SCOPE_EXIT_EXPR(break, "My while got broken\n");
* SCOPE_EXIT_RTN(, ...): Decrements the trace stack counter,
optionally prints a message, then returns without a value.
SCOPE_EXIT_RTN("Bye\n");
* SCOPE_EXIT_RTN_VALUE(__return_value, ...): Decrements the trace
stack counter, optionally prints a message, then returns the value
specified.
SCOPE_EXIT_RTN_VALUE(rc, "Returning with RC: %d\n", rc);
Create an ast_str helper ast_str_tmp() that allocates a temporary
ast_str that can be passed to a function that needs it, then frees
it. This makes using the above macros easier. Example:
SCOPE_ENTER(1, Format Caps 1: %s Format Caps 2: %s\n",
ast_str_tmp(32, ast_format_cap_get_names(cap1, &STR_TMP),
ast_str_tmp(32, ast_format_cap_get_names(cap2, &STR_TMP));
The calls to ast_str_tmp create an ast_str of the specified initial
length which can be referenced as STR_TMP. It then calls the
expression, which must return a char *, ast_strdupa's it, frees
STR_TMP, then returns the ast_strdupa'd string. That string is
freed when the function returns.
Change-Id: I44059b20d55a889aa91440d2f8a590865998be51
2020-06-30 07:56:34 -06:00
|
|
|
} \
|
|
|
|
|
return
|
|
|
|
|
|
|
|
|
|
/*!
|
|
|
|
|
* \brief Scope Exit with return value
|
|
|
|
|
*
|
|
|
|
|
* \param __return_value The return value
|
|
|
|
|
* \param (optional) A printf style format string
|
|
|
|
|
* \param (optional) Arguments
|
|
|
|
|
*
|
|
|
|
|
* \details
|
|
|
|
|
* This macro can be used at the exit points of a function when a value
|
|
|
|
|
* needs to be returned.
|
|
|
|
|
*/
|
|
|
|
|
#define SCOPE_EXIT_RTN_VALUE(__return_value, ...) \
|
2020-08-19 06:37:23 -06:00
|
|
|
ast_debug(__scope_level, " " __VA_ARGS__); \
|
Scope Trace: Add some new tracing macros and an ast_str helper
Created new SCOPE_ functions that don't depend on RAII_VAR. Besides
generating less code, the use of the explicit SCOPE_EXIT macros
capture the line number where the scope exited. The RAII_VAR
versions can't do that.
* SCOPE_ENTER(level, ...): Like SCOPE_TRACE but doesn't use
RAII_VAR and therefore needs needs one of...
* SCOPE_EXIT(...): Decrements the trace stack counter and optionally
prints a message.
* SCOPE_EXIT_EXPR(__expr, ...): Decrements the trace stack counter,
optionally prints a message, then executes the expression.
SCOPE_EXIT_EXPR(break, "My while got broken\n");
* SCOPE_EXIT_RTN(, ...): Decrements the trace stack counter,
optionally prints a message, then returns without a value.
SCOPE_EXIT_RTN("Bye\n");
* SCOPE_EXIT_RTN_VALUE(__return_value, ...): Decrements the trace
stack counter, optionally prints a message, then returns the value
specified.
SCOPE_EXIT_RTN_VALUE(rc, "Returning with RC: %d\n", rc);
Create an ast_str helper ast_str_tmp() that allocates a temporary
ast_str that can be passed to a function that needs it, then frees
it. This makes using the above macros easier. Example:
SCOPE_ENTER(1, Format Caps 1: %s Format Caps 2: %s\n",
ast_str_tmp(32, ast_format_cap_get_names(cap1, &STR_TMP),
ast_str_tmp(32, ast_format_cap_get_names(cap2, &STR_TMP));
The calls to ast_str_tmp create an ast_str of the specified initial
length which can be referenced as STR_TMP. It then calls the
expression, which must return a char *, ast_strdupa's it, frees
STR_TMP, then returns the ast_strdupa'd string. That string is
freed when the function returns.
Change-Id: I44059b20d55a889aa91440d2f8a590865998be51
2020-06-30 07:56:34 -06:00
|
|
|
if (TRACE_ATLEAST(__scope_level)) { \
|
2021-10-28 09:28:57 +02:00
|
|
|
__ast_trace(_A_, AST_TRACE_INDENT_DEC_BEFORE, 0, " " __VA_ARGS__); \
|
2020-07-05 17:51:04 -06:00
|
|
|
if (__scope_task) { \
|
|
|
|
|
_ast_trace_set_indent(0); \
|
|
|
|
|
} \
|
Scope Trace: Add some new tracing macros and an ast_str helper
Created new SCOPE_ functions that don't depend on RAII_VAR. Besides
generating less code, the use of the explicit SCOPE_EXIT macros
capture the line number where the scope exited. The RAII_VAR
versions can't do that.
* SCOPE_ENTER(level, ...): Like SCOPE_TRACE but doesn't use
RAII_VAR and therefore needs needs one of...
* SCOPE_EXIT(...): Decrements the trace stack counter and optionally
prints a message.
* SCOPE_EXIT_EXPR(__expr, ...): Decrements the trace stack counter,
optionally prints a message, then executes the expression.
SCOPE_EXIT_EXPR(break, "My while got broken\n");
* SCOPE_EXIT_RTN(, ...): Decrements the trace stack counter,
optionally prints a message, then returns without a value.
SCOPE_EXIT_RTN("Bye\n");
* SCOPE_EXIT_RTN_VALUE(__return_value, ...): Decrements the trace
stack counter, optionally prints a message, then returns the value
specified.
SCOPE_EXIT_RTN_VALUE(rc, "Returning with RC: %d\n", rc);
Create an ast_str helper ast_str_tmp() that allocates a temporary
ast_str that can be passed to a function that needs it, then frees
it. This makes using the above macros easier. Example:
SCOPE_ENTER(1, Format Caps 1: %s Format Caps 2: %s\n",
ast_str_tmp(32, ast_format_cap_get_names(cap1, &STR_TMP),
ast_str_tmp(32, ast_format_cap_get_names(cap2, &STR_TMP));
The calls to ast_str_tmp create an ast_str of the specified initial
length which can be referenced as STR_TMP. It then calls the
expression, which must return a char *, ast_strdupa's it, frees
STR_TMP, then returns the ast_strdupa'd string. That string is
freed when the function returns.
Change-Id: I44059b20d55a889aa91440d2f8a590865998be51
2020-06-30 07:56:34 -06:00
|
|
|
} \
|
|
|
|
|
return(__return_value)
|
|
|
|
|
|
2020-08-19 06:37:23 -06:00
|
|
|
#else /* AST_DEVMODE */
|
|
|
|
|
#define ast_trace_raw(level, indent_type, ...) \
|
|
|
|
|
ast_debug(level < 0 ? __scope_level : level, " " __VA_ARGS__)
|
|
|
|
|
|
|
|
|
|
#define ast_trace(level, ...) \
|
|
|
|
|
ast_debug(level < 0 ? __scope_level : level, " " __VA_ARGS__)
|
|
|
|
|
|
2020-07-05 17:51:04 -06:00
|
|
|
#define ast_trace_get_indent() (0)
|
|
|
|
|
#define ast_trace_set_indent(indent)
|
|
|
|
|
#define ast_trace_inc_indent()
|
|
|
|
|
#define ast_trace_dec_indent()
|
Scope Trace: Add some new tracing macros and an ast_str helper
Created new SCOPE_ functions that don't depend on RAII_VAR. Besides
generating less code, the use of the explicit SCOPE_EXIT macros
capture the line number where the scope exited. The RAII_VAR
versions can't do that.
* SCOPE_ENTER(level, ...): Like SCOPE_TRACE but doesn't use
RAII_VAR and therefore needs needs one of...
* SCOPE_EXIT(...): Decrements the trace stack counter and optionally
prints a message.
* SCOPE_EXIT_EXPR(__expr, ...): Decrements the trace stack counter,
optionally prints a message, then executes the expression.
SCOPE_EXIT_EXPR(break, "My while got broken\n");
* SCOPE_EXIT_RTN(, ...): Decrements the trace stack counter,
optionally prints a message, then returns without a value.
SCOPE_EXIT_RTN("Bye\n");
* SCOPE_EXIT_RTN_VALUE(__return_value, ...): Decrements the trace
stack counter, optionally prints a message, then returns the value
specified.
SCOPE_EXIT_RTN_VALUE(rc, "Returning with RC: %d\n", rc);
Create an ast_str helper ast_str_tmp() that allocates a temporary
ast_str that can be passed to a function that needs it, then frees
it. This makes using the above macros easier. Example:
SCOPE_ENTER(1, Format Caps 1: %s Format Caps 2: %s\n",
ast_str_tmp(32, ast_format_cap_get_names(cap1, &STR_TMP),
ast_str_tmp(32, ast_format_cap_get_names(cap2, &STR_TMP));
The calls to ast_str_tmp create an ast_str of the specified initial
length which can be referenced as STR_TMP. It then calls the
expression, which must return a char *, ast_strdupa's it, frees
STR_TMP, then returns the ast_strdupa'd string. That string is
freed when the function returns.
Change-Id: I44059b20d55a889aa91440d2f8a590865998be51
2020-06-30 07:56:34 -06:00
|
|
|
#define SCOPE_TRACE(__level, ...)
|
2020-08-19 06:37:23 -06:00
|
|
|
|
|
|
|
|
#define SCOPE_ENTER(level, ...) \
|
|
|
|
|
int __scope_level = level; \
|
|
|
|
|
ast_debug(level, " " __VA_ARGS__)
|
|
|
|
|
|
|
|
|
|
#define SCOPE_ENTER_TASK(level, indent, ...) \
|
|
|
|
|
int __scope_level = level; \
|
|
|
|
|
ast_debug(level, " " __VA_ARGS__)
|
|
|
|
|
|
|
|
|
|
#define SCOPE_EXIT(...) \
|
|
|
|
|
ast_debug(__scope_level, " " __VA_ARGS__)
|
|
|
|
|
|
|
|
|
|
#define SCOPE_EXIT_EXPR(__expr, ...) \
|
|
|
|
|
ast_debug(__scope_level, " " __VA_ARGS__); \
|
|
|
|
|
__expr
|
|
|
|
|
|
|
|
|
|
#define SCOPE_EXIT_RTN(...) \
|
|
|
|
|
ast_debug(__scope_level, " " __VA_ARGS__); \
|
|
|
|
|
return
|
|
|
|
|
|
|
|
|
|
#define SCOPE_EXIT_RTN_VALUE(__return_value, ...) \
|
|
|
|
|
ast_debug(__scope_level, " " __VA_ARGS__); \
|
|
|
|
|
return __return_value
|
|
|
|
|
|
|
|
|
|
#endif /* AST_DEVMODE */
|
|
|
|
|
|
|
|
|
|
/*!
|
|
|
|
|
* The following macros will print log messages before running
|
|
|
|
|
* the associated SCOPE_ macro.
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
#define SCOPE_EXIT_LOG(__log_level, ...) \
|
|
|
|
|
({ \
|
|
|
|
|
ast_log(__log_level, " " __VA_ARGS__); \
|
|
|
|
|
SCOPE_EXIT(" " __VA_ARGS__); \
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
#define SCOPE_EXIT_LOG_RTN(__log_level, ...) \
|
|
|
|
|
({ \
|
|
|
|
|
ast_log(__log_level, " " __VA_ARGS__); \
|
|
|
|
|
SCOPE_EXIT_RTN(" " __VA_ARGS__); \
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
#define SCOPE_EXIT_LOG_RTN_VALUE(__value, __log_level, ...) \
|
|
|
|
|
({ \
|
|
|
|
|
ast_log(__log_level, " " __VA_ARGS__); \
|
|
|
|
|
SCOPE_EXIT_RTN_VALUE(__value, " " __VA_ARGS__); \
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
#define SCOPE_EXIT_LOG_EXPR(__expr, __log_level, ...) \
|
|
|
|
|
({ \
|
|
|
|
|
ast_log(__log_level, " " __VA_ARGS__); \
|
|
|
|
|
SCOPE_EXIT_EXPR(__expr, " " __VA_ARGS__); \
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
#define ast_trace_log(__level, __log_level, ...) \
|
|
|
|
|
({ \
|
|
|
|
|
ast_log(__log_level, " " __VA_ARGS__); \
|
|
|
|
|
ast_trace(__level < 0 ? __scope_level : __level, " " __VA_ARGS__); \
|
|
|
|
|
})
|
|
|
|
|
|
2020-05-14 12:24:19 -06:00
|
|
|
|
1999-10-27 00:56:38 +00:00
|
|
|
#if defined(__cplusplus) || defined(c_plusplus)
|
|
|
|
|
}
|
|
|
|
|
#endif
|
|
|
|
|
|
2005-08-30 18:32:10 +00:00
|
|
|
#endif /* _ASTERISK_LOGGER_H */
|