问题描述
流明日志写入/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更改日志文件名的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!