Index: trunk/phase3/includes/GlobalFunctions.php |
— | — | @@ -285,16 +285,46 @@ |
286 | 286 | } |
287 | 287 | |
288 | 288 | /** |
289 | | - * Log to a file without getting "file size exceeded" signals |
| 289 | + * Log to a file without getting "file size exceeded" signals. |
| 290 | + * |
| 291 | + * Can also log to TCP or UDP with the syntax udp://host:port/prefix. This will |
| 292 | + * send lines to the specified port, prefixed by the specified prefix and a space. |
290 | 293 | */ |
291 | 294 | function wfErrorLog( $text, $file ) { |
292 | | - wfSuppressWarnings(); |
293 | | - $exists = file_exists( $file ); |
294 | | - $size = $exists ? filesize( $file ) : false; |
295 | | - if ( !$exists || ( $size !== false && $size + strlen( $text ) < 0x7fffffff ) ) { |
296 | | - error_log( $text, 3, $file ); |
| 295 | + if ( substr( $file, 0, 4 ) == 'udp:' ) { |
| 296 | + if ( preg_match( '!^(tcp|udp):(?://)?\[([0-9a-fA-F:]+)\]:(\d+)(?:/(.*))?$!', $file, $m ) ) { |
| 297 | + // IPv6 bracketed host |
| 298 | + $protocol = $m[1]; |
| 299 | + $host = $m[2]; |
| 300 | + $port = $m[3]; |
| 301 | + $prefix = isset( $m[4] ) ? $m[4] : ''; |
| 302 | + } elseif ( preg_match( '!^(tcp|udp):(?://)?([a-zA-Z0-9-]+):(\d+)(?:/(.*))?$!', $file, $m ) ) { |
| 303 | + $protocol = $m[1]; |
| 304 | + $host = $m[2]; |
| 305 | + $port = $m[3]; |
| 306 | + $prefix = isset( $m[4] ) ? $m[4] : ''; |
| 307 | + } else { |
| 308 | + throw new MWException( __METHOD__.": Invalid UDP specification" ); |
| 309 | + } |
| 310 | + $prefix = strval( $prefix ); |
| 311 | + if ( $prefix != '' ) { |
| 312 | + $prefix .= ' '; |
| 313 | + } |
| 314 | + $sock = fsockopen( "$protocol://$host", $port ); |
| 315 | + if ( !$sock ) { |
| 316 | + return; |
| 317 | + } |
| 318 | + fwrite( $sock, $prefix . $text ); |
| 319 | + fclose( $sock ); |
| 320 | + } else { |
| 321 | + wfSuppressWarnings(); |
| 322 | + $exists = file_exists( $file ); |
| 323 | + $size = $exists ? filesize( $file ) : false; |
| 324 | + if ( !$exists || ( $size !== false && $size + strlen( $text ) < 0x7fffffff ) ) { |
| 325 | + error_log( $text, 3, $file ); |
| 326 | + } |
| 327 | + wfRestoreWarnings(); |
297 | 328 | } |
298 | | - wfRestoreWarnings(); |
299 | 329 | } |
300 | 330 | |
301 | 331 | /** |