Laravel 5 different log levels for development and production

后端 未结 2 1166
[愿得一人]
[愿得一人] 2021-01-02 02:41

I\'m using Laravel 5.1 and trying to set different logging logic for a development and production environment.

Throughout my application I am using the Log

2条回答
  •  醉话见心
    2021-01-02 03:12

    This gist shows a more comfortable answer, as is not dependent on the chosen handler.

    I'm just providing the essential part in an answer here in case the above link gets deleted in some time.

    In the AppServiceProviders' register method:

    /**
    * Register any application services.
    *
    * @return void
    */
    public function register()
    {
        //
        $monolog = Log::getMonolog();
        foreach($monolog->getHandlers() as $handler) {
          $handler->setLevel(Config::get('app.log-level'));
        }
    }
    

    Then just add an additional key to your config/app.php:

    'log-level' => 'info', // or whatever minimum log level you would like.
    

提交回复
热议问题