bug #22961 [HttpKernel] Support unknown format in LoggerDataCollector (iltar)
This PR was merged into the 3.3 branch.
Discussion
----------
[HttpKernel] Support unknown format in LoggerDataCollector
| Q | A
| ------------- | ---
| Branch? | 3.3
| Bug fix? | yes
| New feature? | no
| BC breaks? | no
| Deprecations? | no
| Tests pass? | yes
| Fixed tickets | #22952
| License | MIT
| Doc PR | ~
The new expected format for the compiler log is `CompilerPassClass: Message`. However, this is not enforced by the old logging method as seen in schmittjoh/JMSDiExtraBundle#276
This PR adds the ability to read those lines without crashing with `Uncaught Notice: Undefined offset: 1`.
Please note that I have not tested this in an application so testers are welcome to confirm this fix!
Commits
-------
a8dfbb1180
Support unknown compiler log format
This commit is contained in:
commit
e87994502c
@ -138,6 +138,9 @@ class LoggerDataCollector extends DataCollector implements LateDataCollectorInte
|
|||||||
$logs = array();
|
$logs = array();
|
||||||
foreach (file($file, FILE_IGNORE_NEW_LINES) as $log) {
|
foreach (file($file, FILE_IGNORE_NEW_LINES) as $log) {
|
||||||
$log = explode(': ', $log, 2);
|
$log = explode(': ', $log, 2);
|
||||||
|
if (!isset($log[1]) || !preg_match('/^[a-zA-Z_\x7f-\xff][a-zA-Z0-9_\x7f-\xff]*+(?:\\\\[a-zA-Z_\x7f-\xff][a-zA-Z0-9_\x7f-\xff]*+)++$/', $log[0])) {
|
||||||
|
$log = array('Unknown Compiler Pass', implode(': ', $log));
|
||||||
|
}
|
||||||
|
|
||||||
$logs[$log[0]][] = array('message' => $log[1]);
|
$logs[$log[0]][] = array('message' => $log[1]);
|
||||||
}
|
}
|
||||||
|
@ -0,0 +1,4 @@
|
|||||||
|
Symfony\Component\DependencyInjection\Compiler\RemovePrivateAliasesPass: Removed service "Psr\Container\ContainerInterface"; reason: private alias.
|
||||||
|
Symfony\Component\DependencyInjection\Compiler\RemovePrivateAliasesPass: Removed service "Symfony\Component\DependencyInjection\ContainerInterface"; reason: private alias.
|
||||||
|
Some custom logging message
|
||||||
|
With ending :
|
@ -17,6 +17,27 @@ use Symfony\Component\HttpKernel\DataCollector\LoggerDataCollector;
|
|||||||
|
|
||||||
class LoggerDataCollectorTest extends TestCase
|
class LoggerDataCollectorTest extends TestCase
|
||||||
{
|
{
|
||||||
|
public function testCollectWithUnexpectedFormat()
|
||||||
|
{
|
||||||
|
$logger = $this->getMockBuilder('Symfony\Component\HttpKernel\Log\DebugLoggerInterface')->getMock();
|
||||||
|
$logger->expects($this->once())->method('countErrors')->will($this->returnValue('foo'));
|
||||||
|
$logger->expects($this->exactly(2))->method('getLogs')->will($this->returnValue(array()));
|
||||||
|
|
||||||
|
$c = new LoggerDataCollector($logger, __DIR__.'/');
|
||||||
|
$c->lateCollect();
|
||||||
|
$compilerLogs = $c->getCompilerLogs()->getValue('message');
|
||||||
|
|
||||||
|
$this->assertSame(array(
|
||||||
|
array('message' => 'Removed service "Psr\Container\ContainerInterface"; reason: private alias.'),
|
||||||
|
array('message' => 'Removed service "Symfony\Component\DependencyInjection\ContainerInterface"; reason: private alias.'),
|
||||||
|
), $compilerLogs['Symfony\Component\DependencyInjection\Compiler\RemovePrivateAliasesPass']);
|
||||||
|
|
||||||
|
$this->assertSame(array(
|
||||||
|
array('message' => 'Some custom logging message'),
|
||||||
|
array('message' => 'With ending :'),
|
||||||
|
), $compilerLogs['Unknown Compiler Pass']);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @dataProvider getCollectTestData
|
* @dataProvider getCollectTestData
|
||||||
*/
|
*/
|
||||||
|
Reference in New Issue
Block a user