MediaWiki REL1_35
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

 __construct ( $channel)
 
 log ( $level, $message, array $context=[])
 Logs with an arbitrary level.
 
 setMinimumForTest (?int $level)
 Change an existing Logger singleton to act like NullLogger.
 

Static Public Member Functions

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

Static Protected Member Functions

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

Protected Attributes

string $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 Monolog uses.
 

Private Attributes

bool $isDB
 Whether the channel is a DB channel.
 
int $minimumLevel
 Minimum level.
 
const LEVEL_ALERT = 550
 
const LEVEL_CRITICAL = 500
 
const LEVEL_DEBUG = 100
 
const LEVEL_EMERGENCY = 600
 
const LEVEL_ERROR = 400
 
const LEVEL_INFINITY = 999
 
const LEVEL_INFO = 200
 
const LEVEL_NOTICE = 250
 
const LEVEL_WARNING = 300
 

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()

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 474 of file LegacyLogger.php.

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

Referenced by MediaWiki\Logger\LegacyLogger\log().

◆ 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 513 of file LegacyLogger.php.

References $file, and UDPTransport\newFromString().

Referenced by MediaWiki\Logger\LegacyLogger\log().

◆ 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 410 of file LegacyLogger.php.

Referenced by MediaWiki\Logger\LegacyLogger\interpolate().

◆ 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 282 of file LegacyLogger.php.

References MediaWiki\Logger\LegacyLogger\$channel, $wgDebugLogGroups, $wgLogExceptionBacktrace, MediaWiki\Logger\LegacyLogger\formatAsWfDebug(), MediaWiki\Logger\LegacyLogger\formatAsWfDebugLog(), MediaWiki\Logger\LegacyLogger\formatAsWfLogDBError(), MWExceptionHandler\getRedactedTrace(), MediaWiki\Logger\LegacyLogger\interpolate(), and MWExceptionHandler\prettyPrintTrace().

Referenced by MediaWiki\Logger\ConsoleLogger\log(), and MediaWiki\Logger\LegacyLogger\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 330 of file LegacyLogger.php.

Referenced by MediaWiki\Logger\LegacyLogger\format().

◆ 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 377 of file LegacyLogger.php.

References WikiMap\getCurrentWikiId(), wfHostname(), and wfTimestamp().

Referenced by MediaWiki\Logger\LegacyLogger\format().

◆ 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 351 of file LegacyLogger.php.

References $wgDBerrorLogTZ, WikiMap\getCurrentWikiId(), and wfHostname().

Referenced by MediaWiki\Logger\LegacyLogger\format().

◆ 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 392 of file LegacyLogger.php.

References MediaWiki\Logger\LegacyLogger\flatten().

Referenced by MediaWiki\Logger\LegacyLogger\format().

◆ log()

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

Logs with an arbitrary level.

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

Definition at line 163 of file LegacyLogger.php.

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

◆ setMinimumForTest()

MediaWiki\Logger\LegacyLogger::setMinimumForTest ( ?int  $level)

Change an existing Logger singleton to act like NullLogger.

Definition at line 146 of file LegacyLogger.php.

References MediaWiki\Logger\LegacyLogger\$minimumLevel, and MediaWiki\Logger\LegacyLogger\LEVEL_INFINITY.

◆ 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 218 of file LegacyLogger.php.

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

Member Data Documentation

◆ $channel

◆ $dbChannels

array MediaWiki\Logger\LegacyLogger::$dbChannels
staticprotected
Initial value:
= [
'DBQuery' => true,
'DBConnection' => true
]
return true
Definition router.php:92

Definition at line 88 of file LegacyLogger.php.

◆ $isDB

bool MediaWiki\Logger\LegacyLogger::$isDB
private

Whether the channel is a DB channel.

Definition at line 106 of file LegacyLogger.php.

◆ $levelMapping

array MediaWiki\Logger\LegacyLogger::$levelMapping
staticprotected
Initial value:
= [
LogLevel::DEBUG => self::LEVEL_DEBUG,
LogLevel::INFO => self::LEVEL_INFO,
LogLevel::NOTICE => self::LEVEL_NOTICE,
LogLevel::WARNING => self::LEVEL_WARNING,
LogLevel::ERROR => self::LEVEL_ERROR,
LogLevel::CRITICAL => self::LEVEL_CRITICAL,
LogLevel::ALERT => self::LEVEL_ALERT,
LogLevel::EMERGENCY => self::LEVEL_EMERGENCY,
]

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

Definition at line 74 of file LegacyLogger.php.

◆ $minimumLevel

int MediaWiki\Logger\LegacyLogger::$minimumLevel
private

Minimum level.

This is just to allow faster discard of debugging messages. Not all messages meeting the level will be logged.

Definition at line 99 of file LegacyLogger.php.

Referenced by MediaWiki\Logger\LegacyLogger\setMinimumForTest().

◆ LEVEL_ALERT

const MediaWiki\Logger\LegacyLogger::LEVEL_ALERT = 550
private

Definition at line 64 of file LegacyLogger.php.

◆ LEVEL_CRITICAL

const MediaWiki\Logger\LegacyLogger::LEVEL_CRITICAL = 500
private

Definition at line 63 of file LegacyLogger.php.

◆ LEVEL_DEBUG

const MediaWiki\Logger\LegacyLogger::LEVEL_DEBUG = 100
private

Definition at line 58 of file LegacyLogger.php.

Referenced by MediaWiki\Logger\LegacyLogger\__construct().

◆ LEVEL_EMERGENCY

const MediaWiki\Logger\LegacyLogger::LEVEL_EMERGENCY = 600
private

Definition at line 65 of file LegacyLogger.php.

◆ LEVEL_ERROR

const MediaWiki\Logger\LegacyLogger::LEVEL_ERROR = 400
private

Definition at line 62 of file LegacyLogger.php.

Referenced by MediaWiki\Logger\LegacyLogger\__construct().

◆ LEVEL_INFINITY

const MediaWiki\Logger\LegacyLogger::LEVEL_INFINITY = 999
private

◆ LEVEL_INFO

const MediaWiki\Logger\LegacyLogger::LEVEL_INFO = 200
private

Definition at line 59 of file LegacyLogger.php.

◆ LEVEL_NOTICE

const MediaWiki\Logger\LegacyLogger::LEVEL_NOTICE = 250
private

Definition at line 60 of file LegacyLogger.php.

◆ LEVEL_WARNING

const MediaWiki\Logger\LegacyLogger::LEVEL_WARNING = 300
private

Definition at line 61 of file LegacyLogger.php.


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