From f820b6edcd3b2b22d64aef71b2750253d2bcafcd Mon Sep 17 00:00:00 2001 From: nickw Date: Mon, 19 Oct 2009 17:15:35 +0000 Subject: Adding debug options to admin site settings. Debugging errors and warnings to screen. If notice level is enabled, output is sent to system log file. git-svn-id: http://code.elgg.org/elgg/trunk@3563 36083f99-b078-4883-b0ff-0f9b5a30f544 --- CHANGES.txt | 1 + actions/admin/site/update_basic.php | 2 +- actions/systemsettings/install.php | 2 +- engine/lib/elgglib.php | 30 +++++++++++++++++++++--------- languages/en.php | 5 ++++- views/default/settings/system.php | 5 ++++- views/failsafe/settings/system.php | 5 ++++- 7 files changed, 36 insertions(+), 14 deletions(-) diff --git a/CHANGES.txt b/CHANGES.txt index e106b5139..16f5cb4bd 100644 --- a/CHANGES.txt +++ b/CHANGES.txt @@ -5,6 +5,7 @@ http://code.elgg.org/elgg/..... User-visible changes: * UTF8 now saved correctly in database. #1151 * Unit tests added at engine/tests/suites.php + * Debug values output to screen when enabled in admin settings Bugfixes: * Searching by tag with extended characters now works. #1151, #1231 diff --git a/actions/admin/site/update_basic.php b/actions/admin/site/update_basic.php index 0b567340c..70cc72730 100644 --- a/actions/admin/site/update_basic.php +++ b/actions/admin/site/update_basic.php @@ -56,7 +56,7 @@ if (get_input('settings') == 'go') { $debug = get_input('debug'); if ($debug) { - set_config('debug', 1, $site->getGUID()); + set_config('debug', $debug, $site->getGUID()); } else { unset_config('debug', $site->getGUID()); } diff --git a/actions/systemsettings/install.php b/actions/systemsettings/install.php index 819ef08ee..ef606315b 100644 --- a/actions/systemsettings/install.php +++ b/actions/systemsettings/install.php @@ -62,7 +62,7 @@ if (get_input('settings') == 'go') { $debug = get_input('debug'); if ($debug) { - set_config('debug', 1, $site->getGUID()); + set_config('debug', $debug, $site->getGUID()); } else { unset_config('debug', $site->getGUID()); } diff --git a/engine/lib/elgglib.php b/engine/lib/elgglib.php index 36e87eca9..a77922a9f 100644 --- a/engine/lib/elgglib.php +++ b/engine/lib/elgglib.php @@ -1752,23 +1752,26 @@ function elgg_log($message, $level='NOTICE') { // only log when debugging is enabled if (isset($CONFIG->debug)) { + // debug to screen or log? + $to_screen = !($CONFIG->debug == 'NOTICE'); + switch ($level) { case 'DEBUG': case 'ERROR': // always report - elgg_dump("$level: $message"); + elgg_dump("$level: $message", $to_screen); break; case 'WARNING': // report execept if user wants only errors - if ($config->debug != 'ERROR') { - elgg_dump("$level: $message"); + if ($CONFIG->debug != 'ERROR') { + elgg_dump("$level: $message", $to_screen); } break; case 'NOTICE': default: // only report when lowest level is desired - if ($config->debug == 'NOTICE') { - elgg_dump("$level: $message"); + if ($CONFIG->debug == 'NOTICE') { + elgg_dump("$level: $message", FALSE); } break; } @@ -1783,14 +1786,23 @@ function elgg_log($message, $level='NOTICE') { * Extremely generic var_dump-esque wrapper * * Immediately dumps the given $value to the screen as a human-readable string. + * The $value can instead be written to the system log through the use of the + * $to_screen flag. * * @param mixed $value + * @param bool $to_screen * @return void */ -function elgg_dump($value) { - echo '
';
-	print_r($value);
-	echo '
'; +function elgg_dump($value, $to_screen = TRUE) { + if ($to_screen == TRUE) { + echo '
';
+		print_r($value);
+		echo '
'; + } + else + { + error_log($value); + } } /** diff --git a/languages/en.php b/languages/en.php index c93f36fd7..310f5cd09 100644 --- a/languages/en.php +++ b/languages/en.php @@ -798,7 +798,10 @@ Alternatively, you can enter your database settings below and we will try and do 'installation:sitepermissions' => "The default access permissions:", 'installation:language' => "The default language for your site:", 'installation:debug' => "Debug mode provides extra information which can be used to diagnose faults, however it can slow your system down so should only be used if you are having problems:", - 'installation:debug:label' => "Turn on debug mode", + 'installation:debug:none' => 'Turn off debug mode (recommended)', + 'installation:debug:error' => 'Display only critical errors', + 'installation:debug:warning' => 'Display errors and warnings', + 'installation:debug:notice' => 'Log all errors, warnings and notices', 'installation:httpslogin' => "Enable this to have user logins performed over HTTPS. You will need to have https enabled on your server for this to work.", 'installation:httpslogin:label' => "Enable HTTPS logins", 'installation:usage' => "This option lets Elgg send anonymous usage statistics back to Curverider.", diff --git a/views/default/settings/system.php b/views/default/settings/system.php index 8df843276..e335b8576 100644 --- a/views/default/settings/system.php +++ b/views/default/settings/system.php @@ -38,7 +38,10 @@ $form_body .= "

" . elgg_echo('installation:allow_user_d $form_body .= "

" . elgg_echo('installation:simplecache:description') . "
" .elgg_view("input/checkboxes", array('options' => array(elgg_echo('installation:simplecache:label')), 'internalname' => 'simplecache_enabled', 'value' => ($vars['config']->simplecache_enabled ? elgg_echo('installation:simplecache:label') : "") )) . "

"; $form_body .= "

" . elgg_echo('installation:viewpathcache:description') . "
" .elgg_view("input/checkboxes", array('options' => array(elgg_echo('installation:viewpathcache:label')), 'internalname' => 'viewpath_cache_enabled', 'value' => (($vars['config']->viewpath_cache_enabled) ? elgg_echo('installation:viewpathcache:label') : "") )) . "

"; -$form_body .= "

" . elgg_echo('installation:debug') . "
" .elgg_view("input/checkboxes", array('options' => array(elgg_echo('installation:debug:label')), 'internalname' => 'debug', 'value' => ($vars['config']->debug ? elgg_echo('installation:debug:label') : "") )) . "

"; +$debug_options = array('0' => elgg_echo('installation:debug:none'), 'ERROR' => elgg_echo('installation:debug:error'), 'WARNING' => elgg_echo('installation:debug:warning'), 'NOTICE' => elgg_echo('installation:debug:notice')); +$form_body .= "

" . elgg_echo('installation:debug'); +$form_body .= elgg_view('input/pulldown', array('options_values' => $debug_options, 'internalname' => 'debug', 'value' => $vars['config']->debug)); +$form_body .= '

'; $form_body .= "

" . elgg_echo('installation:httpslogin') . "
" .elgg_view("input/checkboxes", array('options' => array(elgg_echo('installation:httpslogin:label')), 'internalname' => 'https_login', 'value' => ($vars['config']->https_login ? elgg_echo('installation:httpslogin:label') : "") )) . "

"; diff --git a/views/failsafe/settings/system.php b/views/failsafe/settings/system.php index aa06dd44c..dfc7ecc41 100644 --- a/views/failsafe/settings/system.php +++ b/views/failsafe/settings/system.php @@ -39,7 +39,10 @@ $form_body .= "

" . elgg_echo('installation:language') . elgg_view("input/pull $form_body .= "

" . elgg_echo('installation:sitepermissions') . elgg_view('input/access', array('internalname' => 'default_access','value' => ACCESS_LOGGED_IN)) . "

"; -$form_body .= "

" . elgg_echo('installation:debug') . "
" .elgg_view("input/checkboxes", array('options' => array(elgg_echo('installation:debug:label')), 'internalname' => 'debug', 'value' => ($vars['config']->debug ? elgg_echo('installation:debug:label') : "") )) . "

"; +$debug_options = array('0' => elgg_echo('installation:debug:none'), 'ERROR' => elgg_echo('installation:debug:error'), 'WARNING' => elgg_echo('installation:debug:warning'), 'NOTICE' => elgg_echo('installation:debug:notice')); +$form_body .= "

" . elgg_echo('installation:debug'); +$form_body .= elgg_view('input/pulldown', array('options_values' => $debug_options, 'internalname' => 'debug', 'value' => $vars['config']->debug)); +$form_body .= '

'; $form_body .= "

" . elgg_echo('installation:httpslogin') . "
" .elgg_view("input/checkboxes", array('options' => array(elgg_echo('installation:httpslogin:label')), 'internalname' => 'https_login', 'value' => ($vars['config']->https_login ? elgg_echo('installation:httpslogin:label') : "") )) . "

"; -- cgit v1.2.3