Lumen-framework: Log configuration doesn't work

Created on 23 Mar 2016  路  2Comments  路  Source: laravel/lumen-framework

In a new project

$ composer create-project --prefer-dist laravel/lumen blog && cd blog

1) enable facades in bootstrap/app.php

2) in app/Http/routes.php add log write

$app->get('/', function () use ($app) {
    \Log::debug('CLUMP 2016!');
    return $app->version();
});

3) check logs are working (run and check log file for the record)

$ ./vendor/bin/phpunit

4) add custom log as advised in docs

$app = new \Laravel\Lumen\Application(
    realpath(__DIR__.'/../')
);

$app->configureMonologUsing(function (\Monolog\Logger $monolog) {
    $handler = new \Monolog\Handler\StreamHandler(storage_path('logs/lumen.log'));
    $handler->setFormatter(new \Monolog\Formatter\LineFormatter(null, null, true, true));
    $monolog->pushHandler($handler);
});
...

5) run tests

$ ./vendor/bin/phpunit

PHPUnit 4.8.24 by Sebastian Bergmann and contributors.

PHP Fatal error: Call to a member function error() on null in /.../blog/vendor/laravel/lumen-framework/src/Exceptions/Handler.php on line 36

Most helpful comment

That's a bug in Lumen documentation. Closure must return $monolog

$app->configureMonologUsing(function (\Monolog\Logger $monolog) {
    $handler = new \Monolog\Handler\StreamHandler(storage_path('logs/lumen.log'));
    $handler->setFormatter(new \Monolog\Formatter\LineFormatter(null, null, true, true));
    $monolog->pushHandler($handler);

    // THIS LINE MUST BE ADDED TO DOCUMENTATION
    return $monolog;
});

All 2 comments

That's a bug in Lumen documentation. Closure must return $monolog

$app->configureMonologUsing(function (\Monolog\Logger $monolog) {
    $handler = new \Monolog\Handler\StreamHandler(storage_path('logs/lumen.log'));
    $handler->setFormatter(new \Monolog\Formatter\LineFormatter(null, null, true, true));
    $monolog->pushHandler($handler);

    // THIS LINE MUST BE ADDED TO DOCUMENTATION
    return $monolog;
});

Thanks. Please send a PR to the docs. ;)

Was this page helpful?
0 / 5 - 0 ratings