流明日报 [英] Lumen Daily Logs

查看:54
本文介绍了流明日报的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想将流水日志添加到我的Lumen项目中.

I want to add to my Lumen project a daily Log.

我在app.php(Folder Bootstrap/)中尝试

I try this in the app.php (Folder Bootstrap/)

$logFile = 'laravel.log';

Log::useDailyFiles(storage_path().'/logs/'.$logFile);

但这给我带来了那个错误

But this set me that error

调用未定义的方法Monolog \ logger :: useDailyFiles()

Call to undefined method Monolog\logger::useDailyFiles()

任何帮助,我都感激...谢谢

Any help I appreciate...Thanks

推荐答案

如果您查看框架源代码此处并引用了此处在不扩展应用程序的情况下覆盖默认行为.

If you look at the framework source code here you can see that it will not do daily logs, but rather write to a single log file lumen.log. There is a public method available configureMonologUsing seen here and referenced here that you can use to override the default behavior without extending the Application.

Lumen只是将处理程序设置为独白,因此另一个好的解决方案是您可以这样做:

Lumen just sets a handler to monolog, so another good solution is you could do this:

<?php

namespace App\Providers;

use Illuminate\Support\ServiceProvider;
use Monolog\Formatter\LineFormatter;
use Monolog\Handler\RotatingFileHandler;

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

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

然后别忘了将服务提供商添加到您的Lumen bootstrap/app.php:

Then don't forget to add the service provider to your Lumen bootstrap/app.php:

$app->register(\App\Providers\LogServiceProvider::class);

这篇关于流明日报的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆