From a549004e6dd256f2abf59aa21f625e46704b5d45 Mon Sep 17 00:00:00 2001 From: Tim Starling Date: Fri, 5 Sep 2008 03:46:07 +0000 Subject: [PATCH] In wfDebugLog(): log the hostname if $wgShowHostnames is true. Cache the hostname. --- includes/GlobalFunctions.php | 35 ++++++++++++++++++++++------------- 1 file changed, 22 insertions(+), 13 deletions(-) diff --git a/includes/GlobalFunctions.php b/includes/GlobalFunctions.php index 4d50956e99..e6aca47ee6 100644 --- a/includes/GlobalFunctions.php +++ b/includes/GlobalFunctions.php @@ -255,12 +255,17 @@ function wfDebugMem( $exact = false ) { * log file is specified, (default true) */ function wfDebugLog( $logGroup, $text, $public = true ) { - global $wgDebugLogGroups; + global $wgDebugLogGroups, $wgShowHostnames; if( $text{strlen( $text ) - 1} != "\n" ) $text .= "\n"; if( isset( $wgDebugLogGroups[$logGroup] ) ) { $time = wfTimestamp( TS_DB ); $wiki = wfWikiID(); - wfErrorLog( "$time $wiki: $text", $wgDebugLogGroups[$logGroup] ); + if ( $wgShowHostnames ) { + $host = wfHostname(); + } else { + $host = ''; + } + wfErrorLog( "$time $host $wiki: $text", $wgDebugLogGroups[$logGroup] ); } else if ( $public === true ) { wfDebug( $text, true ); } @@ -767,18 +772,22 @@ function wfDebugDieBacktrace( $msg = '' ) { * @return string */ function wfHostname() { - if ( function_exists( 'posix_uname' ) ) { - // This function not present on Windows - $uname = @posix_uname(); - } else { - $uname = false; - } - if( is_array( $uname ) && isset( $uname['nodename'] ) ) { - return $uname['nodename']; - } else { - # This may be a virtual server. - return $_SERVER['SERVER_NAME']; + static $host; + if ( is_null( $host ) ) { + if ( function_exists( 'posix_uname' ) ) { + // This function not present on Windows + $uname = @posix_uname(); + } else { + $uname = false; + } + if( is_array( $uname ) && isset( $uname['nodename'] ) ) { + $host = $uname['nodename']; + } else { + # This may be a virtual server. + $host = $_SERVER['SERVER_NAME']; + } } + return $host; } /** -- 2.20.1