<?php

/**
 *
 * @author Peter Csubak (chuby)
 * @copyright Peter Csubak (chuby)
 */
class Logger {
	
	private static $loggers = null;
	
	const INFO = "INFO";
	const ERROR = "ERROR";
	const WARNING = "WARNING";
	const DEBUG = "DEBUG";
	
	private function __construct(){
		
	}
	
	public static function newLogger($loggerName, $handler){
		if (self::$loggers === null){
			self::$loggers = array();
		}
		if ($handler instanceof LogHandler){
			if (self::$loggers[$loggerName] == null){
				self::$loggers[$loggerName] = $handler;
			}else{
				throw new LoggerException("A megadott névvel már van logger regisztrálva.");
			}
		}else{
			throw new LoggerException("A megadott log kezelő nem megfelelő típusú.");
		}
	}
	
	public static function log($loggerName, $type, $text){
		if (is_array(self::$loggers) && (self::$loggers[$loggerName] != null) && (self::$loggers[$loggerName] instanceof LogHandler)){
			self::$loggers[$loggerName]->addEntry($loggerName, date("Y.m.d H:i:s"), $type, $text);
		}else{
			throw new LoggerException("Nem található a <<loggerName>> nevű log kezelő.", array("loggerName" => $loggerName));
		}
	}

}
?>