lumen 日志按天生成文件

2021-01-18 11:12:58 浏览数 (2)

声明Provider
代码语言:javascript复制
<?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中添加

代码语言:javascript复制
$app->register(命名空间ProvidersLogServiceProvider::class);

打赏赞微海报分享

0 人点赞