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. 13
      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 #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)

13
framework/log/FileTarget.php

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

Loading…
Cancel
Save