Skip to content

Commit

Permalink
Fixes yiisoft#14264: Fixed a bug where `yii\log\Logger::calculateTimi…
Browse files Browse the repository at this point in the history
…ngs()` was not accepting messages with array tokens
  • Loading branch information
Bizley authored and samdark committed Jun 8, 2017
1 parent fddb34b commit deea182
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 1 deletion.
1 change: 1 addition & 0 deletions framework/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ Yii Framework 2 Change Log
------------------------

- Bug #14248: `yii\console\controllers\MessageController` no longer outputs colorized filenames when console does not support text colorization (PowerGamer1)
- Bug #14264: Fixed a bug where `yii\log\Logger::calculateTimings()` was not accepting messages with array tokens (bizley)


2.0.12 June 05, 2017
Expand Down
2 changes: 1 addition & 1 deletion framework/log/Logger.php
Original file line number Diff line number Diff line change
Expand Up @@ -278,7 +278,7 @@ public function calculateTimings($messages)
list($token, $level, $category, $timestamp, $traces) = $log;
$memory = isset($log[5]) ? $log[5] : 0;
$log[6] = $i;
$hash = md5($token);
$hash = md5(serialize($token));
if ($level == Logger::LEVEL_PROFILE_BEGIN) {
$stack[$hash] = $log;
} elseif ($level == Logger::LEVEL_PROFILE_END) {
Expand Down
22 changes: 22 additions & 0 deletions tests/framework/log/LoggerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -174,12 +174,15 @@ public function testCalculateTimingsWithProfileNotBeginOrEnd()
['message2', Logger::LEVEL_PROFILE, 'category', 'time', 'trace', 1048576],
['message3', Logger::LEVEL_TRACE, 'category', 'time', 'trace', 1048576],
['message4', Logger::LEVEL_WARNING, 'category', 'time', 'trace', 1048576],
[['message5', 'message6'], Logger::LEVEL_ERROR, 'category', 'time', 'trace', 1048576],
];
$this->assertEmpty($this->logger->calculateTimings($messages));
}

/**
* @covers yii\log\Logger::calculateTimings()
*
* See https://github.com/yiisoft/yii2/issues/14264
*/
public function testCalculateTimingsWithProfileBeginEnd()
{
Expand All @@ -201,6 +204,25 @@ public function testCalculateTimingsWithProfileBeginEnd()
],
$this->logger->calculateTimings($messages)
);

$messages = [
'anyKey' => [['a', 'b'], Logger::LEVEL_PROFILE_BEGIN, 'category', 10, 'trace', 1048576],
'anyKey2' => [['a', 'b'], Logger::LEVEL_PROFILE_END, 'category', 15, 'trace', 2097152],
];
$this->assertEquals([
[
'info' => ['a', 'b'],
'category' => 'category',
'timestamp' => 10,
'trace' => 'trace',
'level' => 0,
'duration' => 5,
'memory' => 2097152,
'memoryDiff' => 1048576
]
],
$this->logger->calculateTimings($messages)
);
}

/**
Expand Down

0 comments on commit deea182

Please sign in to comment.