Go to the documentation of this file.
27 use 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
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 ) {
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 \MediaWiki\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 \MediaWiki\restoreWarnings();
static newFromString( $info)
static getRedactedTrace( $e)
Return a copy of an exception's backtrace as an array.
New debugger system that outputs a toolbar on page view.
Handler class for MWExceptions.
wfTimestamp( $outputtype=TS_UNIX, $ts=0)
Get a timestamp string in one of various formats.
as see the revision history and available at free of to any person obtaining a copy of this software and associated documentation to deal in the Software without including without limitation the rights to use
wfHostname()
Fetch server name for use in error reporting etc.
injection txt This is an overview of how MediaWiki makes use of dependency injection The design described here grew from the discussion of RFC T384 The term dependency this means that anything an object needs to operate should be injected from the the object itself should only know narrow no concrete implementation of the logic it relies on The requirement to inject everything typically results in an architecture that based on two main types of and essentially stateless service objects that use other service objects to operate on the value objects As of the beginning MediaWiki is only starting to use the DI approach Much of the code still relies on global state or direct resulting in a highly cyclical dependency which acts as the top level factory for services in MediaWiki which can be used to gain access to default instances of various services MediaWikiServices however also allows new services to be defined and default services to be redefined Services are defined or redefined by providing a callback the instantiator that will return a new instance of the service When it will create an instance of MediaWikiServices and populate it with the services defined in the files listed by thereby bootstrapping the DI framework Per $wgServiceWiringFiles lists includes ServiceWiring php
$wgDBerrorLog
File to log database errors to.
static prettyPrintTrace(array $trace, $pad='')
Generate a string representation of a stacktrace.
static debugMsg( $str, $context=[])
This is a method to pass messages from wfDebug to the pretty debugger.
$wgDebugLogGroups
Map of string log group names to log destinations.
$wgLogExceptionBacktrace
If true, send the exception backtrace to the error log.
see documentation in includes Linker php for Linker::makeImageLink & $time
when a variable name is used in a it is silently declared as a new masking the global
$wgDebugLogFile
Filename for debug logging.
A generic class to send a message over UDP.
wfWikiID()
Get an ASCII string identifying this wiki This is used as a prefix in memcached keys.
div flags Integer display flags(NO_ACTION_LINK, NO_EXTRA_USER_LINKS) 'LogException' returning false will NOT prevent logging $e
static query( $sql, $function, $isMaster, $runTime)
Begins profiling on a database query.
This document is intended to provide useful advice for parties seeking to redistribute MediaWiki to end users It s targeted particularly at maintainers for Linux since it s been observed that distribution packages of MediaWiki often break We ve consistently had to recommend that users seeking support use official tarballs instead of their distribution s and this often solves whatever problem the user is having It would be nice if this could such as
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
$wgDBerrorLogTZ
Timezone to use in the error log.
the array() calling protocol came about after MediaWiki 1.4rc1.