21 namespace MediaWiki\Logger;
27 use Psr\Log\AbstractLogger;
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,
88 if ( self::shouldEmit( $this->channel, $message, $level,
$context ) ) {
90 $destination = self::destination( $this->channel, $message,
$context );
91 self::emit( $text, $destination );
112 if (
$channel ===
'wfLogDBError' ) {
115 $shouldEmit = (bool)$wgDBerrorLog;
117 } elseif (
$channel ===
'wfErrorLog' ) {
121 } elseif (
$channel ===
'wfDebug' ) {
126 $shouldEmit = $wgDebugLogFile !=
'';
128 } elseif ( isset( $wgDebugLogGroups[
$channel] ) ) {
129 $logConfig = $wgDebugLogGroups[
$channel];
131 if ( is_array( $logConfig ) ) {
133 if ( isset( $logConfig[
'sample'] ) ) {
135 $shouldEmit = mt_rand( 1, $logConfig[
'sample'] ) === 1;
138 if ( isset( $logConfig[
'level'] ) ) {
139 if ( is_string( $level ) ) {
140 $level = self::$levelMapping[$level];
142 $shouldEmit = $level >= self::$levelMapping[$logConfig[
'level']];
146 $shouldEmit = $logConfig !==
false;
158 $shouldEmit = $wgDebugLogFile !=
'';
183 } elseif (
$channel ===
'wfLogDBError' ) {
186 } elseif (
$channel ===
'wfErrorLog' ) {
187 $text =
"{$message}\n";
189 } elseif (
$channel ===
'profileoutput' ) {
192 if ( isset(
$context[
'forwarded_for'] ) ) {
193 $forward =
" forwarded for {$context['forwarded_for']}";
195 if ( isset(
$context[
'client_ip'] ) ) {
196 $forward .=
" client IP {$context['client_ip']}";
199 $forward .=
" from {$context['from']}";
202 $forward =
"\t(proxied via {$context['proxy']}{$forward})";
211 $log = sprintf(
"%s\t%04.3f\t%s%s\n",
214 $text = self::formatAsWfDebugLog(
217 } elseif ( !isset( $wgDebugLogGroups[
$channel] ) ) {
218 $text = self::formatAsWfDebug(
219 $channel,
"[{$channel}] {$message}",
$context );
223 $text = self::formatAsWfDebugLog( $channel, $message,
$context );
227 if ( $wgLogExceptionBacktrace && isset(
$context[
'exception'] ) ) {
231 if (
$e instanceof Exception ) {
234 } elseif ( is_array(
$e ) && isset(
$e[
'trace'] ) ) {
236 $backtrace =
$e[
'trace'];
245 return self::interpolate( $text,
$context );
257 $text = preg_replace(
'![\x00-\x08\x0b\x0c\x0e-\x1f]!',
' ', $message );
258 if ( isset(
$context[
'seconds_elapsed'] ) ) {
261 $text =
"{$context['seconds_elapsed']} {$context['memory_used']} {$text}";
263 if ( isset(
$context[
'prefix'] ) ) {
264 $text =
"{$context['prefix']}{$text}";
279 static $cachedTimezone = null;
281 if ( !$cachedTimezone ) {
282 $cachedTimezone =
new DateTimeZone( $wgDBerrorLogTZ );
285 $d = date_create(
'now', $cachedTimezone );
286 $date = $d->format(
'D M j G:i:s T Y' );
291 $text =
"{$date}\t{$host}\t{$wiki}\t{$message}\n";
306 $text =
"{$time} {$host} {$wiki}: {$message}\n";
318 if ( strpos( $message,
'{' ) !==
false ) {
320 foreach ( $context
as $key => $val ) {
321 $replace[
'{' . $key .
'}'] = self::flatten( $val );
323 $message = strtr( $message, $replace );
336 if ( null === $item ) {
340 if ( is_bool( $item ) ) {
341 return $item ?
'true' :
'false';
344 if ( is_float( $item ) ) {
345 if ( is_infinite( $item ) ) {
346 return ( $item > 0 ?
'' :
'-' ) .
'INF';
348 if ( is_nan( $item ) ) {
354 if ( is_scalar( $item ) ) {
355 return (
string)$item;
358 if ( is_array( $item ) ) {
359 return '[Array(' . count( $item ) .
')]';
362 if ( $item instanceof \DateTime ) {
363 return $item->format(
'c' );
366 if ( $item instanceof Exception ) {
367 return '[Exception ' . get_class( $item ) .
'( ' .
368 $item->getFile() .
':' . $item->getLine() .
') ' .
369 $item->getMessage() .
']';
372 if ( is_object( $item ) ) {
373 if ( method_exists( $item,
'__toString' ) ) {
374 return (
string)$item;
377 return '[Object ' . get_class( $item ) .
']';
380 if ( is_resource( $item ) ) {
381 return '[Resource ' . get_resource_type( $item ) .
']';
384 return '[Unknown ' . gettype( $item ) .
']';
404 if ( isset(
$context[
'destination'] ) ) {
406 $destination =
$context[
'destination'];
408 } elseif (
$channel ===
'wfDebug' ) {
411 } elseif (
$channel ===
'wfLogDBError' ) {
414 } elseif ( isset( $wgDebugLogGroups[
$channel] ) ) {
415 $logConfig = $wgDebugLogGroups[
$channel];
417 if ( is_array( $logConfig ) ) {
418 $destination = $logConfig[
'destination'];
420 $destination = strval( $logConfig );
437 public static function emit( $text, $file ) {
438 if ( substr( $file, 0, 4 ) ==
'udp:' ) {
440 $transport->emit( $text );
442 \MediaWiki\suppressWarnings();
443 $exists = file_exists( $file );
444 $size = $exists ? filesize( $file ) :
false;
446 ( $size !==
false && $size + strlen( $text ) < 0x7fffffff )
448 file_put_contents( $file, $text, FILE_APPEND );
450 \MediaWiki\restoreWarnings();
$wgLogExceptionBacktrace
If true, send the exception backtrace to the error log.
New debugger system that outputs a toolbar on page view.
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.
$wgDebugLogGroups
Map of string log group names to log destinations.
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.
Handler class for MWExceptions.
A generic class to send a message over UDP.
when a variable name is used in a it is silently declared as a new local masking the global
$wgDebugLogFile
Filename for debug logging.
see documentation in includes Linker php for Linker::makeImageLink & $time
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.
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
const TS_DB
MySQL DATETIME (YYYY-MM-DD HH:MM:SS)
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.
if the prop value should be in the metadata multi language array format