phpgroupware-cvs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Phpgroupware-cvs] phpgwapi/inc class.log_message.inc.php, NONE, 1.1.2.1


From: Chris Weiss <address@hidden>
Subject: [Phpgroupware-cvs] phpgwapi/inc class.log_message.inc.php, NONE, 1.1.2.1 log_functions.inc.php, NONE, 1.1.2.1
Date: Mon, 20 Oct 2003 13:04:36 +0000

Update of /cvsroot/phpgroupware/phpgwapi/inc
In directory subversions:/tmp/cvs-serv27917/inc

Added Files:
      Tag: Version-0_9_16-branch
        class.log_message.inc.php log_functions.inc.php 
Log Message:
adding files for logging classes, patch #2100


--- NEW FILE: class.log_message.inc.php ---
<?php
        
/**************************************************************************\
        * phpGroupWare - log_message                                            
   *
        * 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         
   *
        
\**************************************************************************/

        /* $Id: class.log_message.inc.php,v 1.1.2.1 2003/10/20 13:04:34 cw Exp 
$ */

        class log_message
        {
                /***************************\
                *       Instance Variables...   *
                \***************************/
                var $severity = 'E';
                var $msg  = 'Unknown error';
                var $timestamp;
                var $fname = '';
                var $line = 0;
                var $app = '';

                var $public_functions = array();

                function log_message($parms)
                {
                        if ($parms == '')
                        {
                                return;
                        }
                        $etext = $parms['text'];
                        $parray = Array();
                        for($counter=1;$counter<=10;$counter++)
                        {
                                // This used to support p_1, etc, but it was 
not used anywhere.
                                // More efficient to standardize on one way.
                                $str = 'p'.$counter;
                                if(isset($parms[$str]) && !empty($parms[$str]))
                                {
                                        $parray[$counter] = $parms[$str];
                                }
                        }

                        // This code is left in for backward compatibility with 
the 
                        // old log code.  Consider it deprecated.
                        if (eregi('([DIWEF])-([[:alnum:]]*)\, 
(.*)',$etext,$match))
                        {
                                $this->severity = strtoupper($match[1]);
                                $this->msg      = trim($match[3]);
                        }
                        else
                        {
                                $this->msg = trim($etext);
                        }
                        
                        // If I was going to use translations for log messages, 
I'd probably put it here.
                        
                        // 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 ( $parms['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", 
">=") )
                                {
                                        $val = print_r($val, true);
                                }
                                $this->msg = preg_replace( "/%$key/", 
"'".$val."'", $this->msg );
                        }
                        @reset($parray);

                        $this->timestamp = time();
                        
                        if ( isset($parms['line']) ) 
                        {
                                $this->line  = $parms['line'];
                        }
                        if ( isset($parms['file']) ) 
                        {
                                // DWD - May want to change the "remove the 
server root" thing to a configuration option
                                $this->fname = substr($parms['file'], 
strlen(PHPGW_SERVER_ROOT) + 1);
                        }                       
                        if  ( isset( 
$GLOBALS['phpgw_info']['flags']['currentapp']) ) 
                        {
                                $this->app = 
$GLOBALS['phpgw_info']['flags']['currentapp'];
                        }
                }
        }

--- NEW FILE: log_functions.inc.php ---
<?php
         
/**************************************************************************\
         * phpGroupWare API - Logging helper functions                          
    *
         * This file written by Doug Dicks <address@hidden>                  *
         * This is just an alternative API to the logging methods in            
    *
         * class.errorlog2.inc.php.  They allow you to call the logging methods 
    *
         * without having to always use a  $GLOBALS['phpgw']->log-> with all of 
    *
         * your logging statements.  For example, instead of                    
    *
         * $GLOBALS['phpgw']->log->debug(); you can use log_debug();            
    *
         *                                                                      
    *
         * The goal is to make it easier to add logging to your code.           
    *
         * 
-------------------------------------------------------------------------*
         * 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        
    *
         
\**************************************************************************/

        /* $Id: log_functions.inc.php,v 1.1.2.1 2003/10/20 13:04:34 cw Exp $ */

        /*!
         @function log_debug
         @abstract Log a message at DEBUG level
         @author doug
         @discussion Log a message at DEBUG level
         @syntax 
         @example 
                function somefunc()
                {
                        /// some code...

                        log_debug(array('text' => 'Did something, now X = %1',
                                                    'p1' => $x,
                                                        'file' => __FILE__,
                                                        'line' => __LINE__));

                        // some more code...
                        // This syntax also works:
                        log_debug('Did something else, now X = %1', $x);
                        // or even if there are no parameters:
                        log_debug('Did something else');
                }
        */
        function log_debug()
        {
                if ( isset($GLOBALS['phpgw']->log) )
                {
                        $arg_array = func_get_args();
                        $GLOBALS['phpgw']->log->log_if_level('D', 
$GLOBALS['phpgw']->log->make_parms($arg_array));
                }
        }
        
        function log_info()
        {
                if ( isset($GLOBALS['phpgw']->log) )
                {
                        $arg_array = func_get_args();
                        $GLOBALS['phpgw']->log->log_if_level('I', 
$GLOBALS['phpgw']->log->make_parms($arg_array));
                }
        }

        function log_warn()
        {
                if ( isset($GLOBALS['phpgw']->log) )
                {
                $arg_array = func_get_args();
                $GLOBALS['phpgw']->log->log_if_level('W', 
$GLOBALS['phpgw']->log->make_parms($arg_array));
                }
        }

        function log_error()
        {
                if ( isset($GLOBALS['phpgw']->log) )
                {
                        $arg_array = func_get_args();
                        $GLOBALS['phpgw']->log->log_if_level('E', 
$GLOBALS['phpgw']->log->make_parms($arg_array));
                }
        }

        function log_fatal()
        {
                if ( isset($GLOBALS['phpgw']->log) )
                {
                        $arg_array = func_get_args();
                        $GLOBALS['phpgw']->log->log_if_level('F', 
$GLOBALS['phpgw']->log->make_parms($arg_array));
                }
        }
        
        
        /* For backward compatibility with some of the existing debugging 
statements */
        function print_debug($message,$var = 'messageonly',$part = 'app', 
$level = 3)
        {
                if ( $var == 'messageonly' )
                {
                        log_debug($message);
                }
                else
                {
                        log_debug($message, $var);
                }
        }
        
?>





reply via email to

[Prev in Thread] Current Thread [Next in Thread]