. /** * Logging API * * Provides functionality to log system events other than bug related history. * * @package CoreAPI * @subpackage LoggingAPI * @copyright Copyright (C) 2000 - 2002 Kenzaburo Ito - kenito@300baud.org * @copyright Copyright (C) 2002 - 2011 MantisBT Team - mantisbt-dev@lists.sourceforge.net * @link http://www.mantisbt.org * * @uses config_api.php * @uses constant_inc.php * @uses event_api.php * @uses utility_api.php */ require_api( 'config_api.php' ); require_api( 'constant_inc.php' ); require_api( 'event_api.php' ); require_api( 'utility_api.php' ); $g_log_levels = array( LOG_EMAIL => 'MAIL', LOG_EMAIL_RECIPIENT => 'RECIPIENT', LOG_FILTERING => 'FILTER', LOG_AJAX => 'AJAX', LOG_LDAP => 'LDAP', LOG_DATABASE => 'DB', ); /** * Log an event * @param int $p_level Valid debug log level * @param string|array $p_msg Either a string, or an array structured as (string,execution time) * @param object $p_backtrace [Optional] debug_backtrace() stack to use * @return null */ function log_event( $p_level, $p_msg, $p_backtrace = null ) { global $g_log_levels; # check to see if logging is enabled $t_sys_log = config_get_global( 'log_level' ); if ( 0 == ( $t_sys_log & $p_level ) ) { return; } if( is_array( $p_msg ) ) { $t_event = $p_msg; $s_msg = var_export( $p_msg, true ); } else { $t_event = array( $p_msg, 0 ); $s_msg = $p_msg; } if( $p_backtrace === null ) { $t_backtrace = debug_backtrace(); } else { $t_backtrace = $p_backtrace; } $t_caller = basename( $t_backtrace[0]['file'] ); $t_caller .= ":" . $t_backtrace[0]['line']; # Is this called from another function? if( isset( $t_backtrace[1] ) ) { $t_caller .= ' ' . $t_backtrace[1]['function'] . '()'; } else { # or from a script directly? $t_caller .= ' ' . $_SERVER['SCRIPT_NAME']; } $t_now = date( config_get_global( 'complete_date_format' ) ); $t_level = $g_log_levels[$p_level]; $t_plugin_event = '[' . $t_level . '] ' . $p_msg; if( function_exists( 'event_signal' ) ) event_signal( 'EVENT_LOG', array( $t_plugin_event ) ); $t_log_destination = config_get_global( 'log_destination' ); if ( is_blank( $t_log_destination ) ) { $t_destination = ''; } else { @list( $t_destination, $t_modifiers ) = explode( ':', $t_log_destination, 2 ); } switch( $t_destination ) { case 'none': break; case 'file': $t_php_event = $t_now . ' ' . $t_level . ' ' . $s_msg; error_log( $t_php_event . PHP_EOL, 3, $t_modifiers ); break; case 'page': global $g_log_events; $g_log_events[] = array( time(), $p_level, $t_event, $t_caller); break; case 'firebug': if( !class_exists( 'FirePHP' ) ) { if( file_exists( config_get_global( 'library_path' ) . 'FirePHPCore' . DIRECTORY_SEPARATOR . 'FirePHP.class.php' ) ) { require_lib( 'FirePHPCore' . DIRECTORY_SEPARATOR . 'FirePHP.class.php' ); } } if( class_exists( 'FirePHP' ) ) { static $firephp; if( $firephp === null ) { $firephp = FirePHP::getInstance(true); } $t_php_event = $t_now . ' ' . $t_level . ' ' . $s_msg; $firephp->log( $p_msg, $t_php_event ); return; } // if firebug is not available, fall through default: # use default PHP error log settings $t_php_event = $t_now . ' ' . $t_level . ' ' . $s_msg; error_log( $t_php_event . PHP_EOL ); break; } } function log_print_to_page() { if ( config_get_global( 'log_destination' ) === 'page' && auth_is_user_authenticated() && access_has_global_level( config_get( 'show_log_threshold' ) ) ) { global $g_log_events, $g_log_levels; echo "\n\n"; echo "
| " . lang_get( 'log_page_number' ) . " | \n"; echo "\t\t\t" . lang_get( 'log_page_time' ) . " | \n"; echo "\t\t\t" . lang_get( 'log_page_caller' ) . " | \n"; echo "\t\t\t" . lang_get( 'log_page_event' ) . " | \n"; echo "\t\t
|---|