countries-laravel icon indicating copy to clipboard operation
countries-laravel copied to clipboard

Laravel 5.6 causes " Call to undefined method Monolog\Logger::listen()"

Open DesmondPang opened this issue 7 years ago • 11 comments
trafficstars

I installed it on Laravel 5.6. It gives "Call to undefined method Monolog\Logger::listen()" error

vendor/laravel/framework/src/Illuminate/Log/LogManager.php

     * @param array  $context
     *
     * @return void
     */
    public function log($level, $message, array $context = [])
    {
        return $this->driver()->log($level, $message, $context);
    }
 
    /**
     * Dynamically call the default driver instance.
     *
     * @param  string  $method
     * @param  array   $parameters
     * @return mixed
     */
    public function __call($method, $parameters)
    {
        return $this->driver()->$method(...$parameters);
    }
}
 

error on this line return $this->driver()->$method(...$parameters);

DesmondPang avatar Mar 18 '18 03:03 DesmondPang

Getting the same with this.

tomschlick avatar Mar 21 '18 16:03 tomschlick

I'm not able to reproduce it. Could anyone give me a stack trace of this error?

antonioribeiro avatar Mar 21 '18 21:03 antonioribeiro

Unfortunately that's the extent of the error it gives me (1 line stack trace). I'll try digging in a little more over the next day or so.

tomschlick avatar Mar 22 '18 12:03 tomschlick

@antonioribeiro: I experienced the same error, and managed to locate the error to something with debugbar and this plugin.

I can reproduce the error on a completely new Laravel 5.6 installation with debugbar and this repo. To recreate the error, try firstly creating a new Laravel 5.6 installation

laravel new test

then install debugbar:

composer require barryvdh/laravel-debugbar --dev

The application should still work. Now install this package using:

composer require pragmarx/countries-laravel

if you go to the frontpage http://test.test, then you should see the following trace:

Symfony \ Component \ Debug \ Exception \ FatalThrowableError (E_ERROR)
Call to undefined method Monolog\Logger::listen()

I hope this helps debugging.

EDIT: I would like to draw your attention to the answer by @kylescousin: https://github.com/barryvdh/laravel-debugbar/issues/812#issuecomment-379248148

From the 5.6 upgrade guide https://laravel.com/docs/5.6/upgrade: "All logging configuration is now housed in its own config/logging.php configuration file. You should place a copy of the default configuration file in your own application and tweak the settings based on your application's needs."

bilfeldt avatar Apr 06 '18 20:04 bilfeldt

Yeah this package causes the error if installed with the debug bar. Removing either package seems to resolve it.

lionslair avatar Apr 13 '18 05:04 lionslair

Anyone had success resolving this?

lionslair avatar Apr 30 '18 03:04 lionslair

It's almost certainly just Laravel Debugbar – see my quick fix here.

corazzi avatar May 02 '18 19:05 corazzi

Steps to reproduce on a clean Laravel install.

composer create-project --prefer-dist laravel/laravel countries

In AppServiceProvider::boot() add

dd([
    'LogManager' => get_class($this->app['log']),
    'Driver'     => get_class($this->app['log']->driver())
]);

Run php artisan and notice by default it should print out.

array:2 [
  "LogManager" => "Illuminate\Log\LogManager"
  "Driver" => "Illuminate\Log\Logger"
]

Install this package (or the standard one) composer require pragmarx/countries-laravel

Run php artisan again

array:2 [
  "LogManager" => "Illuminate\Log\LogManager"
  "Driver" => "Monolog\Logger"
]

I can't figure out what's causing it but for some reason the log driver gets changed when this package is installed. Logging was changed in 5.6 so Illuminate\Log\Logger is a wrapper. This then breaks any other packages or Laravel itself if they want to access the logger.

mnightingale avatar Jul 05 '18 12:07 mnightingale

https://github.com/antonioribeiro/countries-laravel/issues/6#issuecomment-386090515

was a fine workaround for me.

alariva avatar Jul 23 '18 09:07 alariva

As per https://github.com/antonioribeiro/countries-laravel/issues/6#issuecomment-407003331 worked fine on local env.

However, I'm still getting same error on prd where it's supposed there would be no conflict with barryvdh/laravel-debugbar, also having it's config on logs => false.

$ composer install --no-dev
Loading composer repositories with package information
Installing dependencies from lock file
Nothing to install or update
Generating optimized autoload files
> Illuminate\Foundation\ComposerScripts::postAutoloadDump
> @php artisan package:discover

In LogManager.php line 609:
                                                     
  Call to undefined method Monolog\Logger::listen()  
                                                     

Script @php artisan package:discover handling the post-autoload-dump event returned with error code 1

alariva avatar Jul 23 '18 13:07 alariva

Have the same problem as @alariva on production.

denitsa-md avatar Jul 24 '18 06:07 denitsa-md