|
|
|
|
File: [Development] / old-advokit-installer / Logger.class.php
(download)
/
(as text)
Revision: 1.1.1.1 (vendor branch), Sat Jun 5 04:22:14 2004 UTC (6 years, 3 months ago) by travislow Branch: advokit-installer, MAIN CVS Tags: start, HEAD Changes since 1.1: +0 -0 lines Initial import of AdvoKit into voter2voter cvs ... I hope you committed your changes. :-) |
<?
#======================================================================
# Logging stuff.
#
# (c) 2003, Dawnstar - http://dawnstar.com - info@dawnstar.com
#======================================================================
class Logger
{
var $dateformat;
var $log_file;
var $log_level;
var $log_method;
var $user = NULL;
#.................................................. Logger
#
# Constructor. Pass in the config.
#
function Logger( &$config )
{
$this->dateformat = "Y-m-d H:i:s";
$this->log_level = $config->get( "log_level" );
$this->log_method = $config->get( "log_method" );
# Check for log rotation interval. Nothing
# is ever actually rotated, but
$logfile = $config->get( "log_file" );
$rotation = $config->get( "log_rotation" );
$fname = preg_replace( "/(.*)\.[^.]*/", "$1", $logfile );
$ext = preg_replace( "/.*\.([^\.]*)/", "$1", $logfile );
if( "daily" == $rotation )
{
$this->log_file = $ext ? $fname."-".date( "Y-m-d" ).".".$ext : $fname."-".date( "Y-m-d" ).".log";
}
elseif( "monthly" == $rotation )
{
$this->log_file = $ext ? $fname."-".date( "Y-m" ).".".$ext : $fname."-".date( "Y-m" ).".log";
}
else
{
$this->log_file = $ext ? "$fname.$ext" : "$fname.log";
}
$this->debug( __FILE__, "Logger created." );
}
#.................................................. setUser
#
# Pass in the user object.
#
function setUser( &$user )
{
$this->user = $user;
}
#.................................................. error
#
# Log an Error message
#
function error( $where, $message )
{
if( $this->log_level > 0 )
{
$this->doLog( " (ERROR)", $where, $message );
}
}
#.................................................. warning
#
# Log a Warning message
#
function warning( $where, $message )
{
if( $this->log_level > 1 )
{
$this->doLog( "(WARNING)", $where, $message );
}
}
#..................................................info
#
# Log an Info message
#
function info( $where, $message )
{
if( $this->log_level > 2 )
{
$this->doLog( " (INFO)", $where, $message );
}
}
#.................................................. debug
#
# Log a Debug message
#
function debug( $where, $message )
{
if( $this->log_level > 3 )
{
$this->doLog( " (DEBUG)", $where, $message );
}
}
#.................................................. doLog
#
# Do the actual logging
#
function doLog( $level, $where, $message )
{
if( "file" == $this->log_method )
{
$s = date( $this->dateformat, time() )." $level ";
if( isset( $this->user ) )
{
$s .= "user '".$this->user->getUsername()."' ";
}
if( isset( $_SERVER["REMOTE_ADDR"] ) )
{
$s .= $_SERVER["REMOTE_ADDR"];
if( isset( $_SERVER["REMOTE_PORT"] ) )
{
$s .= ":".$_SERVER["REMOTE_PORT"];
}
}
error_log( "$s [".basename( $where )."] - $message\n", 3, $this->log_file );
}
else
{
error_log( date( "M d H:i:s" )." TURBAN PANIC! Logging not correctly configured!!! You must set 'log_method' in the ini file!", 0 );
}
}
}
?>
| cvsadmin@voter2voter.org | CVS Snapshots (updated daily) |