Reputation: 43
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.
Upvotes: 4
Views: 3020
Reputation: 3673
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);
Upvotes: 4
Reputation: 579
As a personal opinion I will avoid altering the file permissions. What I usually do rather is create a different log file for the user needing to write to the Log. You will end up with more files but at least you know which file to look for what.
<?php
...
$app -> configureMonologUsing(function ($monolog) {
// Create a file name: laravel-user.log
$filename = storage_path('logs/laravel-' . php_sapi_name() . '.log');
// Pass that file name to your handler
$handler = new Monolog\Handler\RotatingFileHandler($filename);
$monolog -> pushHandler($handler);
});
...
See these links for more info:
Upvotes: 1