lumen 日誌按天生成檔案

wd731869706發表於2022-01-12

宣告Provider

<?php

namespace 名稱空間;

use IlluminateSupportServiceProvider;
use MonologFormatterLineFormatter;
use MonologHandlerRotatingFileHandler;

class LogServiceProvider extends ServiceProvider
{
    /**
     * Configure logging on boot.
     *
     * @return void
     */
    public function boot()
    {
        $maxFiles = 0;

        $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.
    }
}

註冊

bootstrapapp.php中新增

$app->register(名稱空間ProvidersLogServiceProvider::class);
本作品採用《CC 協議》,轉載必須註明作者和本文連結

相關文章