r41218 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r41217‎ | r41218 | r41219 >
Date:08:17, 24 September 2008
Author:tstarling
Status:old
Tags:
Comment:
* 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
Modified paths:
  • /trunk/phase3/includes/GlobalFunctions.php (modified) (history)
  • /trunk/udplog/demux.py (added) (history)

Diff [purge]

Index: trunk/phase3/includes/GlobalFunctions.php
@@ -297,24 +297,28 @@
298298 $protocol = $m[1];
299299 $host = $m[2];
300300 $port = $m[3];
301 - $prefix = isset( $m[4] ) ? $m[4] : '';
 301+ $prefix = isset( $m[4] ) ? $m[4] : false;
302302 } elseif ( preg_match( '!^(tcp|udp):(?://)?([a-zA-Z0-9-]+):(\d+)(?:/(.*))?$!', $file, $m ) ) {
303303 $protocol = $m[1];
304304 $host = $m[2];
305305 $port = $m[3];
306 - $prefix = isset( $m[4] ) ? $m[4] : '';
 306+ $prefix = isset( $m[4] ) ? $m[4] : false;
307307 } else {
308308 throw new MWException( __METHOD__.": Invalid UDP specification" );
309309 }
310 - $prefix = strval( $prefix );
311 - if ( $prefix != '' ) {
312 - $prefix .= ' ';
 310+ // Clean it up for the multiplexer
 311+ if ( strval( $prefix ) !== '' ) {
 312+ $text = preg_replace( '/^/m', $prefix . ' ', $text );
 313+ if ( substr( $text, -1 ) != "\n" ) {
 314+ $text .= "\n";
 315+ }
313316 }
 317+
314318 $sock = fsockopen( "$protocol://$host", $port );
315319 if ( !$sock ) {
316320 return;
317321 }
318 - fwrite( $sock, $prefix . $text );
 322+ fwrite( $sock, $text );
319323 fclose( $sock );
320324 } else {
321325 wfSuppressWarnings();
Index: trunk/udplog/demux.py
@@ -0,0 +1,42 @@
 2+# Simple python script for demultiplexing MediaWiki log files
 3+
 4+import sys, os, string
 5+
 6+transTable = string.maketrans("./", "__")
 7+openFiles = {}
 8+baseDir = '/var/log/mw/udp';
 9+
 10+while True:
 11+ # Use readline() not next() to avoid python's buffering
 12+ line = sys.stdin.readline()
 13+ if line == '':
 14+ break
 15+
 16+ try:
 17+ (name, text) = line.split(" ", 1)
 18+ except:
 19+ # No name
 20+ continue
 21+ string.translate(name, transTable)
 22+ name += '.log'
 23+ try:
 24+ if name in openFiles:
 25+ f = openFiles[name]
 26+ else:
 27+ f = file(baseDir + '/' + name, "a")
 28+ openFiles[name] = f
 29+ f.write(text)
 30+ f.flush()
 31+ except:
 32+ # Exit if it was a ctrl-C
 33+ if sys.exc_info()[0] == 'KeyboardInterrupt':
 34+ break
 35+
 36+ # Close the file and delete it from the map, in case there's something wrong with it
 37+ if name in openFiles:
 38+ try:
 39+ openFiles[name].close()
 40+ except:
 41+ pass
 42+ del openFiles[name]
 43+
Property changes on: trunk/udplog/demux.py
___________________________________________________________________
Added: svn:eol-style
144 + native