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
This commit is contained in:
Matt Jordan
2016-05-14 07:24:07 -05:00
parent 7643dc44b2
commit 3522376512
4 changed files with 103 additions and 206 deletions

View File

@@ -195,11 +195,25 @@ int ast_unregister_verbose(void (*verboser)(const char *string)) attribute_warn_
void ast_console_puts(const char *string);
/*!
* \brief log the string to the console, and all attached
* console clients
* \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
*
* \version 1.6.1 added level parameter
*/
void ast_console_puts_mutable(const char *string, int level);
/*!
* \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);
void ast_console_toggle_mute(int fd, int silent);
/*!