24use Monolog\Handler\NullHandler;
25use Monolog\Handler\StreamHandler;
27use Wikimedia\ObjectFactory;
145 foreach (
$config as $key => $value ) {
146 if ( isset( $this->config[$key] ) ) {
147 $this->config[$key] = array_merge( $this->config[$key], $value );
149 $this->config[$key] = $value;
152 if ( !isset( $this->config[
'loggers'][
'@default'] ) ) {
153 $this->config[
'loggers'][
'@default'] = [
154 'handlers' => [
'@default' ],
156 if ( !isset( $this->config[
'handlers'][
'@default'] ) ) {
157 $this->config[
'handlers'][
'@default'] = [
158 'class' => StreamHandler::class,
159 'args' => [
'php://stderr', Logger::ERROR ],
173 $this->singletons = [
192 if ( !isset( $this->singletons[
'loggers'][$channel] ) ) {
195 $spec = $this->config[
'loggers'][$channel] ?? $this->config[
'loggers'][
'@default'];
198 $this->singletons[
'loggers'][$channel] = $monolog;
201 return $this->singletons[
'loggers'][$channel];
211 $obj =
new Logger( $channel );
213 if ( isset( $spec[
'calls'] ) ) {
214 foreach ( $spec[
'calls'] as $method => $margs ) {
215 $obj->$method( ...$margs );
219 if ( isset( $spec[
'processors'] ) ) {
220 foreach ( $spec[
'processors'] as $processor ) {
221 $obj->pushProcessor( $this->
getProcessor( $processor ) );
225 if ( isset( $spec[
'handlers'] ) && $spec[
'handlers'] ) {
226 foreach ( $spec[
'handlers'] as $handler ) {
227 $obj->pushHandler( $this->
getHandler( $handler ) );
232 $obj->pushHandler(
new NullHandler() );
243 if ( !isset( $this->singletons[
'processors'][$name] ) ) {
244 $spec = $this->config[
'processors'][$name];
245 $processor = ObjectFactory::getObjectFromSpec( $spec );
246 $this->singletons[
'processors'][$name] = $processor;
248 return $this->singletons[
'processors'][$name];
257 if ( !isset( $this->singletons[
'handlers'][$name] ) ) {
258 $spec = $this->config[
'handlers'][$name];
259 $handler = ObjectFactory::getObjectFromSpec( $spec );
261 isset( $spec[
'formatter'] ) &&
262 is_subclass_of( $handler,
'Monolog\Handler\FormattableHandlerInterface' )
264 $handler->setFormatter(
268 if ( isset( $spec[
'buffer'] ) && $spec[
'buffer'] ) {
271 $this->singletons[
'handlers'][$name] = $handler;
273 return $this->singletons[
'handlers'][$name];
282 if ( !isset( $this->singletons[
'formatters'][$name] ) ) {
283 $spec = $this->config[
'formatters'][$name];
284 $formatter = ObjectFactory::getObjectFromSpec( $spec );
285 $this->singletons[
'formatters'][$name] = $formatter;
287 return $this->singletons[
'formatters'][$name];