You are here

class MessagePlaceholderProcessor in Monolog 2.x

Same name and namespace in other branches
  1. 8 src/Logger/Processor/MessagePlaceholderProcessor.php \Drupal\monolog\Logger\Processor\MessagePlaceholderProcessor

Parse and replace message placeholders.

Hierarchy

Expanded class hierarchy of MessagePlaceholderProcessor

1 string reference to 'MessagePlaceholderProcessor'
monolog.services.yml in ./monolog.services.yml
monolog.services.yml
1 service uses MessagePlaceholderProcessor
monolog.processor.message_placeholder in ./monolog.services.yml
Drupal\monolog\Logger\Processor\MessagePlaceholderProcessor

File

src/Logger/Processor/MessagePlaceholderProcessor.php, line 10

Namespace

Drupal\monolog\Logger\Processor
View source
class MessagePlaceholderProcessor {

  /**
   * The message's placeholders parser.
   *
   * @var \Drupal\Core\Logger\LogMessageParserInterface
   */
  protected $parser;

  /**
   * Construct default object.
   *
   * @param \Drupal\Core\Logger\LogMessageParserInterface $parser
   *   The parser to use when extracting message variables.
   */
  public function __construct(LogMessageParserInterface $parser) {
    $this->parser = $parser;
  }

  /**
   * {@inheritdoc}
   */
  public function __invoke(array $record) {

    // Populate the message placeholders and then replace them in the message.
    $message_placeholders = $this->parser
      ->parseMessagePlaceholders($record['message'], $record['context']);
    $record['message'] = empty($message_placeholders) ? $record['message'] : strtr($record['message'], $message_placeholders);

    // Remove the replaced placeholders from the context to prevent logging the
    // same information twice.
    foreach (array_keys($message_placeholders) as $placeholder) {
      unset($record['context'][$placeholder]);
    }
    return $record;
  }

}

Members

Namesort descending Modifiers Type Description Overrides
MessagePlaceholderProcessor::$parser protected property The message's placeholders parser.
MessagePlaceholderProcessor::__construct public function Construct default object.
MessagePlaceholderProcessor::__invoke public function