if ($this->flushInterval > 0 && count($this->messages) >= $this->flushInterval) {
$this->flush();
}
@ -185,10 +189,40 @@ class Logger extends Component
*/
public function flush($final = false)
{
$messages = $this->messages;
// https://github.com/yiisoft/yii2/issues/5619
// new messages could be logged while the existing ones are being handled by targets
$this->messages = [];
if ($this->profilingAware) {
$keep = [];
$messages = [];
foreach ($this->messages as $index => $message) {
if (is_int($index)) {
$messages[] = $message;
} else {
if (strpos($index, 'begin-') === 0) {
$oppositeProfile = 'end-' . substr($index, 6);
} else {
$oppositeProfile = 'begin-' . substr($index, 4);
}
if (array_key_exists($oppositeProfile, $this->messages)) {
$messages[] = $message;
} else {
$keep[$index] = $message;
}
}
}
if ($this->flushInterval > 0 && count($keep) >= $this->flushInterval) {
$this->messages = [];
$this->log(
'Number of dangling profiling block messages reached flushInterval value and therefore these were flushed. Please consider setting higher flushInterval value or making profiling blocks shorter.',
&& $messages[0][0] === 'Number of dangling profiling block messages reached flushInterval value and therefore these were flushed. Please consider setting higher flushInterval value or making profiling blocks shorter.';