MediaWiki master
MediaWiki\Logger\LoggingContext Class Reference

A helper class for adding extra context to all logs, without the logging code having to be aware. More...

Public Member Functions

 add (array $context)
 Add extra information to the PSR-3 context.
 
 addScoped (array $context)
 Add extra information to the PSR-3 context.
 
 get ()
 Get the current logging context.
 

Detailed Description

A helper class for adding extra context to all logs, without the logging code having to be aware.

(Sometimes called a "diagnostic context".)

Use LoggerFactory::getContext() to obtain the active instance of this class.

Since
1.44

Definition at line 14 of file LoggingContext.php.

Member Function Documentation

◆ add()

MediaWiki\Logger\LoggingContext::add ( array $context)

Add extra information to the PSR-3 context.

All future log events in the current request will include it. In case of key conflict, the context passed to the logger and scoped contexts take priority over this method, and later calls take priority over earlier calls.

It is recommended to make sure the fields added this way have a sufficiently unique name, and to prefix them with 'context.' (e.g. 'context.special_page_name').

Definition at line 31 of file LoggingContext.php.

◆ addScoped()

MediaWiki\Logger\LoggingContext::addScoped ( array $context)

Add extra information to the PSR-3 context.

All future log events within the scope will include it. In case of key conflict, the context passed to the logger takes priority over everything else, inner scopes take priority over outer scopes, and scopes take priority over addContext().

The context is not inherited by callbacks which are scheduled in the scope but executed outside it (such as DeferrableUpdate).

It is recommended to make sure the fields added this way have a sufficiently unique name, and to prefix them with 'context.' (e.g. 'context.special_page_name').

Definition at line 50 of file LoggingContext.php.

◆ get()

MediaWiki\Logger\LoggingContext::get ( )

Get the current logging context.

Access: internal
To be used by loggers only.

Definition at line 64 of file LoggingContext.php.


The documentation for this class was generated from the following file: