MediaWiki  master
MediaWiki\Logger\LegacyLogger Class Reference

PSR-3 logger that mimics the historic implementation of MediaWiki's former wfErrorLog logging implementation. More...

Inheritance diagram for MediaWiki\Logger\LegacyLogger:
Collaboration diagram for MediaWiki\Logger\LegacyLogger:

Public Member Functions

static array __construct ( $channel)
 
 log ( $level, $message, array $context=[])
 Logs with an arbitrary level. More...
 

Static Public Member Functions

static emit ( $text, $file)
 Log to a file without getting "file size exceeded" signals. More...
 
static format ( $channel, $message, $context)
 Format a message. More...
 
static interpolate ( $message, array $context)
 Interpolate placeholders in logging message. More...
 
static shouldEmit ( $channel, $message, $level, $context)
 Determine if the given message should be emitted or not. More...
 

Static Protected Member Functions

static destination ( $channel, $message, $context)
 Select the appropriate log output destination for the given log event. More...
 
static flatten ( $item)
 Convert a logging context element to a string suitable for interpolation. More...
 
static formatAsWfDebug ( $channel, $message, $context)
 Format a message as wfDebug() would have formatted it. More...
 
static formatAsWfDebugLog ( $channel, $message, $context)
 Format a message as `wfDebugLog() would have formatted it. More...
 
static formatAsWfLogDBError ( $channel, $message, $context)
 Format a message as wfLogDBError() would have formatted it. More...
 

Protected Attributes

 $channel
 

Static Protected Attributes

static array $dbChannels
 
static $levelMapping
 Convert \Psr\Log\LogLevel constants into int for sane comparisons These are the same values that Monlog uses. More...
 

Detailed Description

PSR-3 logger that mimics the historic implementation of MediaWiki's former wfErrorLog logging implementation.

This logger is configured by the following global configuration variables:

  • $wgDebugLogFile
  • $wgDebugLogGroups
  • $wgDBerrorLog
  • $wgDBerrorLogTZ

See documentation in DefaultSettings.php for detailed explanations of each variable.

See also
\MediaWiki\Logger\LoggerFactory
Since
1.25
Note
© 2014 Wikimedia Foundation and contributors

Definition at line 51 of file LegacyLogger.php.

Constructor & Destructor Documentation

◆ __construct()

static array MediaWiki\Logger\LegacyLogger::__construct (   $channel)
Parameters
string$channel

Definition at line 86 of file LegacyLogger.php.

References MediaWiki\Logger\LegacyLogger\$channel.

Member Function Documentation

◆ destination()

static MediaWiki\Logger\LegacyLogger::destination (   $channel,
  $message,
  $context 
)
staticprotected

Select the appropriate log output destination for the given log event.

If the event context contains 'destination'

Parameters
string$channel
string$message
array$context
Returns
string

Definition at line 442 of file LegacyLogger.php.

References MediaWiki\Logger\LegacyLogger\$channel, MediaWiki\$context, $wgDBerrorLog, $wgDebugLogFile, and $wgDebugLogGroups.

◆ emit()

static MediaWiki\Logger\LegacyLogger::emit (   $text,
  $file 
)
static

Log to a file without getting "file size exceeded" signals.

Can also log to UDP with the syntax udp://host:port/prefix. This will send lines to the specified port, prefixed by the specified prefix and a space.

Parameters
string$text
string$fileFilename

Definition at line 481 of file LegacyLogger.php.

References $file, and UDPTransport\newFromString().

◆ flatten()

static MediaWiki\Logger\LegacyLogger::flatten (   $item)
staticprotected

Convert a logging context element to a string suitable for interpolation.

Parameters
mixed$item
Returns
string

Definition at line 379 of file LegacyLogger.php.

References null.

◆ format()

static MediaWiki\Logger\LegacyLogger::format (   $channel,
  $message,
  $context 
)
static

Format a message.

Messages to the 'wfDebug' and 'wfLogDBError' channels receive special formatting to mimic the historic output of the functions of the same name. All other channel values are formatted based on the historic output of the wfDebugLog() global function.

Parameters
string$channel
string$message
array$context
Returns
string

Definition at line 223 of file LegacyLogger.php.

References MediaWiki\Logger\LegacyLogger\$channel, MediaWiki\$context, $e, $wgDebugLogGroups, $wgLogExceptionBacktrace, MWExceptionHandler\getRedactedTrace(), and MWExceptionHandler\prettyPrintTrace().

Referenced by MediaWiki\Logger\Monolog\LegacyFormatter\format(), and MediaWiki\Logger\ConsoleLogger\log().

◆ formatAsWfDebug()

static MediaWiki\Logger\LegacyLogger::formatAsWfDebug (   $channel,
  $message,
  $context 
)
staticprotected

Format a message as wfDebug() would have formatted it.

Parameters
string$channel
string$message
array$context
Returns
string

Definition at line 299 of file LegacyLogger.php.

References MediaWiki\$context.

◆ formatAsWfDebugLog()

static MediaWiki\Logger\LegacyLogger::formatAsWfDebugLog (   $channel,
  $message,
  $context 
)
staticprotected

Format a message as `wfDebugLog() would have formatted it.

Parameters
string$channel
string$message
array$context
Returns
string

Definition at line 346 of file LegacyLogger.php.

References $time, WikiMap\getCurrentWikiDbDomain(), WikiMap\getWikiIdFromDbDomain(), wfHostname(), and wfTimestamp().

◆ formatAsWfLogDBError()

static MediaWiki\Logger\LegacyLogger::formatAsWfLogDBError (   $channel,
  $message,
  $context 
)
staticprotected

Format a message as wfLogDBError() would have formatted it.

Parameters
string$channel
string$message
array$context
Returns
string

Definition at line 320 of file LegacyLogger.php.

References $wgDBerrorLogTZ, WikiMap\getCurrentWikiDbDomain(), WikiMap\getWikiIdFromDbDomain(), null, and wfHostname().

◆ interpolate()

static MediaWiki\Logger\LegacyLogger::interpolate (   $message,
array  $context 
)
static

Interpolate placeholders in logging message.

Parameters
string$message
array$context
Returns
string Interpolated message

Definition at line 361 of file LegacyLogger.php.

References as.

Referenced by MediaWiki\Logger\LegacyLoggerTest\testInterpolate(), and MediaWiki\Logger\LegacyLoggerTest\testInterpolate_Error().

◆ log()

MediaWiki\Logger\LegacyLogger::log (   $level,
  $message,
array  $context = [] 
)

Logs with an arbitrary level.

Parameters
string | int$level
string$message
array$context
Returns
null

Definition at line 98 of file LegacyLogger.php.

References MediaWiki\Logger\LegacyLogger\$channel, MediaWiki\$context, $wgDBerrorLog, MWDebug\debugMsg(), format, and MWDebug\query().

◆ shouldEmit()

static MediaWiki\Logger\LegacyLogger::shouldEmit (   $channel,
  $message,
  $level,
  $context 
)
static

Determine if the given message should be emitted or not.

Parameters
string$channel
string$message
string | int$level\Psr\Log\LogEvent constant or Monolog level int
array$context
Returns
bool True if message should be sent to disk/network, false otherwise

Definition at line 159 of file LegacyLogger.php.

References MediaWiki\Logger\LegacyLogger\$channel, MediaWiki\$context, $wgDBerrorLog, $wgDebugLogFile, and $wgDebugLogGroups.

Referenced by MediaWiki\Logger\LegacyLoggerTest\testShouldEmit(), and MediaWiki\Logger\Monolog\LegacyHandler\write().

Member Data Documentation

◆ $channel

◆ $dbChannels

array MediaWiki\Logger\LegacyLogger::$dbChannels
staticprotected
Initial value:
= [
'DBQuery' => true

Definition at line 78 of file LegacyLogger.php.

◆ $levelMapping

array MediaWiki\Logger\LegacyLogger::$levelMapping
staticprotected
Initial value:
= [
LogLevel::DEBUG => 100

Convert \Psr\Log\LogLevel constants into int for sane comparisons These are the same values that Monlog uses.

Definition at line 64 of file LegacyLogger.php.


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