Commit a55d9ba8 by Paul Klimov

Merge pull request #3585 from pawzar/dev

Adding rotateByCopy to yii\log\FileTarget #3562
parents 4b6b9d41 b1cf051a
......@@ -57,6 +57,7 @@ Yii Framework 2 Change Log
- Enh #3518: `yii\helpers\Html::encode()` now replaces invalid code sequences with "?" (DaSourcerer)
- Enh #3521: Added `yii\filters\HttpCache::sessionCacheLimiter` (qiangxue)
- Enh #3542: Removed requirement to specify `extensions` in application config (samdark)
- Enh #3562: Adding rotateByCopy to yii\log\FileTarget (pawzar)
- Enh #3574: Add integrity check support for SQLite (zeeke)
- Enh: Added support for using sub-queries when building a DB query with `IN` condition (qiangxue)
- Enh: Supported adding a new response formatter without the need to reconfigure existing formatters (qiangxue)
......
......@@ -51,6 +51,11 @@ class FileTarget extends Target
* but read-only for other users.
*/
public $dirMode = 0775;
/**
* @var boolean Whether to rotate primary log by copy and truncate
* which is more compatible with log tailers. Defaults to false.
*/
public $rotateByCopy = false;
/**
* Initializes the route.
......@@ -115,10 +120,18 @@ class FileTarget extends Target
if ($i === $this->maxLogFiles) {
@unlink($rotateFile);
} else {
if ($this->rotateByCopy) {
@copy($rotateFile, $file . '.' . ($i + 1));
if ($fp = @fopen($rotateFile, 'a')) {
@ftruncate($fp, 0);
@fclose($fp);
}
} else {
@rename($rotateFile, $file . '.' . ($i + 1));
}
}
}
}
if (is_file($file)) {
@rename($file, $file . '.1'); // suppress errors because it's possible multiple processes enter into this section
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment