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