[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Phpgroupware-cvs] phpgwapi/inc class.log.inc.php class.log_messag...
From: |
Dave Hall |
Subject: |
[Phpgroupware-cvs] phpgwapi/inc class.log.inc.php class.log_messag... |
Date: |
Tue, 19 Sep 2006 15:16:42 +0000 |
CVSROOT: /cvsroot/phpgwapi
Module name: phpgwapi
Changes by: Dave Hall <skwashd> 06/09/19 15:16:42
Modified files:
inc : class.log.inc.php class.log_message.inc.php
functions.inc.php
Log message:
most of the new error hander code
CVSWeb URLs:
http://cvs.savannah.gnu.org/viewcvs/phpgwapi/inc/class.log.inc.php?cvsroot=phpgwapi&r1=1.11&r2=1.12
http://cvs.savannah.gnu.org/viewcvs/phpgwapi/inc/class.log_message.inc.php?cvsroot=phpgwapi&r1=1.3&r2=1.4
http://cvs.savannah.gnu.org/viewcvs/phpgwapi/inc/functions.inc.php?cvsroot=phpgwapi&r1=1.197&r2=1.198
Patches:
Index: class.log.inc.php
===================================================================
RCS file: /cvsroot/phpgwapi/phpgwapi/inc/class.log.inc.php,v
retrieving revision 1.11
retrieving revision 1.12
diff -u -b -r1.11 -r1.12
--- class.log.inc.php 10 Sep 2006 14:18:47 -0000 1.11
+++ class.log.inc.php 19 Sep 2006 15:16:42 -0000 1.12
@@ -7,7 +7,7 @@
* @license http://www.fsf.org/licenses/gpl.html GNU General Public
License
* @package phpgwapi
* @subpackage application
- * @version $Id: class.log.inc.php,v 1.11 2006/09/10 14:18:47 skwashd
Exp $
+ * @version $Id: class.log.inc.php,v 1.12 2006/09/19 15:16:42 skwashd
Exp $
*/
/**
@@ -26,30 +26,35 @@
var $public_functions = array(
'debug',
'info',
+ 'notice',
'warn',
'error',
'fatal',
'iserror',
- // the following 3 are for backward compatibility
+ // the following 3 are for backwards compatibility only
'write',
'message',
'commit'
);
- var $log_level_table = array(
+ var $log_level_table = array
+ (
'F' => 1,
'E' => 2,
'W' => 3,
- 'I' => 4,
- 'D' => 5
+ 'N' => 4,
+ 'I' => 5,
+ 'D' => 6
);
// these are used by the admin appliation when showing the log
file.
- var $log_level_names = array(
+ var $log_level_names = array
+ (
'F' => 'fatal',
'E' => 'error',
'W' => 'warn',
+ 'N' => 'notice',
'I' => 'info',
'D' => 'debug'
);
@@ -73,19 +78,22 @@
function is_level($level)
{
$this->checkprefs();
- if (
$this->log_level_table[$GLOBALS['phpgw_info']['server']['log_levels']['global_level']]
>= $this->log_level_table[$level] ) {
+ if (
$this->log_level_table[$GLOBALS['phpgw_info']['server']['log_levels']['global_level']]
>= $this->log_level_table[$level] )
+ {
return true;
}
- if ( (
isset($GLOBALS['phpgw_info']['flags']['currentapp']) )
- && ( @array_key_exists(
$GLOBALS['phpgw_info']['flags']['currentapp'] ,
$GLOBALS['phpgw_info']['server']['log_levels']['module']) )
- && (
$this->log_level_table[$GLOBALS['phpgw_info']['server']['log_levels']['module'][$GLOBALS['phpgw_info']['flags']['currentapp']]]
>= $this->log_level_table[$level] ) ) {
+ if (
isset($GLOBALS['phpgw_info']['flags']['currentapp'])
+ && @array_key_exists(
$GLOBALS['phpgw_info']['flags']['currentapp'] ,
$GLOBALS['phpgw_info']['server']['log_levels']['module'])
+ &&
$this->log_level_table[$GLOBALS['phpgw_info']['server']['log_levels']['module'][$GLOBALS['phpgw_info']['flags']['currentapp']]]
>= $this->log_level_table[$level] )
+ {
return true;
}
- if ( (
isset($GLOBALS['phpgw_info']['user']['account_lid']) )
- && (
@array_key_exists($GLOBALS['phpgw_info']['user']['account_lid'],
$GLOBALS['phpgw_info']['server']['log_levels']['user']) )
- && (
$this->log_level_table[$GLOBALS['phpgw_info']['server']['log_levels']['user'][$GLOBALS['phpgw_info']['user']['account_lid']]]
>= $this->log_level_table[$level] ) ) {
+ if (
isset($GLOBALS['phpgw_info']['user']['account_lid'])
+ &&
@array_key_exists($GLOBALS['phpgw_info']['user']['account_lid'],
$GLOBALS['phpgw_info']['server']['log_levels']['user'])
+ &&
$this->log_level_table[$GLOBALS['phpgw_info']['server']['log_levels']['user'][$GLOBALS['phpgw_info']['user']['account_lid']]]
>= $this->log_level_table[$level] )
+ {
return true;
}
@@ -95,9 +103,8 @@
function log_if_level($level, $parms)
{
- if ( $this->is_level($level) ) {
-
-
+ if ( $this->is_level($level) )
+ {
$parms['severity']=$level;
$err =
createObject('phpgwapi.log_message',$parms);
$this->write_error_to_db($err);
@@ -105,13 +112,14 @@
// the old methods.
return true;
}
- else {
+ else
+ {
return false;
}
}
- function log() {
- }
+ function log()
+ {}
function make_parms($arg_array)
{
@@ -154,6 +162,12 @@
return $this->log_if_level('I',
$this->make_parms($arg_array));
}
+ function notice()
+ {
+ $arg_array = func_get_args();
+ return $this->log_if_level('N',
$this->make_parms($arg_array));
+ }
+
function warn()
{
$arg_array = func_get_args();
Index: class.log_message.inc.php
===================================================================
RCS file: /cvsroot/phpgwapi/phpgwapi/inc/class.log_message.inc.php,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -b -r1.3 -r1.4
--- class.log_message.inc.php 10 Sep 2006 14:18:47 -0000 1.3
+++ class.log_message.inc.php 19 Sep 2006 15:16:42 -0000 1.4
@@ -7,7 +7,7 @@
* @license http://www.fsf.org/licenses/gpl.html GNU General Public
License
* @package phpgwapi
* @subpackage application
- * @version $Id: class.log_message.inc.php,v 1.3 2006/09/10 14:18:47
skwashd Exp $
+ * @version $Id: class.log_message.inc.php,v 1.4 2006/09/19 15:16:42
skwashd Exp $
*/
/**
@@ -65,23 +65,16 @@
// DWD - override the severity in the message with that
provided in the parms.
// Eventually, the old logging will go away and the
above code can be removed.
- if ( isset($parms['severity']) && $params['severity'] )
+ if ( isset($params['severity']) && $params['severity']
)
{
$this->severity = $parms['severity'];
}
- @reset($parray);
- while( list($key,$val) = each( $parray ) )
- {
- // Experimental code using print_r on
parameters. Don't know if I'll keep this. DWD
- // Make it configurable?
- if ( version_compare(phpversion(), "4.3.0",
">=") )
+ foreach ( $parray as $key => $val )
{
$val = print_r($val, true);
- }
$this->msg = preg_replace( "/%$key/",
"'".$val."'", $this->msg );
}
- @reset($parray);
$this->timestamp = time();
Index: functions.inc.php
===================================================================
RCS file: /cvsroot/phpgwapi/phpgwapi/inc/functions.inc.php,v
retrieving revision 1.197
retrieving revision 1.198
diff -u -b -r1.197 -r1.198
--- functions.inc.php 9 Sep 2006 11:45:35 -0000 1.197
+++ functions.inc.php 19 Sep 2006 15:16:42 -0000 1.198
@@ -7,7 +7,7 @@
* @license http://www.fsf.org/licenses/lgpl.html GNU Lesser General
Public License
* @package phpgwapi
* @subpackage utilities
- * @version $Id: functions.inc.php,v 1.197 2006/09/09 11:45:35 skwashd
Exp $
+ * @version $Id: functions.inc.php,v 1.198 2006/09/19 15:16:42 skwashd
Exp $
*/
@@ -99,6 +99,153 @@
return $value;
}
+ /**
+ * cleans up a backtrace array and converts it to a string
+ *
+ * @param array $bt php backtrace
+ * @return string the formatted backtrace, empty if the user is not an
admin
+ */
+ function phpgw_parse_backtrace($bt)
+ {
+ if ( !is_array($bt) )
+ {
+ return '';
+ }
+
+ $trace = array();
+ $trace[0] = array();
+
+ if ( isset($bt[0]['function']) )
+ {
+ $trace[0]['function'] = $bt[0]['function'];
+ }
+
+ if ( isset($bt[0]['args']) && is_array($bt[0]['args']) )
+ {
+ $trace[0]['args'] = array($bt[0]['args'][0],
$bt[0]['args'][1], $bt[0]['args'][2], $bt[0]['args'][3],
'***error_handler_content_data***');
+ }
+
+ if ( isset($bt[0]['file']) )
+ {
+ $trace[0]['file'] = $bt[0]['file'];
+ }
+
+ if ( isset($bt[0]['line']) )
+ {
+ $trace[0]['line'] = $bt[0]['line'];
+ }
+ unset($bt[0]);
+
+ foreach ( $bt as $num => $entry )
+ {
+ if ( isset($entry['file']) )
+ {
+ $trace[$num]['file'] = '/path/to/phpgroupware'
. substr($entry['file'], strlen(PHPGW_SERVER_ROOT) );
+ }
+
+ if ( isset($entry['line']) )
+ {
+ $trace[$num]['line'] = $entry['line'];
+ }
+
+ if ( isset($entry['line']) )
+ {
+ $trace[$num]['line'] = $entry['line'];
+ }
+
+ if ( isset($entry['type']) && isset($entry['class']) )
+ {
+ $trace[$num]['function'] =
"{$entry['class']}{$entry['type']}{$entry['function']}";
+ }
+ else
+ {
+ $trace[$num]['function'] = $entry['function'];
+ }
+
+ if ( isset($entry['args']) && is_array($entry['args'])
&& count($entry['args']) )
+ {
+ foreach ( $entry['args'] as $anum => $arg )
+ {
+ if ( is_array($arg) )
+ {
+ $trace[$num]['args'][$anum] =
print_r($arg, true);
+ continue;
+ }
+
+ // Drop passwords from backtrace
+ if ( $arg ==
$GLOBALS['phpgw_info']['server']['header_admin_password']
+ || $arg ==
$GLOBALS['phpgw_info']['server']['db_pass']
+ || $arg ==
$GLOBALS['phpgw_info']['user']['passwd']
+ )
+ {
+ $trace[$num]['args'][$anum] =
'***PASSWORD***';
+ }
+ else
+ {
+ $trace[$num]['args'][$anum] =
$arg;
+ }
+ }
+ }
+ else
+ {
+ $trace[$num]['args'] = 'NONE';
+ }
+ }
+ return print_r($trace, true);
+ }
+
+ /**
+ * phpGroupWare generic error handler
+ */
+ function phpgw_handle_error($error_level, $error_msg, $error_file,
$error_line)
+ {
+ if ( error_reporting() == 0 ) // 0 == @function() so we ignore
it, as the dev requested
+ {
+ return true;
+ }
+
+ if ( !isset($GLOBALS['phpgw']->log)
+ || !is_object($GLOBALS['phpgw']->log) )
+ {
+ $GLOBALS['phpgw']->log = createObject('phpgw.log');
+ }
+
+ $log =& $GLOBALS['phpgw']->log;
+
+ $error_file = '/path/to/phpgroupware' . substr($error_file,
strlen(PHPGW_SERVER_ROOT) );
+
+ $bt = debug_backtrace();
+
+ $log_args = array
+ (
+ 'file' => $error_file,
+ 'line' => $error_line,
+ 'text' => "$error_msg\n" . phpgw_parse_backtrace($bt)
+ );
+
+ switch ( $error_level )
+ {
+ case E_USER_ERROR:
+ case E_ERROR:
+ $log_args['severity'] = 'F'; //all "ERRORS"
should be fatal
+ $log->fatal($log_args);
+ break;
+ case E_WARNING:
+ case E_USER_WARNING:
+ $log_args['severity'] = 'W';
+ $log->warn($log_args);
+ echo "\n<br>" . lang('ERROR Warning: %1 in %2
at line %3', $error_msg, $error_file, $error_line) . "<br>\n";
+ break;
+ case E_NOTICE:
+ case E_USER_NOTICE:
+ default:
+ $log_args['severity'] = 'I';
+ $log->notice($log_args);
+ echo "\n<br>" . lang('ERROR Notice: %1 in %2 at
line %3', $error_msg, $error_file, $error_line) . "<br>\n"; //this will be
commented in the final version
+ }
+ }
+ set_error_handler('phpgw_handle_error');
+
function clean_vars($vars, $safe_redirect = True)
{
if ( !is_array($vars) )