25 use Monolog\Handler\StreamHandler;
26 use Wikimedia\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'] ) ) {
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 );
255 if ( isset( $spec[
'formatter'] ) ) {
256 $handler->setFormatter(
260 if ( isset( $spec[
'buffer'] ) && $spec[
'buffer'] ) {
263 $this->singletons[
'handlers'][$name] = $handler;
265 return $this->singletons[
'handlers'][$name];
274 if ( !isset( $this->singletons[
'formatters'][$name] ) ) {
275 $spec = $this->config[
'formatters'][$name];
276 $formatter = ObjectFactory::getObjectFromSpec( $spec );
277 $this->singletons[
'formatters'][$name] = $formatter;
279 return $this->singletons[
'formatters'][$name];