laravel / lumen-framework

The Laravel Lumen Framework.
https://lumen.laravel.com
MIT License
1.48k stars 419 forks source link

LogManager->stack() seems to be broken or passing wrong parameter format #950

Closed ThaDaVos closed 5 years ago

ThaDaVos commented 5 years ago

Description:

I'm trying to use the LogManager->stack() method but I think its broken or I'm passing the wrong format of variables, see example of parameters below:

        Log::stack(['graylog' => [
            'driver' => 'custom',
            'via' => \App\Log\GrayLogLogger::class,
            'graylog' => config('graylog')
        ]], 'graylog');

This example is giving me following error: laravel.EMERGENCY: Unable to create configured logger. Using emergency logger. {"exception":"[object] (ErrorException(code: 0): Illegal offset type at /var/www/html/vendor/illuminate/log/LogManager.php:102)

So I went to take a look inside the source code and I noticed the following call in the createStackDriver method:

        $handlers = collect($config['channels'])->flatMap(function ($channel) {
            return $this->channel($channel)->getHandlers();
        })->all();

When looking at the $this->channel() PHPDoc it looks like it expects a string:

/**
     * Get a log channel instance.
     *
     * @param  string|null  $channel
     * @return mixed
     */

But guess what, it's getting an object instead -> this object is equal to the following:

 [
            'driver' => 'custom',
            'via' => \App\Log\GrayLogLogger::class,
            'graylog' => config('graylog')
        ]

This is the same as the value of the actual channel key shown above.

So it got me thinking, maybe there's something wrong in the source code or maybe I'm passing the wrong thing... I can't figure it out

Steps To Reproduce:

See above

ThaDaVos commented 5 years ago

I followed this answer: https://stackoverflow.com/questions/52469769/create-a-new-laravel-logging-channel-through-serviceprovider

driesvints commented 5 years ago

Glad you found a solution 👍