Lumen-framework: 5.6 Logging Broken

Created on 25 Apr 2018  路  2Comments  路  Source: laravel/lumen-framework

  • Lumen Version: 5.6.3
  • PHP Version: 7.2.3
  • Database Driver & Version: N/A

Description:

Migrating from 5.5.* to 5.6.3 has resulted in logging not reading my configuration files. It is currently only logging to storage/logs/laravel.log - not even lumen.log.

I was previously using configureMonologUsing() and have attempted to convert everything into config/logging.php. That didn't work, so I took the base Lumen logging config and it still would not work. Note that this is running in a Docker container (which shouldn't matter). The container is why I have extra logging setup - I was logging to stderr in order to utilize the docker logs command.

Here's my current config/logging.php:

return [
    'channels' => [
        'stack' => [
            'driver' => 'stack',
            'channels' => [
                'burp'
            ]
        ],
        'burp' => [
            'driver' => 'single',
            'path' => '/tmp/x.txt',
            'level' => 'debug'
        ]/*,
        'daily' => [
            'driver' => 'daily',
            'path' => storage_path('logs/lumen.log'),
            'level' => 'debug',
            'days' => 7
        ],
        'syslog' => [
            'driver' => 'syslog',
            'level' => 'debug'
        ],
        'errorlog' => [
            'driver' => 'errorlog',
            'level' => 'debug'
        ]*/
    ]
];

I don't get anything in /tmp/x.txt. I've tried adding $app->configure('logging'); to my bootstrap/app.php to no avail.

Just for testing I set this in my .env file:

LOG_CHANNEL=burp

Steps To Reproduce:

  • Upgrade to Lumen 5.6.3
  • Run inside a Docker container
  • Use the config I have posted above
  • Run the env I posted above

Most helpful comment

I was having the same issue, can you try using the logging.php below?

<?php

use Monolog\Handler\StreamHandler;

return [

    /*
    |--------------------------------------------------------------------------
    | Default Log Channel
    |--------------------------------------------------------------------------
    |
    | This option defines the default log channel that gets used when writing
    | messages to the logs. The name specified in this option should match
    | one of the channels defined in the "channels" configuration array.
    |
    */

    'default' => env('LOG_CHANNEL', 'stack'),

    /*
    |--------------------------------------------------------------------------
    | Log Channels
    |--------------------------------------------------------------------------
    |
    | Here you may configure the log channels for your application. Out of
    | the box, Laravel uses the Monolog PHP logging library. This gives
    | you a variety of powerful log handlers / formatters to utilize.
    |
    | Available Drivers: "single", "daily", "slack", "syslog",
    |                    "errorlog", "custom", "stack"
    |
    */

    'channels' => [
        'stack' => [
            'driver' => 'stack',
            'channels' => ['single'],
        ],

        'single' => [
            'driver' => 'single',
            'path' => storage_path('logs/lumen.log'),
            'level' => 'debug',
        ],

        'daily' => [
            'driver' => 'daily',
            'path' => storage_path('logs/lumen.log'),
            'level' => 'debug',
            'days' => 7,
        ],

        'slack' => [
            'driver' => 'slack',
            'url' => env('LOG_SLACK_WEBHOOK_URL'),
            'username' => 'Lumen Log',
            'emoji' => ':boom:',
            'level' => 'critical',
        ],

        'stderr' => [
            'driver' => 'monolog',
            'handler' => StreamHandler::class,
            'with' => [
                'stream' => 'php://stderr',
            ],
        ],

        'syslog' => [
            'driver' => 'syslog',
            'level' => 'debug',
        ],

        'errorlog' => [
            'driver' => 'errorlog',
            'level' => 'debug',
        ],
    ],

];

Note in your logging.php the default key is missing as well as the stderr one in the channels array

All 2 comments

I was having the same issue, can you try using the logging.php below?

<?php

use Monolog\Handler\StreamHandler;

return [

    /*
    |--------------------------------------------------------------------------
    | Default Log Channel
    |--------------------------------------------------------------------------
    |
    | This option defines the default log channel that gets used when writing
    | messages to the logs. The name specified in this option should match
    | one of the channels defined in the "channels" configuration array.
    |
    */

    'default' => env('LOG_CHANNEL', 'stack'),

    /*
    |--------------------------------------------------------------------------
    | Log Channels
    |--------------------------------------------------------------------------
    |
    | Here you may configure the log channels for your application. Out of
    | the box, Laravel uses the Monolog PHP logging library. This gives
    | you a variety of powerful log handlers / formatters to utilize.
    |
    | Available Drivers: "single", "daily", "slack", "syslog",
    |                    "errorlog", "custom", "stack"
    |
    */

    'channels' => [
        'stack' => [
            'driver' => 'stack',
            'channels' => ['single'],
        ],

        'single' => [
            'driver' => 'single',
            'path' => storage_path('logs/lumen.log'),
            'level' => 'debug',
        ],

        'daily' => [
            'driver' => 'daily',
            'path' => storage_path('logs/lumen.log'),
            'level' => 'debug',
            'days' => 7,
        ],

        'slack' => [
            'driver' => 'slack',
            'url' => env('LOG_SLACK_WEBHOOK_URL'),
            'username' => 'Lumen Log',
            'emoji' => ':boom:',
            'level' => 'critical',
        ],

        'stderr' => [
            'driver' => 'monolog',
            'handler' => StreamHandler::class,
            'with' => [
                'stream' => 'php://stderr',
            ],
        ],

        'syslog' => [
            'driver' => 'syslog',
            'level' => 'debug',
        ],

        'errorlog' => [
            'driver' => 'errorlog',
            'level' => 'debug',
        ],
    ],

];

Note in your logging.php the default key is missing as well as the stderr one in the channels array

Yeah, I think the _default_ key missing was my problem. This is now working.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

jampack picture jampack  路  3Comments

gfazioli picture gfazioli  路  5Comments

rmblstrp picture rmblstrp  路  5Comments

dunice picture dunice  路  3Comments

maglor picture maglor  路  3Comments