0

I have used this function in bootstrap/app.php file

$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;
 });

It is working to generate log file based on date. But I want to generate log file user wise for that every time I have to change log file path like,

storeage/logs/USERID/DATEWISELOG.log

Instead of create logfile as storeage/logs/DATEWISELOG.log

Is it possible to generate logfile path based on user?

zlatan
  • 3,346
  • 2
  • 17
  • 35
hetal gohel
  • 335
  • 9
  • 21

2 Answers2

0

Since you dont always have an authenticated user, it would be technically difficult.

Then the log handler is bootstrapped before most of the providers including database one, so it would be very difficult to make it dependent on logged in user.

Unless you hack in something yourself.

N69S
  • 16,110
  • 3
  • 22
  • 36
0

Finally I got my answer

in bootstrap/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;
 });

when user logged in then change the value of config("path") as below,

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

it will change the value of config at run time.

hetal gohel
  • 335
  • 9
  • 21