Newer
Older
Digital_Repository / Repositories / statistics / includes / inc.class.logger.es.php
<?php
/**
 *	Logger - Collects log lines and writes them to file at end of request.
 *
 *     $logger = new Logger($file_log);
 *	   $logger->setLog("Some message or vars",__LINE__,__FILE__);
 *     $logger->writeLog();
 *            
 */

class Logger {
	var $_log = array();
	var $_file;

	function Logger($file)
	{
		$this->_file = $file;
	}
	function setLog($input,$line,$file)
	{
		$now = date("D M d H:i:s Y"); 
		$newline = "[$now] ";
		if (!empty($file)) { $newline .= "[$file]"; };
		if (!empty($line)) { $newline .= "[Line: $line]"; };
		if (!empty($input)) { $newline .= " $input"; };
		$this->_log[] = $newline;
	}
	function writeLog()
	{
		$out = implode("\n",$this->_log);
		$handle = fopen($this->_file, "a");
		fwrite($handle, $out);
		fclose($handle);
	}
}

?>