Index: trunk/phase3/includes/GlobalFunctions.php |
— | — | @@ -297,24 +297,28 @@ |
298 | 298 | $protocol = $m[1]; |
299 | 299 | $host = $m[2]; |
300 | 300 | $port = $m[3]; |
301 | | - $prefix = isset( $m[4] ) ? $m[4] : ''; |
| 301 | + $prefix = isset( $m[4] ) ? $m[4] : false; |
302 | 302 | } elseif ( preg_match( '!^(tcp|udp):(?://)?([a-zA-Z0-9-]+):(\d+)(?:/(.*))?$!', $file, $m ) ) { |
303 | 303 | $protocol = $m[1]; |
304 | 304 | $host = $m[2]; |
305 | 305 | $port = $m[3]; |
306 | | - $prefix = isset( $m[4] ) ? $m[4] : ''; |
| 306 | + $prefix = isset( $m[4] ) ? $m[4] : false; |
307 | 307 | } else { |
308 | 308 | throw new MWException( __METHOD__.": Invalid UDP specification" ); |
309 | 309 | } |
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 | + } |
313 | 316 | } |
| 317 | + |
314 | 318 | $sock = fsockopen( "$protocol://$host", $port ); |
315 | 319 | if ( !$sock ) { |
316 | 320 | return; |
317 | 321 | } |
318 | | - fwrite( $sock, $prefix . $text ); |
| 322 | + fwrite( $sock, $text ); |
319 | 323 | fclose( $sock ); |
320 | 324 | } else { |
321 | 325 | 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 |
1 | 44 | + native |