Logger.class.php
gehe zur Dokumentation dieser Datei00001 <?php
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
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'];
00166
00167
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
00189 error_log( $text."\n",3,$filename );
00190 }
00191 }
00192
00193 ?>