*
* @see \MediaWiki\Logger\LoggerFactory
* @since 1.25
- * @author Bryan Davis <bd808@wikimedia.org>
- * @copyright © 2014 Bryan Davis and Wikimedia Foundation.
+ * @copyright © 2014 Wikimedia Foundation and contributors
*/
class LegacyLogger extends AbstractLogger {
* @return null
*/
public function log( $level, $message, array $context = [] ) {
+ if ( is_string( $level ) ) {
+ $level = self::$levelMapping[$level];
+ }
if ( $this->channel === 'DBQuery' && isset( $context['method'] )
&& isset( $context['master'] ) && isset( $context['runtime'] )
) {
}
if ( isset( self::$dbChannels[$this->channel] )
- && isset( self::$levelMapping[$level] )
- && self::$levelMapping[$level] >= LogLevel::ERROR
+ && $level >= self::$levelMapping[LogLevel::ERROR]
) {
// Format and write DB errors to the legacy locations
$effectiveChannel = 'wfLogDBError';
*
* @param string $channel
* @param string $message
- * @param string|int $level \Psr\Log\LogEvent constant or Monlog level int
+ * @param string|int $level \Psr\Log\LogEvent constant or Monolog level int
* @param array $context
* @return bool True if message should be sent to disk/network, false
* otherwise
public static function shouldEmit( $channel, $message, $level, $context ) {
global $wgDebugLogFile, $wgDBerrorLog, $wgDebugLogGroups;
+ if ( is_string( $level ) ) {
+ $level = self::$levelMapping[$level];
+ }
+
if ( $channel === 'wfLogDBError' ) {
// wfLogDBError messages are emitted if a database log location is
// specfied.
}
if ( isset( $logConfig['level'] ) ) {
- if ( is_string( $level ) ) {
- $level = self::$levelMapping[$level];
- }
$shouldEmit = $level >= self::$levelMapping[$logConfig['level']];
}
} else {
* @param string $channel
* @param string $message
* @param array $context
- * @return null
+ * @return string
*/
protected static function formatAsWfDebugLog( $channel, $message, $context ) {
$time = wfTimestamp( TS_DB );
if ( is_nan( $item ) ) {
return 'NaN';
}
- return $item;
+ return (string)$item;
}
if ( is_scalar( $item ) ) {
}
/**
- * Log to a file without getting "file size exceeded" signals.
- *
- * Can also log to UDP with the syntax udp://host:port/prefix. This will send
- * lines to the specified port, prefixed by the specified prefix and a space.
- *
- * @param string $text
- * @param string $file Filename
- */
+ * Log to a file without getting "file size exceeded" signals.
+ *
+ * Can also log to UDP with the syntax udp://host:port/prefix. This will send
+ * lines to the specified port, prefixed by the specified prefix and a space.
+ *
+ * @param string $text
+ * @param string $file Filename
+ */
public static function emit( $text, $file ) {
if ( substr( $file, 0, 4 ) == 'udp:' ) {
$transport = UDPTransport::newFromString( $file );
$transport->emit( $text );
} else {
- \MediaWiki\suppressWarnings();
+ \Wikimedia\suppressWarnings();
$exists = file_exists( $file );
$size = $exists ? filesize( $file ) : false;
if ( !$exists ||
) {
file_put_contents( $file, $text, FILE_APPEND );
}
- \MediaWiki\restoreWarnings();
+ \Wikimedia\restoreWarnings();
}
}