作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
文档说:
By default, Lumen is configured to create daily log files for your application which are stored in the storage/logs directory.
最佳答案
自 this commit有一个 configureMonologUsing 方法。您应该在 bootstrap/app.php 文件中调用此方法
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;
});
<?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()
{
}
}
getMonologHandler
或
registerLogBindings
方法。下面是替换前者的示例。
// This
$app = new Laravel\Lumen\Application(
realpath(__DIR__.'/../')
);
// With this
$app = new App\Application(
realpath(__DIR__.'/../')
);
<?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));
}
}
关于laravel - 流明 (5.1.6) 每日日志,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37342418/
我是一名优秀的程序员,十分优秀!