[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Phpgroupware-cvs] phpgwapi/inc class.log.inc.php, 1.6.4.1, 1.6.4.2 comm
From: |
Chris Weiss <address@hidden> |
Subject: |
[Phpgroupware-cvs] phpgwapi/inc class.log.inc.php, 1.6.4.1, 1.6.4.2 common_functions.inc.php, 1.16.2.5, 1.16.2.6 functions.inc.php, 1.121.2.13.2.16, 1.121.2.13.2.17 |
Date: |
Sun, 19 Oct 2003 01:34:05 +0000 |
Update of /cvsroot/phpgroupware/phpgwapi/inc
In directory subversions:/tmp/cvs-serv4760/phpgwapi/inc
Modified Files:
Tag: Version-0_9_16-branch
class.log.inc.php common_functions.inc.php functions.inc.php
Log Message:
improved logging classes, patch #2100
Index: common_functions.inc.php
===================================================================
RCS file: /cvsroot/phpgroupware/phpgwapi/inc/common_functions.inc.php,v
retrieving revision 1.16.2.5
retrieving revision 1.16.2.6
diff -C2 -d -r1.16.2.5 -r1.16.2.6
*** common_functions.inc.php 9 Oct 2003 08:18:45 -0000 1.16.2.5
--- common_functions.inc.php 19 Oct 2003 01:34:03 -0000 1.16.2.6
***************
*** 33,157 ****
@abstract Direct functions which are not part of the API classes
because they are required to be available at the lowest level.
*/
- /*!
- @function print_debug_subarray
- @abstract Not to be used directly. Should only be used by print_debug()
- */
- function print_debug_subarray($array)
- {
- while(list($key, $value) = each($array))
- {
- if (is_array($value))
- {
- $vartypes[$key] = print_debug_subarray($value);
- }
- else
- {
- $vartypes[$key] = gettype($value);
- }
- }
- return $vartypes;
- }
-
- /*!
- @function print_debug
- @abstract print debug data only when debugging mode is turned on.
- @author seek3r
- @discussion This function is used to debugging data.
- @syntax print_debug('message', $somevar);
- @example print_debug('this is some debugging data',$somevar);
- */
- function print_debug($message,$var = 'messageonly',$part = 'app',
$level = 3)
- {
- // if (($part == 'app' && EXP_DEBUG_APP == True) || ($part ==
'api' && DEBUG_API == True))
- if (($part == 'app' && DEBUG_APP == True) || ($part == 'api' &&
DEBUG_API == True))
- {
- if (!defined('DEBUG_OUTPUT'))
- {
- define('DEBUG_OUTPUT', 1);
- }
- if ($level >= DEBUG_LEVEL)
- {
- if (!is_array($var))
- {
- if ($var != 'messageonly')
- {
- if (!DEBUG_DATATYPES)
- {
- $output =
"$message\n$var";
- }
- else
- {
- $output =
"$message\n$var is a ".gettype($var);
- }
- }
- else
- {
- $output = $message;
- }
-
- /* Bit 1 means to output to screen */
- if (!!(DEBUG_OUTPUT & 1))
- {
- echo "$output<br>\n";
- }
- /* Bit 2 means to output to sql */
- if (!!(DEBUG_OUTPUT & 2))
- {
- /* Need to flesh this out
still. I dont have a table to dump this in yet.*/
- /* So the SQL statement will go
here*/
- }
-
- /* Example of how this can be extended
to output to other locations as well. This example uses a COM object */
- /*
- if (!!(DEBUG_OUTPUT & 32))
- {
- $obj_debug = new
COM('Some_COM_App.Class','localhost');
- if (is_object($obj_debug))
- {
- $DebugMessage_return =
$obj_debug->DebugMessage($output);
- }
- }
- */
- }
- else
- {
- if (floor(phpversion()) > 3 &&
!!(DEBUG_OUTPUT & 2))
- {
- ob_start();
- }
- echo "<pre>\n$message\n";
- print_r($var);
- if (DEBUG_DATATYPES)
- {
- while(list($key, $value) =
each($var))
- {
- if (is_array($value))
- {
- $vartypes[$key]
= print_debug_subarray($value);
- }
- else
- {
- $vartypes[$key]
= gettype($value);
- }
- }
- echo "Data Types:\n";
- print_r($vartypes);
- }
- echo "\n<pre>\n";
- if (floor(phpversion()) > 3 &&
!!(DEBUG_OUTPUT & 2))
- {
- $output .= ob_get_contents();
- ob_end_clean();
- /* Need to flesh this out
still. I dont have a table to dump this in yet.*/
- /* So the SQL statement will go
here*/
- if (!!(DEBUG_OUTPUT & 1))
- {
- echo "$output<br>\n";
- }
- }
- }
- }
- }
- }
/*!
--- 33,36 ----
Index: functions.inc.php
===================================================================
RCS file: /cvsroot/phpgroupware/phpgwapi/inc/functions.inc.php,v
retrieving revision 1.121.2.13.2.16
retrieving revision 1.121.2.13.2.17
diff -C2 -d -r1.121.2.13.2.16 -r1.121.2.13.2.17
*** functions.inc.php 5 Oct 2003 07:35:18 -0000 1.121.2.13.2.16
--- functions.inc.php 19 Oct 2003 01:34:03 -0000 1.121.2.13.2.17
***************
*** 74,78 ****
magic_quotes_runtime(false);
! print_debug('sane environment','messageonly','api');
/****************************************************************************\
--- 74,79 ----
magic_quotes_runtime(false);
! // Can't use this yet - errorlog hasn't been created.
! // print_debug('sane environment','messageonly','api');
/****************************************************************************\
***************
*** 125,129 ****
}
! print_debug('domain',@$GLOBALS['phpgw_info']['user']['domain'],'api');
/****************************************************************************\
--- 126,131 ----
}
! // Can't use this yet - errorlog hasn't been created.
! // print_debug('domain',@$GLOBALS['phpgw_info']['user']['domain'],'api');
/****************************************************************************\
***************
*** 179,182 ****
--- 181,187 ----
else
{
+ /*
+ This code doesn't unserialize the variables like the code in config does.
This was causing problems with
+ my new logging stuff. So I changed it.
$GLOBALS['phpgw']->db->query("select * from phpgw_config WHERE
config_app='phpgwapi'",__LINE__,__FILE__);
while ($GLOBALS['phpgw']->db->next_record())
***************
*** 184,187 ****
--- 189,200 ----
$GLOBALS['phpgw_info']['server'][$GLOBALS['phpgw']->db->f('config_name')] =
stripslashes($GLOBALS['phpgw']->db->f('config_value'));
}
+ */
+ $c = CreateObject('phpgwapi.config','phpgwapi');
+ $c->read_repository();
+ foreach ($c->config_data as $k => $v)
+ {
+ $GLOBALS['phpgw_info']['server'][$k] = $v;
+ }
+
if(@isset($GLOBALS['phpgw_info']['server']['cache_phpgw_info']))
***************
*** 208,212 ****
* Required classes
*
\************************************************************************/
! $GLOBALS['phpgw']->log = CreateObject('phpgwapi.errorlog');
$GLOBALS['phpgw']->translation = CreateObject('phpgwapi.translation');
$GLOBALS['phpgw']->common = CreateObject('phpgwapi.common');
--- 221,226 ----
* Required classes
*
\************************************************************************/
! $GLOBALS['phpgw']->log = CreateObject('phpgwapi.log');
! include_once(PHPGW_API_INC . '/log_functions.inc.php');
$GLOBALS['phpgw']->translation = CreateObject('phpgwapi.translation');
$GLOBALS['phpgw']->common = CreateObject('phpgwapi.common');
***************
*** 219,227 ****
$GLOBALS['phpgw']->applications = CreateObject('phpgwapi.applications');
print_debug('main class loaded', 'messageonly','api');
! if (!
isset($GLOBALS['phpgw_info']['flags']['included_classes']['error']) ||
! ! $GLOBALS['phpgw_info']['flags']['included_classes']['error'])
{
!
include_once(PHPGW_INCLUDE_ROOT.'/phpgwapi/inc/class.error.inc.php');
! $GLOBALS['phpgw_info']['flags']['included_classes']['error'] =
True;
}
--- 233,243 ----
$GLOBALS['phpgw']->applications = CreateObject('phpgwapi.applications');
print_debug('main class loaded', 'messageonly','api');
! // This include was here before for the old error class. I've left it
in for the
! // new log_message class with replaced error. I'm not sure if it is
needed, though. -doug
! if (!
isset($GLOBALS['phpgw_info']['flags']['included_classes']['log_message']) ||
! !
$GLOBALS['phpgw_info']['flags']['included_classes']['log_message'])
{
!
include_once(PHPGW_INCLUDE_ROOT.'/phpgwapi/inc/class.log_message.inc.php');
!
$GLOBALS['phpgw_info']['flags']['included_classes']['log_message'] = True;
}
***************
*** 452,455 ****
}
}
!
error_reporting(E_ERROR | E_WARNING | E_PARSE);
--- 468,471 ----
}
}
!
error_reporting(E_ERROR | E_WARNING | E_PARSE);
Index: class.log.inc.php
===================================================================
RCS file: /cvsroot/phpgroupware/phpgwapi/inc/class.log.inc.php,v
retrieving revision 1.6.4.1
retrieving revision 1.6.4.2
diff -C2 -d -r1.6.4.1 -r1.6.4.2
*** class.log.inc.php 23 Sep 2003 01:01:43 -0000 1.6.4.1
--- class.log.inc.php 19 Oct 2003 01:34:02 -0000 1.6.4.2
***************
*** 1,12 ****
<?php
/**************************************************************************\
! * phpGroupWare - log
*
* http://www.phpgroupware.org
*
- * This application written by jerry westrick <address@hidden> *
* --------------------------------------------
*
! * This program is free software; you can redistribute it and/or modify
it *
! * under the terms of the GNU General Public License as published by
the *
! * Free Software Foundation; either version 2 of the License, or (at
your *
! * option) any later version.
*
\**************************************************************************/
--- 1,21 ----
<?php
/**************************************************************************\
! * phpGroupWare - log
*
* http://www.phpgroupware.org
*
* --------------------------------------------
*
! * This library is part of the phpGroupWare API
*
! * http://www.phpgroupware.org/api
*
! *
------------------------------------------------------------------------ *
! * This library is free software; you can redistribute it and/or modify
it *
! * under the terms of the GNU General Public License as published by
*
! * the Free Software Foundation; either version 2.1 of the License,
*
! * or any later version.
*
! * This library is distributed in the hope that it will be useful, but
*
! * WITHOUT ANY WARRANTY; without even the implied warranty of
*
! * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
*
! * See the GNU General Public License for more details.
*
! * You should have received a copy of the GNU General Public License
*
! * along with this library; if not, write to the Free Software
Foundation, *
! * Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
\**************************************************************************/
***************
*** 15,18 ****
--- 24,28 ----
class log
{
+
/***************************\
* Instance Variables... *
***************
*** 20,177 ****
var $errorstack = array();
var $public_functions = array(
! 'message',
'error',
'iserror',
! 'severity',
! 'commit',
! 'clearstack',
! 'astable'
);
! function
message($etext,$p0='',$p1='',$p2='',$p3='',$p4='',$p5='',$p6='',$p7='',$p8='',$p9='')
! {
! $parms = array($p0,$p1,$p2,$p3,$p4,$p5,$p6,$p7,$p8,$p9);
! CreateObject('phpgwapi.error',$etext,$parms,1);
! }
! function
error($etext,$p0='',$p1='',$p2='',$p3='',$p4='',$p5='',$p6='',$p7='',$p8='',$p9='')
{
! $parms = array($p0,$p1,$p2,$p3,$p4,$p5,$p6,$p7,$p8,$p9);
! CreateObject('phpgwapi.error',$etext,$parms,false);
}
! function iserror($ecode)
! {
! $errorstack = $this->errorstack;
! reset($errorstack);
! while(list(,$err)=each($errorstack))
! {
! if ($ecode == $err->code)
! {
return true;
- }
}
return false;
}
! function severity()
{
! $max = 'I';
! $errorstack = $this->errorstack;
! reset($errorstack);
! while(list(,$err)=each($errorstack))
{
! switch($err->severity)
{
! case 'F':
! return 'F';
! break;
! case 'E':
! $max = 'E';
! break;
! case 'W':
! if ($max == 'I')
! {
! $max = 'W';
}
- break;
}
}
! return $max;
}
! function commit()
{
! $db = $GLOBALS['phpgw']->db;
! $db->query("insert into phpgw_log (log_date, log_user,
log_app, log_severity) values "
! ."('".
$GLOBALS['phpgw']->db->to_timestamp(time())
!
."',".intval(GLOBALS['phpgw']->session->account_id)
!
.",'".$GLOBALS['phpgw_info']['flags']['currentapp']."'"
! .",'".$this->severity()."'"
! .")"
! ,__LINE__,__FILE__);
! $errorstack = $this->errorstack;
! for ($i = 0; $i < count($errorstack); $i++)
! {
! $err = $errorstack[$i];
! $db->query("insert into phpgw_log_msg "
! . "(log_msg_seq_no, log_msg_date, "
! . "log_msg_severity, log_msg_code,
log_msg_msg, log_msg_parms) values "
! . "(" . $i
! . ", '" .
$GLOBALS['phpgw']->db->to_timestamp($err->timestamp)
! . "', '". $err->severity . "'"
! . ", '". $err->code . "'"
! . ", '". $err->msg . "'"
! . ", '".
addslashes(implode('|',$err->parms)). "'"
! . ")",__LINE__,__FILE__);
}
- unset ($errorstack);
- unset ($this->errorstack);
- $this->errorstack = array();
}
! function clearstack()
{
! $new = array();
! reset($this->errorstack);
! for ($i = 0; $i < count($this->errorstack); $i++)
{
! $err = $this->errorstack[$i];
! if ($err->ismsg)
! {
! $new[] = $err;
! }
}
- unset ($this->errorstack);
- $this->errorstack = $new;
}
! function astable()
{
! $html = "<center>\n";
! $html .= "<table width=\"98%\">\n";
! $html .= "\t<tr bgcolor=\"D3DCFF\">\n";
! $html .= "\t\t<td width=\"2%\">No</td>\n";
! $html .= "\t\t<td width=\"16%\">Date</td>\n";
! $html .= "\t\t<td width=\"15%\">App</td>\n";
! $html .= "\t\t<td align=\"center\",
width=\"2%\">S</td>\n";
! $html .= "\t\t<td width=\"10%\">Error Code</td>\n";
! $html .= "\t\t<td >Msg</td>\n";
! $html .= "\t</tr>\n";
!
! $errorstack = $this->errorstack;
! for ($i = 0; $i < count($errorstack); $i++)
! {
! $err = $errorstack[$i];
! switch ($err->severity)
! {
! case 'I':
! $color = 'C0FFC0';
! break;
! case 'W':
! $color = 'FFFFC0';
! break;
! case 'E':
! $color = 'FFC0C0';
! break;
! case 'F':
! $color = 'FF0909';
! break;
! }
! $html .= "\t<tr bgcolor=".'"'.$color.'"'.">\n";
! $html .= "\t\t<td align=center>".$i."</td>\n";
! $html .=
"\t\t<td>".$GLOBALS['phpgw']->common->show_date($err->timestamp)."</td>\n";
! $html .=
"\t\t<td>".$GLOBALS['phpgw_info']['flags']['currentapp']."  </td>\n";
! $html .= "\t\t<td
align=center>".$err->severity."</td>\n";
! $html .= "\t\t<td>".$err->code."</td>\n";
! $html .= "\t\t<td>".$err->langmsg()."</td>\n";
! $html .= "\t</tr>\n";
! }
! $html .= "</table>\n";
! $html .= "</center>\n";
! return $html;
}
}
--- 30,258 ----
var $errorstack = array();
var $public_functions = array(
! 'debug',
! 'info',
! 'warn',
'error',
+ 'fatal',
'iserror',
! // the following 3 are for backward compatibility
! 'write',
! 'message',
! 'commit'
);
! var $log_level_table = array(
! 'F' => 1,
! 'E' => 2,
! 'W' => 3,
! 'I' => 4,
! 'D' => 5
! );
! // these are used by the admin appliation when showing the log
file.
!
! var $log_level_names = array(
! 'F' => 'fatal',
! 'E' => 'error',
! 'W' => 'warn',
! 'I' => 'info',
! 'D' => 'debug'
! );
!
! function get_level_name($level)
{
! return $this->log_level_names[$level];
}
+
+ function is_level($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']) )
! && ( 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']) )
+ && (
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;
+ }
+
return false;
}
+
+
+ function log_if_level($level, $parms)
+ {
+ if ( $this->is_level($level) ) {
+
+
+ $parms['severity']=$level;
+ $err =
CreateObject('phpgwapi.log_message',$parms);
+ $this->write_error_to_db($err);
+ $this->handle_fatal_error($err);
// this is here instead of in fatal() because I still support
+
// the old methods.
+ return true;
+ }
+ else {
+ return false;
+ }
+ }
! function log() {
! }
!
! function make_parms($arg_array)
{
! if ( count($arg_array) == 0 )
{
! $parms['text'] = 'No message passed to logging
function!';
! }
! else
! {
! // if they've passed in an array of parms,
! // just return it.
! if ( is_array($arg_array[0]) )
{
! return $arg_array[0];
! }
! else
! {
! // otherwise the first arg is the
message text and the rest are
! // parameters to that message
! list($k, $v) = each($arg_array);
! $parms['text'] = $v;
! while ( list($k, $v) = each($arg_array)
)
! {
! $parms['p'.$k] = $v;
}
}
}
! return $parms;
}
! function debug()
{
! $arg_array = func_get_args();
! return $this->log_if_level('D',
$this->make_parms($arg_array));
! }
! function info()
! {
! $arg_array = func_get_args();
! return $this->log_if_level('I',
$this->make_parms($arg_array));
! }
!
! function warn()
! {
! $arg_array = func_get_args();
! return $this->log_if_level('W',
$this->make_parms($arg_array));
! }
!
! function error()
! {
! $arg_array = func_get_args();
! return $this->log_if_level('E',
$this->make_parms($arg_array));
! }
!
! function fatal()
! {
! $arg_array = func_get_args();
! return $this->log_if_level('F',
$this->make_parms($arg_array));
! }
!
! function write_error_to_db($err) {
! $db = $GLOBALS['phpgw']->db;
! $db->query("insert into phpgw_log (log_date, log_app,
log_account_id, log_account_lid, log_severity, log_file, log_line, log_msg)
values "
! . "('" .
$GLOBALS['phpgw']->db->to_timestamp(time()) . "'"
! . ",'" .
$db->db_addslashes($GLOBALS['phpgw_info']['flags']['currentapp']) . "'"
! . "," . (
$GLOBALS['phpgw']->session->account_id ? $GLOBALS['phpgw']->session->account_id
: -1)
! . ",'" .
$db->db_addslashes($GLOBALS['phpgw']->session->account_lid) . "'"
! . ",'" . $err->severity . "'"
! . ",'" . $db->db_addslashes($err->fname) . "'"
! . "," . intval($err->line)
! . ",'" . $db->db_addslashes($err->msg) . "'"
! . ")"
! ,__LINE__,__FILE__
! );
! if ( $db->Errno ) {
! trigger_error("Failed to log error to database.
DB errno " . $db->Errno . ": message " . $db->Error, E_USER_NOTICE);
}
}
! // I pulled this from the old code, where it's used to display
a fatal error and determinate processing..
! // Do I still want to do this? If so, do I want to translate
the error message like it used to?
! //
! function handle_fatal_error($err)
{
! if ($err->severity == 'F')
{
! // This is it... Don't return
! // do rollback!
! // Hmmm this only works if UI!!!!
! // What Do we do if it's a SOAP/XML?
! echo "<Center>";
! echo "<h1>Fatal Error</h1>";
! echo "<center>\n";
! echo "<table width=\"98%\">\n";
! echo "\t<tr bgcolor=\"D3DCFF\">\n";
! echo "\t\t<td width=\"16%\">Date</td>\n";
! echo "\t\t<td width=\"15%\">App</td>\n";
! echo "\t\t<td align=\"center\",
width=\"2%\">S</td>\n";
! echo "\t\t<td >Msg</td>\n";
! echo "\t\t<td >File</td>\n";
! echo "\t\t<td >Line</td>\n";
! echo "\t</tr>\n";
!
! echo "\t<tr bgcolor=".'"'.'FF0909'.'"'.">\n";
! echo
"\t\t<td>".$GLOBALS['phpgw']->common->show_date($err->timestamp)."</td>\n";
! echo "\t\t<td>".$err->app."  </td>\n";
! echo "\t\t<td
align=center>".$err->severity."</td>\n";
! echo "\t\t<td>".$err->msg."</td>\n";
! echo "\t\t<td>".$err->fname."</td>\n";
! echo "\t\t<td>".$err->line."</td>\n";
! echo "\t</tr>\n";
!
! echo "</table>\n";
! echo "</center>\n";
!
! echo "</center>";
!
! $GLOBALS['phpgw']->common->phpgw_exit(True);
}
}
!
! // write() left in for backward compatibility
! function write($parms)
{
! $err = CreateObject('phpgwapi.log_message',$parms);
! $this->write_error_to_db($err);
! return true;
! }
! // message() left in for backward compatibility
! function message($parms)
! {
! $err = CreateObject('phpgwapi.log_message',$parms);
! $this->write_error_to_db($err);
! return true;
! }
! // commit() left in for backward compatibility
! function commit()
! {
! return true;
! }
! // clearstack() left in for backward compatibility
! function clearstack()
! {
! return true;
}
+
+
}
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [Phpgroupware-cvs] phpgwapi/inc class.log.inc.php, 1.6.4.1, 1.6.4.2 common_functions.inc.php, 1.16.2.5, 1.16.2.6 functions.inc.php, 1.121.2.13.2.16, 1.121.2.13.2.17,
Chris Weiss <address@hidden> <=
- Prev by Date:
[Phpgroupware-cvs] setup/inc functions.inc.php,1.47.2.2,1.47.2.3
- Next by Date:
[Phpgroupware-cvs] property/inc class.soentity.inc.php, 1.2, 1.3 class.soadmin_entity.inc.php, 1.3, 1.4 class.uiadmin_entity.inc.php, 1.3, 1.4 class.boadmin_entity.inc.php, 1.2, 1.3
- Previous by thread:
[Phpgroupware-cvs] setup/inc functions.inc.php,1.47.2.2,1.47.2.3
- Next by thread:
[Phpgroupware-cvs] property/inc class.soentity.inc.php, 1.2, 1.3 class.soadmin_entity.inc.php, 1.3, 1.4 class.uiadmin_entity.inc.php, 1.3, 1.4 class.boadmin_entity.inc.php, 1.2, 1.3
- Index(es):