Skip to content

Commit

Permalink
Do not rotate with copying by default unless OS is Windows
Browse files Browse the repository at this point in the history
  • Loading branch information
samdark committed Apr 18, 2019
1 parent 80e1450 commit 416c8a9
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions src/FileTarget.php
Expand Up @@ -57,7 +57,7 @@ class FileTarget extends Target
*/
public $dirMode = 0775;
/**
* @var bool Whether to rotate log files by copy and truncate in contrast to rotation by
* @var bool|null Whether to rotate log files by copy and truncate in contrast to rotation by
* renaming files. Defaults to `true` to be more compatible with log tailers and is windows
* systems which do not play well with rename on open files. Rotation by renaming however is
* a bit faster.
Expand All @@ -68,10 +68,18 @@ class FileTarget extends Target
* the PHP documentation. By setting rotateByCopy to `true` you can work
* around this problem.
*/
public $rotateByCopy = true;
public $rotateByCopy;

private function isRunningOnWindows()
{
return DIRECTORY_SEPARATOR === '\\';
}

public function __construct(string $logFile = '@runtime/logs/app.log')
{
if ($this->rotateByCopy === null) {
$this->rotateByCopy = $this->isRunningOnWindows();
}
$this->setLogFile($logFile);
}

Expand Down

0 comments on commit 416c8a9

Please sign in to comment.