1
0
mirror of https://github.com/Seldaek/monolog.git synced 2025-10-22 17:16:18 +02:00

Fix BrowserConsoleHandler formatting

This resolves an issue whereby all styles would be applied in reverse
order to the formatting markers.
This commit is contained in:
Trevor North
2019-10-11 11:56:29 +01:00
committed by Jordi Boggiano
parent 65f1f304d4
commit 0ff3a9bd03
2 changed files with 21 additions and 4 deletions

View File

@@ -164,21 +164,22 @@ class BrowserConsoleHandler extends AbstractProcessingHandler
private static function handleStyles($formatted)
{
$args = array(static::quote('font-weight: normal'));
$args = array();
$format = '%c' . $formatted;
preg_match_all('/\[\[(.*?)\]\]\{([^}]*)\}/s', $format, $matches, PREG_OFFSET_CAPTURE | PREG_SET_ORDER);
foreach (array_reverse($matches) as $match) {
$args[] = static::quote(static::handleCustomStyles($match[2][0], $match[1][0]));
$args[] = '"font-weight: normal"';
$args[] = static::quote(static::handleCustomStyles($match[2][0], $match[1][0]));
$pos = $match[0][1];
$format = substr($format, 0, $pos) . '%c' . $match[1][0] . '%c' . substr($format, $pos + strlen($match[0][0]));
}
array_unshift($args, static::quote($format));
$args[] = static::quote('font-weight: normal');
$args[] = static::quote($format);
return $args;
return array_reverse($args);
}
private static function handleCustomStyles($style, $string)