4

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.

Anamus
  • 43
  • 1
  • 5

2 Answers2

4

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);
Moradnejad
  • 3,466
  • 2
  • 30
  • 52
0

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:

Community
  • 1
  • 1
David Lartey
  • 531
  • 8
  • 15