From f83036ae9d4439f3cfbb8c1d7ec06d3fd0b1f0e4 Mon Sep 17 00:00:00 2001 From: jerrywestrick Date: Wed, 8 Aug 2001 07:21:29 +0000 Subject: [PATCH] __FILE__, __LINE__ parameters --- admin/inc/class.uilog.inc.php | 64 ++++++++++++++++++++++------ phpgwapi/inc/class.error.inc.php | 39 ++++++++++++----- phpgwapi/inc/class.errorlog.inc.php | 58 ++++++++++++++++--------- phpgwapi/setup/setup.inc.php | 2 +- phpgwapi/setup/tables_update.inc.php | 14 +++++- 5 files changed, 132 insertions(+), 45 deletions(-) diff --git a/admin/inc/class.uilog.inc.php b/admin/inc/class.uilog.inc.php index 55af64d017..527b6084b1 100644 --- a/admin/inc/class.uilog.inc.php +++ b/admin/inc/class.uilog.inc.php @@ -39,6 +39,7 @@ + // Handle the Edit Table Button if (isset($editable)) { @@ -114,8 +115,11 @@ 'log_msg_date_e', 'log_msg_severity', 'log_msg_code', - 'log_msg_text' + 'log_msg_text', + 'log_msg_file', + 'log_msg_line' ); + // Store defaults in session data... $phpgw->session->appsession ('session_data', 'log', @@ -138,17 +142,51 @@ function list_log() { global $phpgw, $phpgw_info; -/* -$phpgw->log->write(array('text'=>'I-TestWrite, write: %1','p1'=>'This message should appear in log')); -$phpgw->log->message(array('text'=>'I-TestMsg, msg: %1','p1'=>'This message should appear in log')); -$phpgw->log->error(array('text'=>'I-TestInfo, info: %1','p1'=>'This Informational should not be in log')); -$phpgw->log->clearstack(); -$phpgw->log->error(array('text'=>'I-TestInfo, info: %1','p1'=>'This Informational should be in log')); -$phpgw->log->error(array('text'=>'W-TestWarn, warn: %1','p1'=>'This is a test Warning')); -$phpgw->log->error(array('text'=>'E-TestError, err: %1','p1'=>'This is a test Error')); -$phpgw->log->error(array('text'=>'F-Abend, abort: %1','p1'=>'Force abnormal termination')); -$phpgw->log->commit(); // commit error stack to log... -*/ + + if (false) // add some errors to the log... + { + // Test 1: single Error line immedeately to errorlog + // (could be type Debug, Info, Warning, or Error) + $phpgw->log->write(array('text'=>'I-TestWrite, write: %1','p1'=>'This message should appear in log','file'=>__FILE__,'line'=>__LINE__)); + + + // Test 2: A message should appear in log even if clearstack is called + $phpgw->log->message(array('text'=>'I-TestMsg, msg: %1','p1'=>'This message should appear in log','file'=>__FILE__,'line'=>__LINE__)); + $phpgw->log->error(array('text'=>'I-TestInfo, info: %1','p1'=>'This Informational should not be in log','file'=>__FILE__,'line'=>__LINE__)); + $phpgw->log->clearstack(); + $phpgw->log->commit(); // commit error stack to log... + + // Test 3: one debug message + $phpgw->log->error(array('text'=>'D-Debug, dbg: %1','p1'=>'This debug statment should be in log','file'=>__FILE__,'line'=>__LINE__)); + $phpgw->log->commit(); // commit error stack to log... + + // Test 3: debug and one informational + $phpgw->log->error(array('text'=>'D-Debug, dbg: %1','p1'=>'This debug statment should be in log','file'=>__FILE__,'line'=>__LINE__)); + $phpgw->log->error(array('text'=>'I-TestInfo, info: %1','p1'=>'This Informational should be in log','file'=>__FILE__,'line'=>__LINE__)); + $phpgw->log->commit(); // commit error stack to log... + + // Test 4: an informational and a Warning + $phpgw->log->error(array('text'=>'D-Debug, dbg: %1','p1'=>'This debug statment should be in log','file'=>__FILE__,'line'=>__LINE__)); + $phpgw->log->error(array('text'=>'I-TestInfo, info: %1','p1'=>'This Informational should be in log','file'=>__FILE__,'line'=>__LINE__)); + $phpgw->log->error(array('text'=>'W-TestWarn, warn: %1','p1'=>'This is a test Warning','file'=>__FILE__,'line'=>__LINE__)); + $phpgw->log->commit(); // commit error stack to log... + + // Test 5: and an error + $phpgw->log->error(array('text'=>'D-Debug, dbg: %1','p1'=>'This debug statment should be in log','file'=>__FILE__,'line'=>__LINE__)); + $phpgw->log->error(array('text'=>'I-TestInfo, info: %1','p1'=>'This Informational should be in log','file'=>__FILE__,'line'=>__LINE__)); + $phpgw->log->error(array('text'=>'W-TestWarn, warn: %1','p1'=>'This is a test Warning','file'=>__FILE__,'line'=>__LINE__)); + $phpgw->log->error(array('text'=>'E-TestError, err: %1','p1'=>'This is a test Error','file'=>__FILE__,'line'=>__LINE__)); + $phpgw->log->commit(); // commit error stack to log... + + + // Test 6: and finally a fatal... + $phpgw->log->error(array('text'=>'D-Debug, dbg: %1','p1'=>'This debug statment should be in log','file'=>__FILE__,'line'=>__LINE__)); + $phpgw->log->error(array('text'=>'I-TestInfo, info: %1','p1'=>'This Informational should be in log','file'=>__FILE__,'line'=>__LINE__)); + $phpgw->log->error(array('text'=>'W-TestWarn, warn: %1','p1'=>'This is a test Warning','file'=>__FILE__,'line'=>__LINE__)); + $phpgw->log->error(array('text'=>'E-TestError, err: %1','p1'=>'This is a test Error','file'=>__FILE__,'line'=>__LINE__)); + $phpgw->log->error(array('text'=>'F-Abend, abort: %1','p1'=>'Force abnormal termination','file'=>__FILE__,'line'=>__LINE__)); + + }; $this->t->set_file(array('log_list_t' => 'log.tpl')); /* // --------------------------------- nextmatch --------------------------- @@ -227,6 +265,7 @@ $phpgw->log->commit(); // commit error stack to log... switch($row[$this->column['log_severity']]['value']) { + case 'D': $row[$this->column['log_severity']]['bgcolor'] = 'D3DCFF'; break; case 'I': $row[$this->column['log_severity']]['bgcolor'] = 'C0FFC0'; break; case 'W': $row[$this->column['log_severity']]['bgcolor'] = 'FFFFC0'; break; case 'E': $row[$this->column['log_severity']]['bgcolor'] = 'FFC0C0'; break; @@ -235,6 +274,7 @@ $phpgw->log->commit(); // commit error stack to log... switch($row[$this->column['log_msg_severity']]['value']) { + case 'D': $color = 'D3DCFF'; break; case 'I': $color = 'C0FFC0'; break; case 'W': $color = 'FFFFC0'; break; case 'E': $color = 'FFC0C0'; break; diff --git a/phpgwapi/inc/class.error.inc.php b/phpgwapi/inc/class.error.inc.php index e7596c7e5b..48478afec6 100755 --- a/phpgwapi/inc/class.error.inc.php +++ b/phpgwapi/inc/class.error.inc.php @@ -23,24 +23,30 @@ var $parms = array(); var $ismsg = 0; var $timestamp; + var $fname; + var $line; + var $app; var $public_functions = array(); - /*******************************************\ - * Constructor * - * to be accessed as new error() * - \*******************************************/ // Translate Message into Language function langmsg() { return lang($this->msg,$this->parms); } - - function error($etext, $parms, $ismsg) + function error($parms) { global $phpgw; - if (eregi('([IWEF])-(.*)[\,](.*)',$etext,$match)) + if ($parms == '') + { + return; + }; + $etext =$parms['text']; + $parray = array($parms['p1'],$parms['p2'],$parms['p3'],$parms['p4'],$parms['p5'],$parms['p6'],$parms['p7'],$parms['p8'],$parms['p9'],$parms['p10']); + $fname = $parms['file']; + $line = $parms['line']; + if (eregi('([DIWEF])-(.*)[\,](.*)',$etext,$match)) { $this->severity = strtoupper($match[1]); $this->code = $match[2]; @@ -51,14 +57,25 @@ $this->msg = trim($etext); } $this->timestamp = time(); - $this->parms = $parms; - $this->ismsg = $ismsg; - + $this->parms = $parray; + $this->ismsg = $parms['ismsg']; + $this->fname = $fname; + $this->line = $line; + $this->app = $phpgw_info['flags']['currentapp']; + + if (!$this->fname or !$this->line) + { + $phpgw->log->error(array('text'=>'W-PGMERR, Programmer failed to pass __FILE__ and/or __LINE__ in next log message', + 'file'=>__FILE__,'line'=>__LINE__ + ) + ); + } + $phpgw->log->errorstack[] = $this; if ($this->severity == 'F') { // This is it... Don't return - // do rollback... + // do rollback! // Hmmm this only works if UI!!!! // What Do we do if it's a SOAP/XML? echo "
"; diff --git a/phpgwapi/inc/class.errorlog.inc.php b/phpgwapi/inc/class.errorlog.inc.php index 978eb3185c..f4709ac5d3 100644 --- a/phpgwapi/inc/class.errorlog.inc.php +++ b/phpgwapi/inc/class.errorlog.inc.php @@ -27,34 +27,38 @@ 'astable', ); - function message($parms) { - $etext =$parms['text']; - $parms = array($parms['p0'],$parms['p1'],$parms['p2'],$parms['p3'],$parms['p4'],$parms['p5'],$parms['p6'],$parms['p7'],$parms['p8'],$parms['p9']); - CreateObject('phpgwapi.error',$etext,$parms,1); + $parms['ismsg']=1; + CreateObject('phpgwapi.error',$parms); + return true; } function error($parms) { - $etext =$parms['text']; - $parms = array($parms['p0'],$parms['p1'],$parms['p2'],$parms['p3'],$parms['p4'],$parms['p5'],$parms['p6'],$parms['p7'],$parms['p8'],$parms['p9']); - CreateObject('phpgwapi.error',$etext,$parms,''); + $parms['ismsg']=0; + CreateObject('phpgwapi.error',$parms); + return true; } function write($parms) { - $etext =$parms['text']; - $parms = array($parms['p0'],$parms['p1'],$parms['p2'],$parms['p3'],$parms['p4'],$parms['p5'],$parms['p6'],$parms['p7'],$parms['p8'],$parms['p9']); + $parms['ismsg']=0; $save = $this->errorstack; $this->$errorstack = array(); - CreateObject('phpgwapi.error',$etext,$parms,1); + CreateObject('phpgwapi.error',$parms); $this->commit(); $this->errorstack = $save; + return true; } + + + + + function iserror($parms) { $ecode = $parms['code']; @@ -73,7 +77,7 @@ function severity() { - $max = 'I'; + $max = 'D'; $errorstack = $this->errorstack; reset($errorstack); while(list(,$err)=each($errorstack)) @@ -82,11 +86,15 @@ { case 'F': return 'F'; break; case 'E': $max = 'E'; break; - case 'W': if ($max == 'I') + case 'W': if ($max != 'E') { $max = 'W'; } break; + case 'I': if ($max == 'D') + { + $max = 'I'; + } } } return $max; @@ -97,7 +105,7 @@ global $phpgw, $phpgw_info; $db = $phpgw->db; - $db->lock('phpgw_log'); +// $db->lock('phpgw_log'); $db->query ("insert into phpgw_log (log_date, log_user, log_app, log_severity) values " ."('". $phpgw->db->to_timestamp(time() ) @@ -107,18 +115,19 @@ .")" ,__LINE__,__FILE__); - $db->query('select max(log_id) as lid from phpgw_log'); - $db->next_record(); - $log_id = $db->f('lid'); - $db->unlock(); + $log_id = $db->get_last_insert_id('phpgw_log','log_id'); +// $db->query('select max(log_id) as lid from phpgw_log'); +// $db->next_record(); +// $log_id = $db->f('lid'); +// $db->unlock(); $errorstack = $this->errorstack; for ($i = 0; $i < count($errorstack); $i++) { $err = $errorstack[$i]; $db->query ("insert into phpgw_log_msg " - ."(Log_msg_log_id, log_msg_seq_no, log_msg_date, " - ."log_msg_severity, log_msg_code, log_msg_msg, log_msg_parms) values " + ."(Log_msg_log_id, log_msg_seq_no, log_msg_date, log_msg_severity, " + ."log_msg_code, log_msg_msg, log_msg_parms, log_msg_file, log_msg_line) values " ."(" . $log_id ."," . $i .", '" . $phpgw->db->to_timestamp($err->timestamp @@ -127,12 +136,15 @@ .", '". $err->code . "'" .", '". $err->msg . "'" .", '". addslashes(implode('|',$err->parms)). "'" + .", '". $err->fname . "'" + .", ". $err->line .")" ,__LINE__,__FILE__); }; unset ($errorstack); unset ($this->errorstack); $this->errorstack = array(); + return true; } @@ -150,6 +162,7 @@ } unset ($this->errorstack); $this->errorstack = $new; + return true; } function astable() @@ -165,6 +178,8 @@ $html .= "\t\tS\n"; $html .= "\t\tError Code\n"; $html .= "\t\tMsg\n"; + $html .= "\t\tFile\n"; + $html .= "\t\tLine\n"; $html .= "\t\n"; $errorstack = $this->errorstack; @@ -173,6 +188,7 @@ $err = $errorstack[$i]; switch ($err->severity) { + case 'D': $color = 'D3DCFF'; break; case 'I': $color = 'C0FFC0'; break; case 'W': $color = 'FFFFC0'; break; case 'E': $color = 'FFC0C0'; break; @@ -182,10 +198,12 @@ $html .= "\t\n"; $html .= "\t\t".$i."\n"; $html .= "\t\t".$phpgw->common->show_date($err->timestamp)."\n"; - $html .= "\t\t".$phpgw_info['flags']['currentapp']."  \n"; + $html .= "\t\t".$err->app."  \n"; $html .= "\t\t".$err->severity."\n"; $html .= "\t\t".$err->code."\n"; $html .= "\t\t".$err->langmsg()."\n"; + $html .= "\t\t".$err->fname."\n"; + $html .= "\t\t".$err->line."\n"; $html .= "\t\n"; }; $html .= "\n"; diff --git a/phpgwapi/setup/setup.inc.php b/phpgwapi/setup/setup.inc.php index 492bc134e2..0dcaae1270 100755 --- a/phpgwapi/setup/setup.inc.php +++ b/phpgwapi/setup/setup.inc.php @@ -14,7 +14,7 @@ /* Basic information about this app */ $setup_info['phpgwapi']['name'] = 'phpgwapi'; $setup_info['phpgwapi']['title'] = 'phpgwapi'; - $setup_info['phpgwapi']['version'] = '0.9.13.008'; + $setup_info['phpgwapi']['version'] = '0.9.13.009'; $setup_info['phpgwapi']['versions']['current_header'] = '1.17'; $setup_info['phpgwapi']['enable'] = 3; $setup_info['phpgwapi']['app_order'] = 1; diff --git a/phpgwapi/setup/tables_update.inc.php b/phpgwapi/setup/tables_update.inc.php index e72d1c7278..b82e5a855b 100644 --- a/phpgwapi/setup/tables_update.inc.php +++ b/phpgwapi/setup/tables_update.inc.php @@ -2024,7 +2024,7 @@ } - $test[] = '0.9.13.007'; // version number? + $test[] = '0.9.13.007'; function phpgwapi_upgrade0_9_13_007() { global $setup_info, $phpgw_setup; @@ -2035,4 +2035,16 @@ return $setup_info['phpgwapi']['currentver']; } + $test[] = '0.9.13.008'; + function phpgwapi_upgrade0_9_13_008() + { + global $setup_info, $phpgw_setup; + + $phpgw_setup->oProc->AddColumn('phpgw_log_msg','log_msg_file',array('type' => 'varchar', 'precision' => 255, 'nullable'=> False)); + $phpgw_setup->oProc->AddColumn('phpgw_log_msg','log_msg_line',array('type' => 'int', 'precision' => 4, 'nullable'=> False)); + + $setup_info['phpgwapi']['currentver'] = '0.9.13.008'; + return $setup_info['phpgwapi']['currentver']; + } + ?>