Seit this commit gibt es eine configureMonologUsing-Methode. Sie sollten
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;
});
in der Bootstrap/app.php Datei einen Aufruf dieser Methode setzen Sie können einen Service-Provider erstellen, die eine neue rotierende Protokollhandler erstellt und ersetzt dann die Monolog-Handler.
<?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()
{
}
}
Sie könnten auch Anwendung erweitern und ersetzen die getMonologHandler
oder registerLogBindings
Methoden. Unten ist ein Beispiel, das das erstere ersetzt.
in Bootstrap-Ersetzen/start.php
// This
$app = new Laravel\Lumen\Application(
realpath(__DIR__.'/../')
);
// With this
$app = new App\Application(
realpath(__DIR__.'/../')
);
Und schaffen 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));
}
}
Große Antwort @ ben-Swinburne !! Erstellen eines neuen Service Providers funktioniert gut !! – Sangar82