Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I change the default file permissions for log files created by PHP Monologger?

Laravel documentation shows that you can define custom configurations for your Monologger by placing the following code into your bootstrap/app.php file:

    $app->configureMonologUsing(function($monolog) {
    $monolog->pushHandler();
});

What are the possible custom configurations & syntaxes for them?

I'd like to change the daily log file's default permissions to 664 instead of the default 644, to avoid 'Permission denied' issues in the application.

like image 702
Anamus Avatar asked Sep 06 '25 19:09

Anamus


1 Answers

For FileHandler and RotatingFileHandler you can easily set permission during construct. For RotatingFileHandler you have to set an optional parameter. These are parameters:

($filename, $maxFiles = 0, $level = Logger::DEBUG, $bubble = true, $filePermission = null, $useLocking = false)

A code like this will work for you:

$handler = new Monolog\Handler\RotatingFileHandler($filename,0,Logger::DEBUG,true,0664);
like image 151
Moradnejad Avatar answered Sep 08 '25 12:09

Moradnejad