27use Psr\Log\AbstractLogger;
62 LogLevel::DEBUG => 100,
63 LogLevel::INFO => 200,
64 LogLevel::NOTICE => 250,
65 LogLevel::WARNING => 300,
66 LogLevel::ERROR => 400,
67 LogLevel::CRITICAL => 500,
68 LogLevel::ALERT => 550,
69 LogLevel::EMERGENCY => 600,
77 'DBConnection' =>
true
95 public function log( $level, $message, array
$context = [] ) {
96 if ( is_string( $level ) ) {
97 $level = self::$levelMapping[$level];
99 if ( $this->channel ===
'DBQuery' && isset(
$context[
'method'] )
106 if ( isset( self::$dbChannels[$this->channel] )
107 && $level >= self::$levelMapping[LogLevel::ERROR]
110 $effectiveChannel =
'wfLogDBError';
115 if ( self::shouldEmit( $effectiveChannel, $message, $level,
$context ) ) {
139 if ( is_string( $level ) ) {
140 $level = self::$levelMapping[$level];
143 if (
$channel ===
'wfLogDBError' ) {
148 } elseif (
$channel ===
'wfErrorLog' ) {
152 } elseif (
$channel ===
'wfDebug' ) {
162 if ( is_array( $logConfig ) ) {
164 if ( isset( $logConfig[
'sample'] ) ) {
166 $shouldEmit = mt_rand( 1, $logConfig[
'sample'] ) === 1;
169 if ( isset( $logConfig[
'level'] ) ) {
170 $shouldEmit = $level >= self::$levelMapping[$logConfig[
'level']];
174 $shouldEmit = $logConfig !==
false;
211 } elseif (
$channel ===
'wfLogDBError' ) {
214 } elseif (
$channel ===
'wfErrorLog' ) {
215 $text =
"{$message}\n";
217 } elseif (
$channel ===
'profileoutput' ) {
220 if ( isset(
$context[
'forwarded_for'] ) ) {
221 $forward =
" forwarded for {$context['forwarded_for']}";
223 if ( isset(
$context[
'client_ip'] ) ) {
224 $forward .=
" client IP {$context['client_ip']}";
227 $forward .=
" from {$context['from']}";
230 $forward =
"\t(proxied via {$context['proxy']}{$forward})";
239 $log = sprintf(
"%s\t%04.3f\t%s%s\n",
259 if (
$e instanceof Exception ) {
262 } elseif ( is_array(
$e ) && isset(
$e[
'trace'] ) ) {
264 $backtrace =
$e[
'trace'];
285 $text = preg_replace(
'![\x00-\x08\x0b\x0c\x0e-\x1f]!',
' ', $message );
286 if ( isset(
$context[
'seconds_elapsed'] ) ) {
289 $text =
"{$context['seconds_elapsed']} {$context['memory_used']} {$text}";
291 if ( isset(
$context[
'prefix'] ) ) {
292 $text =
"{$context['prefix']}{$text}";
307 static $cachedTimezone =
null;
309 if ( !$cachedTimezone ) {
313 $d = date_create(
'now', $cachedTimezone );
314 $date = $d->format(
'D M j G:i:s T Y' );
319 $text =
"{$date}\t{$host}\t{$wiki}\t{$message}\n";
335 $text =
"{$time} {$host} {$wiki}: {$message}\n";
347 if ( strpos( $message,
'{' ) !==
false ) {
349 foreach (
$context as $key => $val ) {
352 $message = strtr( $message, $replace );
365 if (
null === $item ) {
369 if ( is_bool( $item ) ) {
370 return $item ?
'true' :
'false';
373 if ( is_float( $item ) ) {
374 if ( is_infinite( $item ) ) {
375 return ( $item > 0 ?
'' :
'-' ) .
'INF';
377 if ( is_nan( $item ) ) {
380 return (
string)$item;
383 if ( is_scalar( $item ) ) {
384 return (
string)$item;
387 if ( is_array( $item ) ) {
388 return '[Array(' . count( $item ) .
')]';
391 if ( $item instanceof \DateTime ) {
392 return $item->format(
'c' );
395 if ( $item instanceof Exception ) {
396 return '[Exception ' . get_class( $item ) .
'( ' .
397 $item->getFile() .
':' . $item->getLine() .
') ' .
398 $item->getMessage() .
']';
401 if ( is_object( $item ) ) {
402 if ( method_exists( $item,
'__toString' ) ) {
403 return (
string)$item;
406 return '[Object ' . get_class( $item ) .
']';
409 if ( is_resource( $item ) ) {
410 return '[Resource ' . get_resource_type( $item ) .
']';
413 return '[Unknown ' . gettype( $item ) .
']';
433 if ( isset(
$context[
'destination'] ) ) {
435 $destination =
$context[
'destination'];
437 } elseif (
$channel ===
'wfDebug' ) {
440 } elseif (
$channel ===
'wfLogDBError' ) {
446 if ( is_array( $logConfig ) ) {
447 $destination = $logConfig[
'destination'];
449 $destination = strval( $logConfig );
465 public static function emit( $text, $file ) {
466 if ( substr( $file, 0, 4 ) ==
'udp:' ) {
468 $transport->emit( $text );
470 \Wikimedia\suppressWarnings();
471 $exists = file_exists( $file );
472 $size = $exists ? filesize( $file ) :
false;
474 ( $size !==
false && $size + strlen( $text ) < 0x7fffffff )
476 file_put_contents( $file, $text, FILE_APPEND );
478 \Wikimedia\restoreWarnings();
$wgLogExceptionBacktrace
If true, send the exception backtrace to the error log.
$wgDBerrorLogTZ
Timezone to use in the error log.
$wgDBerrorLog
File to log database errors to.
$wgDebugLogGroups
Map of string log group names to log destinations.
$wgDebugLogFile
Filename for debug logging.
wfHostname()
Fetch server name for use in error reporting etc.
wfTimestamp( $outputtype=TS_UNIX, $ts=0)
Get a timestamp string in one of various formats.
wfWikiID()
Get an ASCII string identifying this wiki This is used as a prefix in memcached keys.
New debugger system that outputs a toolbar on page view.
static query( $sql, $function, $isMaster, $runTime)
Begins profiling on a database query.
static debugMsg( $str, $context=[])
This is a method to pass messages from wfDebug to the pretty debugger.
Handler class for MWExceptions.
static prettyPrintTrace(array $trace, $pad='')
Generate a string representation of a stacktrace.
static getRedactedTrace( $e)
Return a copy of an exception's backtrace as an array.
A generic class to send a message over UDP.
static newFromString( $info)
see documentation in includes Linker php for Linker::makeImageLink & $time
do that in ParserLimitReportFormat instead use this to modify the parameters of the image all existing parser cache entries will be invalid To avoid you ll need to handle that somehow(e.g. with the RejectParserCacheValue hook) because MediaWiki won 't do it for you. & $defaults also a ContextSource after deleting those rows but within the same transaction you ll probably need to make sure the header is varied on and they can depend only on the ResourceLoaderContext $context
null means default in associative array with keys and values unescaped Should be merged with default with a value of false meaning to suppress the attribute in associative array with keys and values unescaped noclasses just before the function returns a value If you return true
if the prop value should be in the metadata multi language array format
returning false will NOT prevent logging $e