<?php
require_once(dirname(__FILE__).'/../../../param/parameters.php');
/**
* log class (SINGLETON see http://en.wikipedia.org/wiki/Singleton_pattern)
*
* Creates daily logs in log folder.
* Sample:
* Log::fGetInstance()->fLog(Log::$TYPE['info'] ,__CLASS__, 'info message');
* Log::fGetInstance()->fLog(Log::$TYPE['warning'] ,__CLASS__, 'warning message');
* Log::fGetInstance()->fLog(Log::$TYPE['error'] ,__CLASS__, 'error message');
*
* @author Olivier G <hide@address.com>
* @version 1.0
* @license http://opensource.org/licenses/gpl-license.php GNU Public License
* @link http://gemibloo.fr
*/
class Log{
public static $TYPE = array('info'=>'info', 'warning'=>'warning', 'error'=>'error');
private static $_instance;
private $_handle;
/**
* __construct
*/
private function __construct() {
$filename = dirname(__FILE__).'/../../../log/Gemibloo_'.date('Ymd').'.log';
$this->_handle = fopen($filename, 'a');
}
/**
* __destruct
*/
function __destruct() {
if(FALSE !== $this->_handle){
fclose($this->_handle);
$this->_handle = NULL;
}
}
/**
* __clone
*/
private function __clone() {}
/**
* fGetInstance method
*/
public static function fGetInstance()
{
if (!isset(self::$_instance)) {
$c = __CLASS__;
self::$_instance = new $c;
}
return self::$_instance;
}//getInstance
/**
* fLog method
*/
public function fLog($aType, $aSource, $aContent){
if( (FALSE !== $this->_handle) && ( TRUE === array_key_exists($aType,self::$TYPE) ) )
fwrite ($this->_handle, date('Ymj-H:m:s')."\t".strtoupper($aType)."\t".$aSource."\t".$aContent."\n");
}
}//Plugin
?>