Lumen Daily Logs

匿名 (未验证) 提交于 2019-12-03 02:33:02

问题:

I want to add to my Lumen project a daily Log.

I try this in the app.php (Folder Bootstrap/)

$logFile = 'laravel.log';  Log::useDailyFiles(storage_path().'/logs/'.$logFile); 

But this set me that error

Call to undefined method Monolog\logger::useDailyFiles()

Any help I appreciate...Thanks

回答1:

If you look at the framework source code here you can see that it will not do daily logs, but rather write to a single log file lumen.log. There is a public method available configureMonologUsing seen here and referenced here that you can use to override the default behavior without extending the Application.

Lumen just sets a handler to monolog, so another good solution is you could do this:

<?php  namespace App\Providers;  use Illuminate\Support\ServiceProvider; use Monolog\Formatter\LineFormatter; use Monolog\Handler\RotatingFileHandler;  class LogServiceProvider extends ServiceProvider {     /**      * Configure logging on boot.      *      * @return void      */     public function boot()     {         $maxFiles = 5;          $handlers[] = (new RotatingFileHandler(storage_path("logs/lumen.log"), $maxFiles))             ->setFormatter(new LineFormatter(null, null, true, true));          $this->app['log']->setHandlers($handlers);     }      /**      * Register the log service.      *      * @return void      */     public function register()     {         // Log binding already registered in vendor/laravel/lumen-framework/src/Application.php.     } } 

Then don't forget to add the service provider to your Lumen bootstrap/app.php:

$app->register(\App\Providers\LogServiceProvider::class); 


回答2:

This is not necessary as per the lumen documentation:

By default, Lumen is configured to create daily log files for your application which are stored in the storage/logs directory.

So you wouldn't have to change anything.



文章来源: Lumen Daily Logs
标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!