Logger.class.php

gehe zur Dokumentation dieser Datei
00001 <?php
00002 // ---------------------------------------------------------------------------
00003 // $Id$
00004 // ---------------------------------------------------------------------------
00005 // OpenRat Content Management System
00006 // Copyright (C) 2002 Jan Dankert, jandankert@jandankert.de
00007 //
00008 // This program is free software; you can redistribute it and/or
00009 // modify it under the terms of the GNU General Public License
00010 // as published by the Free Software Foundation; either version 2
00011 // of the License, or (at your option) any later version.
00012 //
00013 // This program is distributed in the hope that it will be useful,
00014 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00015 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00016 // GNU General Public License for more details.
00017 //
00018 // You should have received a copy of the GNU General Public License
00019 // along with this program; if not, write to the Free Software
00020 // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
00021 // ---------------------------------------------------------------------------
00022 // $Log$
00023 // Revision 1.5  2007-11-08 21:32:06  dankert
00024 // Aktion-Name mitloggen.
00025 //
00026 // Revision 1.4  2004/11/10 22:50:37  dankert
00027 // Benutzen von Konstanten zur Performancesteigerung
00028 //
00029 // Revision 1.3  2004/10/04 19:57:17  dankert
00030 // Bugfix und trace()
00031 //
00032 // Revision 1.2  2004/05/02 15:04:16  dankert
00033 // Einf?gen package-name (@package)
00034 //
00035 // Revision 1.1  2004/04/24 17:03:28  dankert
00036 // Initiale Version
00037 //
00038 // ---------------------------------------------------------------------------
00039 
00040 
00041 switch( strtolower($conf['log']['level']) )
00042 {
00043      case 'trace':
00044           define('OR_LOG_LEVEL_TRACE',true );
00045 
00046      case 'debug':
00047           define('OR_LOG_LEVEL_DEBUG',true );
00048 
00049      case 'info':
00050           define('OR_LOG_LEVEL_INFO' ,true );
00051 
00052      case 'warn':
00053           define('OR_LOG_LEVEL_WARN' ,true );
00054 
00055      case 'error':
00056           define('OR_LOG_LEVEL_ERROR',true );
00057 }
00058 
00059 if   ( !defined('OR_LOG_LEVEL_TRACE') ) define('OR_LOG_LEVEL_TRACE',false );
00060 if   ( !defined('OR_LOG_LEVEL_DEBUG') ) define('OR_LOG_LEVEL_DEBUG',false );
00061 if   ( !defined('OR_LOG_LEVEL_INFO' ) ) define('OR_LOG_LEVEL_INFO' ,false );
00062 if   ( !defined('OR_LOG_LEVEL_WARN' ) ) define('OR_LOG_LEVEL_WARN' ,false );
00063 if   ( !defined('OR_LOG_LEVEL_ERROR') ) define('OR_LOG_LEVEL_ERROR',false );
00064 
00065 
00066 
00074 class Logger
00075 {
00081      function trace( $message )
00082      {
00083           if   ( OR_LOG_LEVEL_TRACE )
00084                Logger::doLog( 'trace',$message );
00085      }
00086 
00087 
00093      function debug( $message )
00094      {
00095           if   ( OR_LOG_LEVEL_DEBUG )
00096                Logger::doLog( 'debug',$message );
00097      }
00098 
00099 
00105      function info( $message )
00106      {
00107           if   ( OR_LOG_LEVEL_INFO )
00108                Logger::doLog( 'info',$message );
00109      }
00110 
00111 
00117      function warn( $message )
00118      {
00119           if   ( OR_LOG_LEVEL_WARN )
00120                Logger::doLog( 'warn',$message );
00121      }
00122 
00123 
00129      function error( $message )
00130      {
00131           if   ( OR_LOG_LEVEL_ERROR )
00132                Logger::doLog( 'error',$message );
00133      }
00134 
00135 
00144      function doLog( $facility,$message )
00145      {
00146           global $conf;
00147           global $SESS;
00148           
00149           $filename = $conf['log']['file'];
00150 
00151           if   ( $filename == '' )
00152                return;
00153 
00154           if   ( ! is_writable($filename) )
00155                Http::serverError( "logfile $filename is not writable by the server" );
00156 
00157           $thisLevel = strtoupper($facility);
00158           
00159           $user = Session::getUser();
00160           if   ( is_object($user) )
00161                $username = $user->name;
00162           else
00163                $username = '-';
00164      
00165           $text = $conf['log']['format']; // Format der Logdatei lesen
00166 
00167           // Ersetzen von Variablen
00168           if   ( $conf['log']['dns_lookup'] )
00169                $text = str_replace( '%host',gethostbyaddr(getenv('REMOTE_ADDR')),$text );
00170           else
00171                $text = str_replace( '%host',getenv('REMOTE_ADDR'),$text );
00172           
00173           $action = Session::get('action');
00174           if   ( empty($action) )
00175                $action = '-';
00176 
00177           $action = Session::get('action');
00178           if   ( empty($action) )
00179                $action = '-';
00180                
00181           $text = str_replace( '%user'  ,str_pad($username ,8),$text );
00182           $text = str_replace( '%level' ,str_pad($thisLevel,5),$text );
00183           $text = str_replace( '%agent' ,getenv('HTTP_USER_AGENT'),$text );
00184           $text = str_replace( '%action',str_pad($action,12),$text );
00185           $text = str_replace( '%text'  ,$message,$text );
00186           $text = str_replace( '%time'  ,date($conf['log']['date_format']),$text );
00187 
00188           // Schreiben in Logdatei
00189           error_log( $text."\n",3,$filename );
00190      }
00191 }
00192 
00193 ?>

Erzeugt am Thu May 14 00:55:49 2009 für OpenRat von  doxygen 1.5.8