Location: PHPKode > projects > Tv.2 CMS > tv2engine/ctlErrors.class.php
<?php
/** 
 * Error handler (currently logs errors into files).
 * 
 * @package tv2-engine
 * @author Emilis Dambauskas (hide@address.com)
 * @copyright 2002–2003 Emilis Dambauskas under {@link http://opensource.org/licenses/artistic-license.php Artistic license}
 * @version $Id: ctlErrors.class.php,v 1.1 2003/07/05 09:46:53 lunaticlt Exp $
 * @class ctlErrors 
 */
class ctlErrors
{
	/**
	 * error log file of the day
	 * @attribute private string $file_name
	 */
	var $file_name;
	
	/**
	 * Counts number of errors
	 * @attribute private int $err_count
	 */
	var $err_count;
	
	/**
	 * Directory where error logs are kept
	 * @attribute private string $dir
	 */
	var $dir;
	
	/**
	 * File handle for first error file
	 * @attribute private mixed $fp1
	 */
	var $fp;
	/**
	 * File handle for second error file
	 * @attribute private mixed $fp2
	 */
	var $fp2;
	
	
	/**
	 * Constructor. Sets $this->dir and $this->file_name
	 *
	 * @constructor ctlErrors   
	 * @use $config (This is optional - if not found uses ./errors/ for $this->dir)  
	 */ 
	function ctlErrors()
	{
		$this->err_count = 0;
		$this->fp = NULL;
		$this->fp2 = NULL;
		$this->file_name = date('Ymd').'.log';
		
		if (isset($GLOBALS['config']['errors']))
				$this->dir = $GLOBALS['config']['errors']['dir'];
		else
				$this->dir = 'errors/';
	}
	
//----------------- PUBLIC METHODS --------------------------------------------
	
	/**
	 * Adds error message
	 *
	 * @method public add
	 * @return boolean always FALSE 
	 * @param string $message error message  
	 */  
	function add($message)
	{
		$message = date('Y-m-d H:i:s').'|'.$_SERVER['REMOTE_ADDR'].'|'.$message."\n";
		
		if (!$this->err_count)
		{
			$this->fp = fopen($this->dir.$this->file_name, 'ab');
			$this->fp2 = fopen($this->dir.'_last.log', 'wb');
		}
		
		fwrite($this->fp, $message, strlen($message));
		fwrite($this->fp2, $message, strlen($message));
		
		$this->err_count++;
		
		return FALSE;
	} // end of function add
	
}
Return current item: Tv.2 CMS