From aab518cf7875270c36aefadaa5b7ad58085a0933 Mon Sep 17 00:00:00 2001 From: Tim Starling Date: Wed, 24 Sep 2008 08:17:35 +0000 Subject: [PATCH] * Add a simple log demultiplexer, written in python, for low-volume MediaWiki logs * in wfErrorLog(): clean up log text so that it works properly with the multiplexer --- includes/GlobalFunctions.php | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/includes/GlobalFunctions.php b/includes/GlobalFunctions.php index 80e5843776..440791eeaf 100644 --- a/includes/GlobalFunctions.php +++ b/includes/GlobalFunctions.php @@ -297,24 +297,28 @@ function wfErrorLog( $text, $file ) { $protocol = $m[1]; $host = $m[2]; $port = $m[3]; - $prefix = isset( $m[4] ) ? $m[4] : ''; + $prefix = isset( $m[4] ) ? $m[4] : false; } elseif ( preg_match( '!^(tcp|udp):(?://)?([a-zA-Z0-9-]+):(\d+)(?:/(.*))?$!', $file, $m ) ) { $protocol = $m[1]; $host = $m[2]; $port = $m[3]; - $prefix = isset( $m[4] ) ? $m[4] : ''; + $prefix = isset( $m[4] ) ? $m[4] : false; } else { throw new MWException( __METHOD__.": Invalid UDP specification" ); } - $prefix = strval( $prefix ); - if ( $prefix != '' ) { - $prefix .= ' '; + // Clean it up for the multiplexer + if ( strval( $prefix ) !== '' ) { + $text = preg_replace( '/^/m', $prefix . ' ', $text ); + if ( substr( $text, -1 ) != "\n" ) { + $text .= "\n"; + } } + $sock = fsockopen( "$protocol://$host", $port ); if ( !$sock ) { return; } - fwrite( $sock, $prefix . $text ); + fwrite( $sock, $text ); fclose( $sock ); } else { wfSuppressWarnings(); -- 2.20.1