Commit 7c609ad8 by Carsten Brandt

allow disabling log rotation

fixes #6896 close #6913
parent 6846e17e
...@@ -9,6 +9,7 @@ Yii Framework 2 Change Log ...@@ -9,6 +9,7 @@ Yii Framework 2 Change Log
- Enh #6106: Added ability to specify `encode` for each item of `yii\widgets\Breadcrumbs` (samdark, aleksanderd) - Enh #6106: Added ability to specify `encode` for each item of `yii\widgets\Breadcrumbs` (samdark, aleksanderd)
- Enh #6493: Added support for the `Access-Control-Expose-Headers` header by `yii\filters\Cors` (usualdesigner) - Enh #6493: Added support for the `Access-Control-Expose-Headers` header by `yii\filters\Cors` (usualdesigner)
- Enh #6697: Added `yii\helpers\Url::current()` method that allows adding or removing parameters from current URL (samdark, callmez) - Enh #6697: Added `yii\helpers\Url::current()` method that allows adding or removing parameters from current URL (samdark, callmez)
- Enh #6896: Added `yii\log\FileTarget::$enableRotation` to allow disabling log rotation when external tools are configured for this (cebe)
- Chg #5690: adjusted paths in message config generated by `yii message/config` to reflect directory structure better (mikehaertl, samdark) - Chg #5690: adjusted paths in message config generated by `yii message/config` to reflect directory structure better (mikehaertl, samdark)
- Chg #6661: Hyperlinks that are enclosed within an exist form will use the same form for submission if they specify both of the `href` and `data-method` attributes (qiangxue) - Chg #6661: Hyperlinks that are enclosed within an exist form will use the same form for submission if they specify both of the `href` and `data-method` attributes (qiangxue)
......
...@@ -31,6 +31,13 @@ class FileTarget extends Target ...@@ -31,6 +31,13 @@ class FileTarget extends Target
*/ */
public $logFile; public $logFile;
/** /**
* @var bool whether log files should be rotated when they reach a certain [[maxFileSize|maximum size]].
* Log rotation is enabled by default. This property allows you to disable it, when you have configured
* an external tools for log rotation on your server.
* @since 2.0.3
*/
public $enableRotation = true;
/**
* @var integer maximum log file size, in kilo-bytes. Defaults to 10240, meaning 10MB. * @var integer maximum log file size, in kilo-bytes. Defaults to 10240, meaning 10MB.
*/ */
public $maxFileSize = 10240; // in KB public $maxFileSize = 10240; // in KB
...@@ -101,10 +108,12 @@ class FileTarget extends Target ...@@ -101,10 +108,12 @@ class FileTarget extends Target
throw new InvalidConfigException("Unable to append to log file: {$this->logFile}"); throw new InvalidConfigException("Unable to append to log file: {$this->logFile}");
} }
@flock($fp, LOCK_EX); @flock($fp, LOCK_EX);
// clear stat cache to ensure getting the real current file size and not a cached one if ($this->enableRotation) {
// this may result in rotating twice when cached file size is used on subsequent calls // clear stat cache to ensure getting the real current file size and not a cached one
clearstatcache(); // this may result in rotating twice when cached file size is used on subsequent calls
if (@filesize($this->logFile) > $this->maxFileSize * 1024) { clearstatcache();
}
if ($this->enableRotation && @filesize($this->logFile) > $this->maxFileSize * 1024) {
$this->rotateFiles(); $this->rotateFiles();
@flock($fp, LOCK_UN); @flock($fp, LOCK_UN);
@fclose($fp); @fclose($fp);
......
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