Go to the documentation of this file.
29 use Psr\Log\AbstractLogger;
65 LogLevel::DEBUG => 100,
66 LogLevel::INFO => 200,
67 LogLevel::NOTICE => 250,
68 LogLevel::WARNING => 300,
69 LogLevel::ERROR => 400,
70 LogLevel::CRITICAL => 500,
71 LogLevel::ALERT => 550,
72 LogLevel::EMERGENCY => 600,
80 'DBConnection' =>
true
98 public function log( $level, $message, array
$context = [] ) {
101 if ( is_string( $level ) ) {
102 $level = self::$levelMapping[$level];
104 if ( $this->channel ===
'DBQuery'
105 && $level === self::$levelMapping[LogLevel::DEBUG]
127 if ( isset( self::$dbChannels[$this->channel] )
128 && $level >= self::$levelMapping[LogLevel::ERROR]
132 $effectiveChannel =
'wfLogDBError';
137 if ( self::shouldEmit( $effectiveChannel, $message, $level,
$context ) ) {
161 if ( is_string( $level ) ) {
162 $level = self::$levelMapping[$level];
165 if (
$channel ===
'wfLogDBError' ) {
170 } elseif (
$channel ===
'wfDebug' ) {
180 if ( is_array( $logConfig ) ) {
182 if ( isset( $logConfig[
'sample'] ) ) {
184 $shouldEmit = mt_rand( 1, $logConfig[
'sample'] ) === 1;
187 if ( isset( $logConfig[
'level'] ) ) {
188 $shouldEmit = $level >= self::$levelMapping[$logConfig[
'level']];
192 $shouldEmit = $logConfig !==
false;
228 } elseif (
$channel ===
'wfLogDBError' ) {
231 } elseif (
$channel ===
'profileoutput' ) {
234 if ( isset(
$context[
'forwarded_for'] ) ) {
235 $forward =
" forwarded for {$context['forwarded_for']}";
237 if ( isset(
$context[
'client_ip'] ) ) {
238 $forward .=
" client IP {$context['client_ip']}";
241 $forward .=
" from {$context['from']}";
244 $forward =
"\t(proxied via {$context['proxy']}{$forward})";
253 $log = sprintf(
"%s\t%04.3f\t%s%s\n",
273 if ( $e instanceof Throwable || $e instanceof Exception ) {
276 } elseif ( is_array( $e ) && isset( $e[
'trace'] ) ) {
278 $backtrace = $e[
'trace'];
299 $text = preg_replace(
'![\x00-\x08\x0b\x0c\x0e-\x1f]!',
' ', $message );
300 if ( isset(
$context[
'seconds_elapsed'] ) ) {
303 $text =
"{$context['seconds_elapsed']} {$context['memory_used']} {$text}";
305 if ( isset(
$context[
'prefix'] ) ) {
306 $text =
"{$context['prefix']}{$text}";
321 static $cachedTimezone =
null;
323 if ( !$cachedTimezone ) {
327 $d = date_create(
'now', $cachedTimezone );
328 $date = $d->format(
'D M j G:i:s T Y' );
333 $text =
"{$date}\t{$host}\t{$wiki}\t{$message}\n";
349 $text =
"{$time} {$host} {$wiki}: {$message}\n";
361 if ( strpos( $message,
'{' ) !==
false ) {
363 foreach (
$context as $key => $val ) {
366 $message = strtr( $message, $replace );
379 if ( $item ===
null ) {
383 if ( is_bool( $item ) ) {
384 return $item ?
'true' :
'false';
387 if ( is_float( $item ) ) {
388 if ( is_infinite( $item ) ) {
389 return ( $item > 0 ?
'' :
'-' ) .
'INF';
391 if ( is_nan( $item ) ) {
394 return (
string)$item;
397 if ( is_scalar( $item ) ) {
398 return (
string)$item;
401 if ( is_array( $item ) ) {
402 return '[Array(' . count( $item ) .
')]';
405 if ( $item instanceof \DateTime ) {
406 return $item->format(
'c' );
409 if ( $item instanceof Throwable || $item instanceof Exception ) {
410 $which = $item instanceof Error ?
'Error' :
'Exception';
411 return '[' . $which .
' ' . get_class( $item ) .
'( ' .
412 $item->getFile() .
':' . $item->getLine() .
') ' .
413 $item->getMessage() .
']';
416 if ( is_object( $item ) ) {
417 if ( method_exists( $item,
'__toString' ) ) {
418 return (
string)$item;
421 return '[Object ' . get_class( $item ) .
']';
424 if ( is_resource( $item ) ) {
425 return '[Resource ' . get_resource_type( $item ) .
']';
428 return '[Unknown ' . gettype( $item ) .
']';
448 if ( isset(
$context[
'destination'] ) ) {
450 $destination =
$context[
'destination'];
452 } elseif (
$channel ===
'wfDebug' ) {
455 } elseif (
$channel ===
'wfLogDBError' ) {
461 if ( is_array( $logConfig ) ) {
462 $destination = $logConfig[
'destination'];
464 $destination = strval( $logConfig );
481 if ( substr(
$file, 0, 4 ) ==
'udp:' ) {
483 $transport->emit( $text );
485 \Wikimedia\suppressWarnings();
486 $exists = file_exists(
$file );
487 $size = $exists ? filesize(
$file ) :
false;
489 ( $size !==
false && $size + strlen( $text ) < 0x7fffffff )
491 file_put_contents(
$file, $text, FILE_APPEND );
493 \Wikimedia\restoreWarnings();
static query( $sql, $function, $runTime, $dbhost)
Begins profiling on a database query.
static newFromString( $info)
static getRedactedTrace( $e)
Return a copy of an exception's backtrace as an array.
static getCurrentWikiDbDomain()
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.
if(PHP_SAPI !='cli-server') if(!isset( $_SERVER['SCRIPT_FILENAME'])) $file
Item class for a filearchive table row.
wfHostname()
Fetch server name for use in error reporting etc.
$wgDBerrorLog
File to log database errors to.
static prettyPrintTrace(array $trace, $pad='')
Generate a string representation of a stacktrace.
static getWikiIdFromDbDomain( $domain)
Get the wiki ID of a database domain.
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.
$wgDebugLogFile
Filename for debug logging.
A generic class to send a message over UDP.
Helper tools for dealing with other locally-hosted wikis.
$wgDBerrorLogTZ
Timezone to use in the error log.