Laravel Lumen更改日志文件名 [英] Laravel Lumen change log file name

查看:329
本文介绍了Laravel Lumen更改日志文件名的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

流明日志写入/storage/logs,默认情况下命名为lumen.log.如何将文件名更改为xyz.log?

Lumen logs are written to /storage/logs and by default given the name lumen.log. How do I change the file name to say xyz.log?

推荐答案

如注释中所述,日志文件的位置和名称是硬编码的.

As mentioned in comments the location and the name of the log file is hardcoded.

现在,如果出于某些令人信服的原因想要对其进行更改,则可以始终扩展Laravel\Lumen\Application类并覆盖getMonologHandler()方法.

Now if for some compelling reason you want to change it you can always extend Laravel\Lumen\Application class and override getMonologHandler() method.

app文件夹中创建一个看起来像

Create a new file Application.php in app folder that looks like

namespace App;

use Laravel\Lumen\Application as LumenApplication;
use Monolog\Formatter\LineFormatter;
use Monolog\Handler\StreamHandler;
use Monolog\Logger;

class Application extends LumenApplication
{
    protected function getMonologHandler()
    {
        return (new StreamHandler(storage_path(env('APP_LOG_PATH', 'logs/xyz.log')), Logger::DEBUG))
            ->setFormatter(new LineFormatter(null, null, true, true));
    }
}

现在更改

$app = new Laravel\Lumen\Application(

$app = new App\Application(

bootstrap\app.php文件中

现在将您的日志文件命名为xyz.log.您还可以通过定义环境变量APP_LOG_PATH将其更改为所需的任何内容,即通过.env文件

Voila your log file now is called xyz.log. More over you can change it to whatever you want by defining the environment variable APP_LOG_PATH i.e. via .env file

APP_LOG_PATH=logs/abc.log

这篇关于Laravel Lumen更改日志文件名的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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