25use Monolog\Handler\StreamHandler;
27use Psr\Log\LoggerInterface;
28use Wikimedia\ObjectFactory\ObjectFactory;
147 foreach (
$config as $key => $value ) {
148 if ( isset( $this->config[$key] ) ) {
149 $this->config[$key] = array_merge( $this->config[$key], $value );
151 $this->config[$key] = $value;
154 if ( !isset( $this->config[
'loggers'][
'@default'] ) ) {
155 $this->config[
'loggers'][
'@default'] = [
156 'handlers' => [
'@default' ],
158 if ( !isset( $this->config[
'handlers'][
'@default'] ) ) {
159 $this->config[
'handlers'][
'@default'] = [
160 'class' => StreamHandler::class,
161 'args' => [
'php://stderr', Logger::ERROR ],
175 $this->singletons = [
194 if ( !isset( $this->singletons[
'loggers'][$channel] ) ) {
197 $spec = $this->config[
'loggers'][$channel] ?? $this->config[
'loggers'][
'@default'];
200 $this->singletons[
'loggers'][$channel] = $monolog;
203 return $this->singletons[
'loggers'][$channel];
214 if ( isset( $spec[
'handlers'] ) && $spec[
'handlers'] ) {
215 foreach ( $spec[
'handlers'] as $handler ) {
221 if ( isset( $spec[
'processors'] ) ) {
222 foreach ( $spec[
'processors'] as $processor ) {
229 $obj =
new Logger( $channel, $handlers, $processors,
new DateTimeZone(
'UTC' ) );
231 if ( isset( $spec[
'calls'] ) ) {
232 foreach ( $spec[
'calls'] as $method => $margs ) {
233 $obj->$method( ...$margs );
246 if ( !isset( $this->singletons[
'processors'][$name] ) ) {
247 $spec = $this->config[
'processors'][$name];
248 $processor = ObjectFactory::getObjectFromSpec( $spec );
249 $this->singletons[
'processors'][$name] = $processor;
251 return $this->singletons[
'processors'][$name];
260 if ( !isset( $this->singletons[
'handlers'][$name] ) ) {
261 $spec = $this->config[
'handlers'][$name];
262 $handler = ObjectFactory::getObjectFromSpec( $spec );
264 isset( $spec[
'formatter'] ) &&
265 is_subclass_of( $handler,
'Monolog\Handler\FormattableHandlerInterface' )
267 $handler->setFormatter(
268 $this->getFormatter( $spec[
'formatter'] )
271 if ( isset( $spec[
'buffer'] ) && $spec[
'buffer'] ) {
274 $this->singletons[
'handlers'][$name] = $handler;
276 return $this->singletons[
'handlers'][$name];
285 if ( !isset( $this->singletons[
'formatters'][$name] ) ) {
286 $spec = $this->config[
'formatters'][$name];
287 $formatter = ObjectFactory::getObjectFromSpec( $spec );
288 $this->singletons[
'formatters'][$name] = $formatter;
290 return $this->singletons[
'formatters'][$name];