63 LogLevel::DEBUG => 100,
64 LogLevel::INFO => 200,
65 LogLevel::NOTICE => 250,
66 LogLevel::WARNING => 300,
67 LogLevel::ERROR => 400,
68 LogLevel::CRITICAL => 500,
69 LogLevel::ALERT => 550,
70 LogLevel::EMERGENCY => 600,
78 'DBConnection' =>
true
97 if ( is_string( $level ) ) {
98 $level = self::$levelMapping[$level];
100 if ( $this->channel ===
'DBQuery' && isset(
$context[
'method'] )
107 if ( isset( self::$dbChannels[$this->channel] )
108 && $level >= self::$levelMapping[LogLevel::ERROR]
111 $effectiveChannel =
'wfLogDBError';
116 if ( self::shouldEmit( $effectiveChannel, $message, $level,
$context ) ) {
118 $destination = self::destination( $effectiveChannel, $message,
$context );
119 self::emit( $text, $destination );
140 if ( is_string( $level ) ) {
141 $level = self::$levelMapping[$level];
144 if (
$channel ===
'wfLogDBError' ) {
147 $shouldEmit = (bool)$wgDBerrorLog;
149 } elseif (
$channel ===
'wfErrorLog' ) {
153 } elseif (
$channel ===
'wfDebug' ) {
158 $shouldEmit = $wgDebugLogFile !=
'';
160 } elseif ( isset( $wgDebugLogGroups[
$channel] ) ) {
161 $logConfig = $wgDebugLogGroups[
$channel];
163 if ( is_array( $logConfig ) ) {
165 if ( isset( $logConfig[
'sample'] ) ) {
167 $shouldEmit = mt_rand( 1, $logConfig[
'sample'] ) === 1;
170 if ( isset( $logConfig[
'level'] ) ) {
171 $shouldEmit = $level >= self::$levelMapping[$logConfig[
'level']];
175 $shouldEmit = $logConfig !==
false;
187 $shouldEmit = $wgDebugLogFile !=
'';
207 global $wgDebugLogGroups, $wgLogExceptionBacktrace;
212 } elseif (
$channel ===
'wfLogDBError' ) {
215 } elseif (
$channel ===
'wfErrorLog' ) {
216 $text =
"{$message}\n";
218 } elseif (
$channel ===
'profileoutput' ) {
221 if ( isset(
$context[
'forwarded_for'] ) ) {
222 $forward =
" forwarded for {$context['forwarded_for']}";
224 if ( isset(
$context[
'client_ip'] ) ) {
225 $forward .=
" client IP {$context['client_ip']}";
228 $forward .=
" from {$context['from']}";
231 $forward =
"\t(proxied via {$context['proxy']}{$forward})";
240 $log = sprintf(
"%s\t%04.3f\t%s%s\n",
243 $text = self::formatAsWfDebugLog(
246 } elseif ( !isset( $wgDebugLogGroups[
$channel] ) ) {
247 $text = self::formatAsWfDebug(
248 $channel,
"[{$channel}] {$message}",
$context );
252 $text = self::formatAsWfDebugLog( $channel, $message,
$context );
256 if ( $wgLogExceptionBacktrace && isset(
$context[
'exception'] ) ) {
263 } elseif ( is_array(
$e ) && isset(
$e[
'trace'] ) ) {
265 $backtrace =
$e[
'trace'];
274 return self::interpolate( $text,
$context );
286 $text = preg_replace(
'![\x00-\x08\x0b\x0c\x0e-\x1f]!',
' ', $message );
287 if ( isset(
$context[
'seconds_elapsed'] ) ) {
290 $text =
"{$context['seconds_elapsed']} {$context['memory_used']} {$text}";
292 if ( isset(
$context[
'prefix'] ) ) {
293 $text =
"{$context['prefix']}{$text}";
308 static $cachedTimezone = null;
310 if ( !$cachedTimezone ) {
314 $d = date_create(
'now', $cachedTimezone );
315 $date = $d->format(
'D M j G:i:s T Y' );
320 $text =
"{$date}\t{$host}\t{$wiki}\t{$message}\n";
336 $text =
"{$time} {$host} {$wiki}: {$message}\n";
348 if ( strpos( $message,
'{' ) !==
false ) {
350 foreach ( $context
as $key => $val ) {
351 $replace[
'{' . $key .
'}'] = self::flatten( $val );
353 $message = strtr( $message, $replace );
366 if ( null === $item ) {
370 if ( is_bool( $item ) ) {
371 return $item ?
'true' :
'false';
374 if ( is_float( $item ) ) {
375 if ( is_infinite( $item ) ) {
376 return ( $item > 0 ?
'' :
'-' ) .
'INF';
378 if ( is_nan( $item ) ) {
384 if ( is_scalar( $item ) ) {
385 return (
string)$item;
388 if ( is_array( $item ) ) {
389 return '[Array(' . count( $item ) .
')]';
392 if ( $item instanceof \DateTime ) {
393 return $item->format(
'c' );
397 return '[Exception ' . get_class( $item ) .
'( ' .
398 $item->getFile() .
':' . $item->getLine() .
') ' .
399 $item->getMessage() .
']';
402 if ( is_object( $item ) ) {
403 if ( method_exists( $item,
'__toString' ) ) {
404 return (
string)$item;
407 return '[Object ' . get_class( $item ) .
']';
410 if ( is_resource( $item ) ) {
411 return '[Resource ' . get_resource_type( $item ) .
']';
414 return '[Unknown ' . gettype( $item ) .
']';
432 $destination = $wgDebugLogFile;
434 if ( isset(
$context[
'destination'] ) ) {
436 $destination =
$context[
'destination'];
438 } elseif (
$channel ===
'wfDebug' ) {
439 $destination = $wgDebugLogFile;
441 } elseif (
$channel ===
'wfLogDBError' ) {
444 } elseif ( isset( $wgDebugLogGroups[
$channel] ) ) {
445 $logConfig = $wgDebugLogGroups[
$channel];
447 if ( is_array( $logConfig ) ) {
448 $destination = $logConfig[
'destination'];
450 $destination = strval( $logConfig );
466 public static function emit( $text, $file ) {
467 if ( substr( $file, 0, 4 ) ==
'udp:' ) {
469 $transport->emit( $text );
471 \MediaWiki\suppressWarnings();
472 $exists = file_exists( $file );
473 $size = $exists ? filesize( $file ) :
false;
475 ( $size !==
false && $size + strlen( $text ) < 0x7fffffff )
477 file_put_contents( $file, $text, FILE_APPEND );
479 \MediaWiki\restoreWarnings();
static query($sql, $function, $isMaster, $runTime)
Begins profiling on a database query.
the array() calling protocol came about after MediaWiki 1.4rc1.
$wgDBerrorLogTZ
Timezone to use in the error log.
static debugMsg($str, $context=[])
This is a method to pass messages from wfDebug to the pretty debugger.
Apache License January AND DISTRIBUTION Definitions License shall mean the terms and conditions for use
div flags Integer display flags(NO_ACTION_LINK, NO_EXTRA_USER_LINKS) 'LogException'returning false will NOT prevent logging $e
$wgDBerrorLog
File to log database errors to.
wfHostname()
Fetch server name for use in error reporting etc.
when a variable name is used in a it is silently declared as a new local masking the global
wfTimestamp($outputtype=TS_UNIX, $ts=0)
Get a timestamp string in one of various formats.
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
wfWikiID()
Get an ASCII string identifying this wiki This is used as a prefix in memcached keys.
static newFromString($info)
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
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
static getRedactedTrace($e)
Return a copy of an exception's backtrace as an array.
static prettyPrintTrace(array $trace, $pad= '')
Generate a string representation of a stacktrace.
see documentation in includes Linker php for Linker::makeImageLink & $time
if the prop value should be in the metadata multi language array format
const TS_DB
MySQL DATETIME (YYYY-MM-DD HH:MM:SS)