Fix #18274: Fix yii\log\Logger to calculate profile timings no matter the value of the flush interval

This commit is contained in:
Bizley
2021-07-30 22:55:19 +02:00
committed by GitHub
parent 9607d0eb52
commit fb7bc9fa5c
4 changed files with 83 additions and 11 deletions

View File

@ -20,6 +20,7 @@ Yii Framework 2 Change Log
- Enh #18726: Added `yii\helpers\Json::$prettyPrint` (rhertogh)
- Enh #18734: Added `yii\validators\EmailValidator::$enableLocalIDN` (brandonkelly)
- Enh #18656: Added ability for `yii serve`'s `--router` param to take an alias (markhuot)
- Bug #18274: Fix `yii\log\Logger` to calculate profile timings no matter the value of the flush interval (bizley)
2.0.42.1 May 06, 2021

View File

@ -108,7 +108,7 @@ class Logger extends Component
*/
public $traceLevel = 0;
/**
* @var Dispatcher the message dispatcher
* @var Dispatcher the message dispatcher.
*/
public $dispatcher;
/**
@ -117,6 +117,13 @@ class Logger extends Component
*/
public $dbEventNames = ['yii\db\Command::query', 'yii\db\Command::execute'];
/**
* @var array of profiling related messages.
* Structure of a log message is the same as in [[$messages]].
* @since 2.0.43
*/
protected $profileMessages = [];
/**
* Initializes the logger by registering [[flush()]] as a shutdown function.
@ -162,7 +169,11 @@ class Logger extends Component
}
}
}
$this->messages[] = [$message, $level, $category, $time, $traces, memory_get_usage()];
$data = [$message, $level, $category, $time, $traces, memory_get_usage()];
$this->messages[] = $data;
if ($level == self::LEVEL_PROFILE_BEGIN || $level == self::LEVEL_PROFILE_END) {
$this->profileMessages[] = $data;
}
if ($this->flushInterval > 0 && count($this->messages) >= $this->flushInterval) {
$this->flush();
}
@ -213,7 +224,7 @@ class Logger extends Component
*/
public function getProfiling($categories = [], $excludeCategories = [])
{
$timings = $this->calculateTimings($this->messages);
$timings = $this->calculateTimings($this->profileMessages);
if (empty($categories) && empty($excludeCategories)) {
return $timings;
}