Commit b1cf051a by Paweł 'Zibi' Zaremba

Adding rotateByCopy to yii\log\FileTarget #3562

parent 4b6b9d41
...@@ -57,6 +57,7 @@ Yii Framework 2 Change Log ...@@ -57,6 +57,7 @@ Yii Framework 2 Change Log
- Enh #3518: `yii\helpers\Html::encode()` now replaces invalid code sequences with "?" (DaSourcerer) - Enh #3518: `yii\helpers\Html::encode()` now replaces invalid code sequences with "?" (DaSourcerer)
- Enh #3521: Added `yii\filters\HttpCache::sessionCacheLimiter` (qiangxue) - Enh #3521: Added `yii\filters\HttpCache::sessionCacheLimiter` (qiangxue)
- Enh #3542: Removed requirement to specify `extensions` in application config (samdark) - 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 #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: 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) - Enh: Supported adding a new response formatter without the need to reconfigure existing formatters (qiangxue)
......
...@@ -51,6 +51,11 @@ class FileTarget extends Target ...@@ -51,6 +51,11 @@ class FileTarget extends Target
* but read-only for other users. * but read-only for other users.
*/ */
public $dirMode = 0775; 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. * Initializes the route.
...@@ -115,10 +120,18 @@ class FileTarget extends Target ...@@ -115,10 +120,18 @@ class FileTarget extends Target
if ($i === $this->maxLogFiles) { if ($i === $this->maxLogFiles) {
@unlink($rotateFile); @unlink($rotateFile);
} else { } 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)); @rename($rotateFile, $file . '.' . ($i + 1));
} }
} }
} }
}
if (is_file($file)) { if (is_file($file)) {
@rename($file, $file . '.1'); // suppress errors because it's possible multiple processes enter into this section @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