Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
DesmondPang opened this issue Mar 18, 2018 · 11 comments

Comments

@DesmondPang
Copy link

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);

@tomschlick
Copy link

Getting the same with this.

@antonioribeiro
Copy link
Owner

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

@tomschlick
Copy link

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.

@bilfeldt
Copy link

bilfeldt commented Apr 6, 2018

@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: barryvdh/laravel-debugbar#812 (comment)

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."

@lionslair
Copy link
Contributor

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

@lionslair
Copy link
Contributor

Anyone had success resolving this?

@corazzi
Copy link

corazzi commented May 2, 2018

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

@mnightingale
Copy link

mnightingale commented Jul 5, 2018

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.

@alariva
Copy link

alariva commented Jul 23, 2018

#6 (comment)

was a fine workaround for me.

@alariva
Copy link

alariva commented Jul 23, 2018

As per #6 (comment) 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

@denitsa-md
Copy link

Have the same problem as @alariva on production.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

9 participants