Documentantion says:
By default, Lumen is configured to create daily log files for your application which are stored in the storage/logs directory.
But my application still generating a lumen.log without daily log.
My version: Laravel Framework version Lumen (5.1.6) (Laravel Components 5.1.*) I came from 5.1 installation.
How can generate logs with daily files?
Since this commit there's a configureMonologUsing method. You should place a call to this method in your bootstrap/app.php file
use Monolog\Formatter\LineFormatter;
use Monolog\Handler\RotatingFileHandler;
$app->configureMonologUsing(function ($monolog) {
$maxFiles = 7;
$rotatingLogHandler = (new RotatingFileHandler(storage_path('logs/lumen.log'), $maxFiles))
->setFormatter(new LineFormatter(null, null, true, true));
$monolog->setHandlers([$rotatingLogHandler]);
return $monolog;
});
You can create a service provider which creates a new rotating log handler and then replaces the Monolog handlers.
<?php
namespace App\Providers;
use Illuminate\Support\ServiceProvider;
use Monolog\Formatter\LineFormatter;
use Monolog\Handler\RotatingFileHandler;
class LogServiceProvider extends ServiceProvider
{
public function boot()
{
app('Psr\Log\LoggerInterface')->setHandlers([$this->getRotatingLogHandler()]);
}
public function getRotatingLogHandler($maxFiles = 7)
{
return (new RotatingFileHandler(storage_path('logs/lumen.log'), $maxFiles))
->setFormatter(new LineFormatter(null, null, true, true));
}
public function register()
{
}
}
You could also extend Application and replace the getMonologHandler
or registerLogBindings
methods. Below is an example replacing the former.
Replace in bootstrap/start.php
// This
$app = new Laravel\Lumen\Application(
realpath(__DIR__.'/../')
);
// With this
$app = new App\Application(
realpath(__DIR__.'/../')
);
And create App\Application.php
<?php
namespace App;
use Monolog\Formatter\LineFormatter;
use Monolog\Handler\RotatingFileHandler;
use Laravel\Lumen\Application as LumenApplication;
class Application extends LumenApplication
{
/**
* {@inheritdoc}
*/
protected function getMonologHandler()
{
$maxRotatedFiles = 3
return (new RotatingFileHandler(storage_path('logs/lumen.log'), $maxRotatedFiles))
->setFormatter(new LineFormatter(null, null, true, true));
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With