0

我在bootstrap/app.php文件中使用了这个功能

$app->configureMonologUsing(function ($monolog) {
 $maxFiles = 7;

 $rotatingLogHandler = (new Monolog\Handler\RotatingFileHandler(storage_path('logs/lumen.log'), $maxFiles))
    ->setFormatter(new Monolog\Formatter\LineFormatter(null, null, true, true));

 $monolog->setHandlers([$rotatingLogHandler]);

 return $monolog;
 });

它正在根据日期生成日志文件。但是每次我必须更改日志文件路径时,我都想为用户明智地生成日志文件,例如,

storeage/logs/USERID/DATEWISELOG.log

而不是创建日志文件为storeage/logs/DATEWISELOG.log

logfile是否可以根据用户生成路径?

4

2 回答 2

0

终于我得到了答案

引导程序/app.php

$app->configureMonologUsing(function ($monolog) {
 $maxFiles = 7;

 $rotatingLogHandler = (new Monolog\Handler\RotatingFileHandler(config("path"), $maxFiles))
    ->setFormatter(new Monolog\Formatter\LineFormatter(null, null, true, true));

 $monolog->setHandlers([$rotatingLogHandler]);

 return $monolog;
 });

当用户登录时,如下更改 config("path") 的值,

config(['path' => storage_path('logs')."/".$user->user_id."/lumen.log"]);

它将在运行时更改 config 的值。

于 2019-10-03T11:57:57.697 回答
0

由于您并不总是拥有经过身份验证的用户,因此在技术上会很困难。

然后日志处理程序在大多数提供程序(包括数据库之一)之前被引导,因此很难使其依赖于登录用户。

除非你自己破解一些东西。

于 2019-10-03T09:02:17.463 回答