24use Monolog\Handler\StreamHandler;
26use Wikimedia\ObjectFactory\ObjectFactory;
144 foreach (
$config as $key => $value ) {
145 if ( isset( $this->config[$key] ) ) {
146 $this->config[$key] = array_merge( $this->config[$key], $value );
148 $this->config[$key] = $value;
151 if ( !isset( $this->config[
'loggers'][
'@default'] ) ) {
152 $this->config[
'loggers'][
'@default'] = [
153 'handlers' => [
'@default' ],
155 if ( !isset( $this->config[
'handlers'][
'@default'] ) ) {
156 $this->config[
'handlers'][
'@default'] = [
157 'class' => StreamHandler::class,
158 'args' => [
'php://stderr', Logger::ERROR ],
172 $this->singletons = [
191 if ( !isset( $this->singletons[
'loggers'][$channel] ) ) {
194 $spec = $this->config[
'loggers'][$channel] ?? $this->config[
'loggers'][
'@default'];
197 $this->singletons[
'loggers'][$channel] = $monolog;
200 return $this->singletons[
'loggers'][$channel];
210 $obj =
new Logger( $channel );
212 if ( isset( $spec[
'calls'] ) ) {
213 foreach ( $spec[
'calls'] as $method => $margs ) {
214 $obj->$method( ...$margs );
218 if ( isset( $spec[
'processors'] ) ) {
219 foreach ( $spec[
'processors'] as $processor ) {
220 $obj->pushProcessor( $this->
getProcessor( $processor ) );
224 if ( isset( $spec[
'handlers'] ) && $spec[
'handlers'] ) {
225 foreach ( $spec[
'handlers'] as $handler ) {
226 $obj->pushHandler( $this->
getHandler( $handler ) );
238 if ( !isset( $this->singletons[
'processors'][$name] ) ) {
239 $spec = $this->config[
'processors'][$name];
240 $processor = ObjectFactory::getObjectFromSpec( $spec );
241 $this->singletons[
'processors'][$name] = $processor;
243 return $this->singletons[
'processors'][$name];
252 if ( !isset( $this->singletons[
'handlers'][$name] ) ) {
253 $spec = $this->config[
'handlers'][$name];
254 $handler = ObjectFactory::getObjectFromSpec( $spec );
256 isset( $spec[
'formatter'] ) &&
257 is_subclass_of( $handler,
'Monolog\Handler\FormattableHandlerInterface' )
259 $handler->setFormatter(
263 if ( isset( $spec[
'buffer'] ) && $spec[
'buffer'] ) {
266 $this->singletons[
'handlers'][$name] = $handler;
268 return $this->singletons[
'handlers'][$name];
277 if ( !isset( $this->singletons[
'formatters'][$name] ) ) {
278 $spec = $this->config[
'formatters'][$name];
279 $formatter = ObjectFactory::getObjectFromSpec( $spec );
280 $this->singletons[
'formatters'][$name] = $formatter;
282 return $this->singletons[
'formatters'][$name];