Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions config/config.sample.php
Original file line number Diff line number Diff line change
Expand Up @@ -728,6 +728,13 @@
*/
'logfile' => '/var/log/nextcloud.log',

/**
* Log file mode for the Nextcloud loggin type in octal notation.
*
* Defaults to 0640 (writeable by user, readable by group).
*/
'logfilemode' => 0640,

/**
* Loglevel to start logging at. Valid values are: 0 = Debug, 1 = Info, 2 =
* Warning, 3 = Error, and 4 = Fatal. The default value is Warning.
Expand Down
7 changes: 5 additions & 2 deletions lib/private/Log/File.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,8 @@
class File implements IWriter, IFileBased {
/** @var string */
protected $logFile;
/** @var int */
protected $logFileMode;
/** @var SystemConfig */
private $config;

Expand All @@ -67,6 +69,7 @@ public function __construct(string $path, string $fallbackPath = '', SystemConfi
}
}
$this->config = $config;
$this->logFileMode = $config->getValue('logfilemode', 0640);
}

/**
Expand Down Expand Up @@ -134,8 +137,8 @@ public function write(string $app, $message, int $level) {
}
$entry = json_encode($entry, JSON_PARTIAL_OUTPUT_ON_ERROR);
$handle = @fopen($this->logFile, 'a');
if ((fileperms($this->logFile) & 0777) != 0640) {
@chmod($this->logFile, 0640);
if ($this->logFileMode > 0 && (fileperms($this->logFile) & 0777) != $this->logFileMode) {
@chmod($this->logFile, $this->logFileMode);
}
if ($handle) {
fwrite($handle, $entry."\n");
Expand Down
12 changes: 6 additions & 6 deletions tests/lib/Log/LogFactoryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -83,10 +83,10 @@ public function testFile(string $type) {
$datadir = \OC::$SERVERROOT.'/data';
$defaultLog = $datadir . '/nextcloud.log';

$this->systemConfig->expects($this->exactly(2))
$this->systemConfig->expects($this->exactly(3))
->method('getValue')
->withConsecutive(['datadirectory', $datadir], ['logfile', $defaultLog])
->willReturnOnConsecutiveCalls($datadir, $defaultLog);
->withConsecutive(['datadirectory', $datadir], ['logfile', $defaultLog], ['logfilemode', 0640])
->willReturnOnConsecutiveCalls($datadir, $defaultLog, 0640);

$log = $this->factory->get($type);
$this->assertInstanceOf(File::class, $log);
Expand All @@ -113,10 +113,10 @@ public function testFileCustomPath($path, $expected) {
$datadir = \OC::$SERVERROOT.'/data';
$defaultLog = $datadir . '/nextcloud.log';

$this->systemConfig->expects($this->exactly(2))
$this->systemConfig->expects($this->exactly(3))
->method('getValue')
->withConsecutive(['datadirectory', $datadir], ['logfile', $defaultLog])
->willReturnOnConsecutiveCalls($datadir, $path);
->withConsecutive(['datadirectory', $datadir], ['logfile', $defaultLog], ['logfilemode', 0640])
->willReturnOnConsecutiveCalls($datadir, $path, 0640);

$log = $this->factory->get('file');
$this->assertInstanceOf(File::class, $log);
Expand Down