]> git.ipfire.org Git - thirdparty/asterisk.git/commitdiff
logger.c: Fix default console logging when no logger.conf available.
authorRichard Mudgett <rmudgett@digium.com>
Thu, 18 Oct 2018 00:34:37 +0000 (19:34 -0500)
committerRichard Mudgett <rmudgett@digium.com>
Wed, 24 Oct 2018 22:10:30 +0000 (17:10 -0500)
Default logging was not setup correctly when there was no logger.conf.
This resulted in many expected log messages not actually getting out to
the console.

Change-Id: I542e61c03b2f630ff5327f9de5641d776c6fa70c

main/logger.c

index 89a40f020bd16b39b1f1d3ce8a26317c241d3498..20411ce24771ae5008252256553de2e12631b9c4 100644 (file)
@@ -423,7 +423,8 @@ static struct logchannel *make_logchannel(const char *channel, const char *compo
        return chan;
 }
 
-/* \brief Read config, setup channels.
+/*!
+ * \brief Read config, setup channels.
  * \param locked The logchannels list is locked and this is a reload
  * \param altconf Alternate configuration file to read.
  *
@@ -471,12 +472,11 @@ static int init_logger_chain(int locked, const char *altconf)
 
        /* If no config file, we're fine, set default options. */
        if (!cfg) {
-               if (!(chan = ast_calloc(1, sizeof(*chan) + 1))) {
-                       fprintf(stderr, "Failed to initialize default logging\n");
+               chan = make_logchannel("console", "error,warning,notice,verbose", 0, 0);
+               if (!chan) {
+                       fprintf(stderr, "ERROR: Failed to initialize default logging\n");
                        return -1;
                }
-               chan->type = LOGTYPE_CONSOLE;
-               chan->logmask = (1 << __LOG_WARNING) | (1 << __LOG_NOTICE) | (1 << __LOG_ERROR);
 
                if (!locked) {
                        AST_RWLIST_WRLOCK(&logchannels);
@@ -553,7 +553,8 @@ static int init_logger_chain(int locked, const char *altconf)
        }
        var = ast_variable_browse(cfg, "logfiles");
        for (; var; var = var->next) {
-               if (!(chan = make_logchannel(var->name, var->value, var->lineno, 0))) {
+               chan = make_logchannel(var->name, var->value, var->lineno, 0);
+               if (!chan) {
                        /* Print error message directly to the consoles since the lock is held
                         * and we don't want to unlock with the list partially built */
                        ast_console_puts_mutable("ERROR: Unable to create log channel '", __LOG_ERROR);