Skip to content

Commit

Permalink
allow disabling log rotation
Browse files Browse the repository at this point in the history
fixes #6896

close #6913
  • Loading branch information
cebe committed Jan 22, 2015
1 parent 6846e17 commit 7c609ad
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 4 deletions.
1 change: 1 addition & 0 deletions framework/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 #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 #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 #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)

Expand Down
17 changes: 13 additions & 4 deletions framework/log/FileTarget.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,13 @@ class FileTarget extends Target
* The directory containing the log files will be automatically created if not existing.
*/
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.
*/
Expand Down Expand Up @@ -101,10 +108,12 @@ public function export()
throw new InvalidConfigException("Unable to append to log file: {$this->logFile}");
}
@flock($fp, LOCK_EX);
// clear stat cache to ensure getting the real current file size and not a cached one
// this may result in rotating twice when cached file size is used on subsequent calls
clearstatcache();
if (@filesize($this->logFile) > $this->maxFileSize * 1024) {
if ($this->enableRotation) {
// clear stat cache to ensure getting the real current file size and not a cached one
// this may result in rotating twice when cached file size is used on subsequent calls
clearstatcache();
}
if ($this->enableRotation && @filesize($this->logFile) > $this->maxFileSize * 1024) {
$this->rotateFiles();
@flock($fp, LOCK_UN);
@fclose($fp);
Expand Down

0 comments on commit 7c609ad

Please sign in to comment.