Let Monolog insert exception_id and exception_url so that consumers
of logging data (such as Logstash) may provide a normalised message
that does not contain these variants, for ease of aggregation
and message trend counting.
Bug: T45086
Change-Id: I7cc8f8c9e68031ad6771593d390079c0a3a535b9
return "[$id] $url $type from line $line of $file: $message";
}
return "[$id] $url $type from line $line of $file: $message";
}
+ /**
+ * Get a normalised message for formatting with PSR-3 log event context.
+ *
+ * Must be used together with `getLogContext()` to be useful.
+ *
+ * @since 1.30
+ * @param Exception|Throwable $e
+ * @return string
+ */
+ public static function getLogNormalMessage( $e ) {
+ $type = get_class( $e );
+ $file = $e->getFile();
+ $line = $e->getLine();
+ $message = $e->getMessage();
+
+ return "[{exception_id}] {exception_url} $type from line $line of $file: $message";
+ }
+
/**
* @param Exception|Throwable $e
* @return string
/**
* @param Exception|Throwable $e
* @return string
return [
'exception' => $e,
'exception_id' => WebRequest::getRequestId(),
return [
'exception' => $e,
'exception_id' => WebRequest::getRequestId(),
+ 'exception_url' => self::getURL() ?: '[no req]',
'caught_by' => $catcher
];
}
'caught_by' => $catcher
];
}
if ( !( $e instanceof MWException ) || $e->isLoggable() ) {
$logger = LoggerFactory::getInstance( 'exception' );
$logger->error(
if ( !( $e instanceof MWException ) || $e->isLoggable() ) {
$logger = LoggerFactory::getInstance( 'exception' );
$logger->error(
- self::getLogMessage( $e ),
+ self::getLogNormalMessage( $e ),
self::getLogContext( $e, $catcher )
);
self::getLogContext( $e, $catcher )
);
$logger = LoggerFactory::getInstance( $channel );
$logger->log(
$level,
$logger = LoggerFactory::getInstance( $channel );
$logger->log(
$level,
- self::getLogMessage( $e ),
+ self::getLogNormalMessage( $e ),
self::getLogContext( $e, $catcher )
);
}
self::getLogContext( $e, $catcher )
);
}