With laravel 5.5 we had access to configureMonologUsing()
method in $app which made it possible for things like this in bootstrap/app.php:
$app->configureMonologUsing(function (Monolog\Logger $monolog) {
$processUser = posix_getpwuid(posix_geteuid());
$processName= $processUser['name'];
$filename = storage_path('logs/laravel-' . php_sapi_name() . '-' . $processName . '.log');
$handler = new Monolog\Handler\RotatingFileHandler($filename);
$monolog->pushHandler($handler);
});
Doing this is useful when your app may be called from different contexts (eg CLI/HTTP) with different users (which is desirable) and file rotation. Doing this prevents write errors in case the log file was created by the HTTP user before the CLI one tries to add something in it and vice-versa.
Handling this is otherwise tricky or insecure as it involves to be able to set write perms on files that may not exist yet.
In addition, it's quite handy to have logs separated by contexts as they usually have little in common and it makes it easier to search among them.
Unfortunately, this way of doing things is not possible anymore with laravel 5.6 and I could not (yet) find a way to transparently do so for all file based logging.
Thanks