diff --git a/phpgwapi/inc/common_functions.inc.php b/phpgwapi/inc/common_functions.inc.php index 61dc5d4593..e72b4b08e1 100755 --- a/phpgwapi/inc/common_functions.inc.php +++ b/phpgwapi/inc/common_functions.inc.php @@ -1422,13 +1422,12 @@ function __autoload($class) } /** - * Fail a little bit more gracefully then an uncought exception - * - * Does NOT return - * + * Clasify exception for a headline and log it to error_log, if not running as cli + * * @param Exception $e + * @param string &$headline */ -function egw_exception_handler(Exception $e) +function _egw_log_exception(Exception $e,&$headline=null) { if ($e instanceof egw_exception_no_permission) { @@ -1446,6 +1445,29 @@ function egw_exception_handler(Exception $e) { $headline = try_lang('An error happened'); } + // log exception to error log, if not running as cli, + // which outputs the error_log to stderr and therefore output it twice to the user + if(!isset($_SERVER['HTTP_HOST']) || $GLOBALS['egw_info']['flags']['no_exception_handler'] == 'cli') + { + error_log($headline.': '.$e->getMessage()); + foreach(explode("\n",$e->getTraceAsString()) as $line) error_log($line); + error_log('# Instance='.$GLOBALS['egw_info']['user']['domain'].', User='.$GLOBALS['egw_info']['user']['account_lid'].', URL='. + ($_SERVER['HTTPS']?'https://':'http://').$_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI']); + } +} + +/** + * Fail a little bit more gracefully then an uncought exception + * + * Does NOT return + * + * @param Exception $e + */ +function egw_exception_handler(Exception $e) +{ + // logging all exceptions to the error_log (if not cli) and get headline + _egw_log_exception($e,$headline); + // exception handler for cli (command line interface) clients, no html, no logging if(!isset($_SERVER['HTTP_HOST']) || $GLOBALS['egw_info']['flags']['no_exception_handler'] == 'cli') { @@ -1456,12 +1478,6 @@ function egw_exception_handler(Exception $e) } exit($e->getCode() ? $e->getCode() : 9999); // allways give a non-zero exit code } - // logging all exceptions to the error_log - error_log($headline.': '.$e->getMessage()); - foreach(explode("\n",$e->getTraceAsString()) as $line) error_log($line); - error_log('# Instance='.$GLOBALS['egw_info']['user']['domain'].', User='.$GLOBALS['egw_info']['user']['account_lid'].', URL='. - ($_SERVER['HTTPS']?'https://':'http://').$_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI']); - // regular GUI exception if (!isset($GLOBALS['egw_info']['flags']['no_exception_handler'])) { @@ -1494,9 +1510,9 @@ function egw_exception_handler(Exception $e) header('HTTP/1.1 401 Unauthorized'); header('X-WebDAV-Status: 401 Unauthorized', true); } - if (is_object($GLOBALS['egw']) && isset($GLOBALS['egw']->common)) + if (is_object($GLOBALS['egw'])) { - $GLOBALS['egw']->common->egw_exit(); + common::egw_exit(); } exit; } diff --git a/xajax.php b/xajax.php index 09ace44179..6080f02a4c 100644 --- a/xajax.php +++ b/xajax.php @@ -33,7 +33,7 @@ function xajax_redirect(&$anon_account) } /** - * Exception handler for xajax, return the message (and trace) as alert() to the user + * Exception handler for xajax, return the message (and trace, if enabled) as alert() to the user * * Does NOT return! * @@ -41,8 +41,20 @@ function xajax_redirect(&$anon_account) */ function ajax_exception_handler(Exception $e) { + // logging all exceptions to the error_log + if (function_exists('_egw_log_exception')) + { + _egw_log_exception($e,$message); + } $response = new xajaxResponse(); - $response->addAlert($e->getMessage()."\n\n".$e->getTraceAsString()); + $message .= ($message ? "\n\n" : '').$e->getMessage(); + + // only show trace (incl. function arguments) if explicitly enabled, eg. on a development system + if ($GLOBALS['egw_info']['server']['exception_show_trace']) + { + $message .= "\n\n".$e->getTraceAsString(); + } + $response->addAlert($message); $response->printOutput(); if (is_object($GLOBALS['egw']))