Browse Source

Adding rotateByCopy to yii\log\FileTarget #3562

tags/2.0.0-rc
Paweł 'Zibi' Zaremba 10 years ago
parent
commit
b1cf051a73
  1. 1
      framework/CHANGELOG.md
  2. 15
      framework/log/FileTarget.php

1
framework/CHANGELOG.md

@ -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)

15
framework/log/FileTarget.php

@ -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,7 +120,15 @@ class FileTarget extends Target
if ($i === $this->maxLogFiles) { if ($i === $this->maxLogFiles) {
@unlink($rotateFile); @unlink($rotateFile);
} else { } else {
@rename($rotateFile, $file . '.' . ($i + 1)); if ($this->rotateByCopy) {
@copy($rotateFile, $file . '.' . ($i + 1));
if ($fp = @fopen($rotateFile, 'a')) {
@ftruncate($fp, 0);
@fclose($fp);
}
} else {
@rename($rotateFile, $file . '.' . ($i + 1));
}
} }
} }
} }

Loading…
Cancel
Save