* .env
LOG_CHANNEL=daily
LOG_SLACK_WEBHOOK_URL=
LOG_PATH=/storage/logs/lumen.log
LOG_MAXFILE=5
* 参照 pearl/lumen-log-rotate
创建文件 .\app\Providers\LogRotateServiceProvider.php
<?php
namespace App\Providers;
use Monolog\Formatter\LineFormatter;
use Illuminate\Support\ServiceProvider;
use Monolog\Handler\RotatingFileHandler;
class LogRotateServiceProvider extends ServiceProvider
{
/**
* Perform post-registration booting of services.
*
* @return void
*/
public function boot()
{
$handlers[] = (new RotatingFileHandler(env('LOG_PATH', storage_path('logs/lumen.log')), env('LOG_MAXFILE', 5)))
->setFormatter(new LineFormatter("[%datetime%] %channel%.%level_name%: %message% %context% %extra%\n", null, true, true));
$this->app['log']->setHandlers($handlers);
}
}
?>
* 注册服务
.\bootstrap\app.php
+1 line:
$app->register(App\Providers\LogRotateServiceProvider::class);