3 namespace Drupal\Core\Logger;
6 * Parses log messages and their placeholders.
8 class LogMessageParser implements LogMessageParserInterface {
13 public function parseMessagePlaceholders(&$message, array &$context) {
16 if (($start = strpos($message, '{')) !== FALSE && strpos($message, '}') > $start) {
18 // Transform PSR3 style messages containing placeholders to
19 // \Drupal\Component\Render\FormattableMarkup style.
20 $message = preg_replace('/\{(.*)\}/U', '@$1', $message);
22 foreach ($context as $key => $variable) {
23 // PSR3 style placeholders.
25 // Keys are not prefixed with anything according to PSR3 specs.
26 // If the message is "User {username} created" the variable key will be
28 if (strpos($message, '@' . $key) !== FALSE) {
32 if (!empty($key) && ($key[0] === '@' || $key[0] === '%' || $key[0] === '!')) {
33 // The key is now in \Drupal\Component\Render\FormattableMarkup style.
34 $variables[$key] = $variable;