Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
100.00% covered (success)
100.00%
3 / 3
100.00% covered (success)
100.00%
1 / 1
CRAP
100.00% covered (success)
100.00%
1 / 1
ContextProcessor
100.00% covered (success)
100.00%
3 / 3
100.00% covered (success)
100.00%
1 / 1
1
100.00% covered (success)
100.00%
1 / 1
 __invoke
100.00% covered (success)
100.00%
3 / 3
100.00% covered (success)
100.00%
1 / 1
1
1<?php
2
3namespace MediaWiki\Logger\Monolog;
4
5use MediaWiki\Logger\LoggerFactory;
6use Monolog\LogRecord;
7
8/**
9 * Annotate log records with the context added via LoggerFactory::getContext().
10 * @since 1.44
11 */
12class ContextProcessor {
13
14    public function __invoke( LogRecord $record ): LogRecord {
15        // LogRecord::$context is readonly, so return a copy with the merged
16        // context. The union keeps keys already on the record, matching the
17        // prior precedence where per-call context beat the diagnostic context.
18        return $record->with(
19            context: $record->context + LoggerFactory::getContext()->get()
20        );
21    }
22
23}