<?php
/**
* The abstract class of logger.
* User can define the log level for the different output details.
*
* @package com.freeorm
* @author Yide Zou
* @link http://www.freeorm.com
* @copyright Copyright (c) 2010 Yide Zou <hide@address.com>.
* All Rights Reserved.
* @license This software is released under the terms of the GNU Lesser General Public License
* A copy of which is available from http://www.gnu.org/copyleft/lesser.html
*/
abstract class Logger
{
protected $level = LOG_LVL_NONE;
public function __construct($level=LOG_LVL_NONE)
{
$this->level = $level;
}
/**
* get current level
*/
public function getLevel()
{
return $this->level;
}
/**
* set level
*/
public function setLevel($level)
{
$this->level = $level;
}
/**
* Log the normal message
* It will be output if the log level == LOG_LVL_ALL
*/
public function log($text)
{
if ($this->level == LOG_LVL_ALL)
$this->output($text, 'SYSOUT');
}
/**
* Log the debug message
* It will be output if the log level >= LOG_LVL_DEBUG
*/
public function debug($text)
{
if ($this->level >= LOG_LVL_DEBUG)
$this->output($text, 'DEBUG');
}
/**
* Log the error message
* It will be output if the log level >= LOG_LVL_ERROR
*/
public function err($text)
{
if ($this->level >= LOG_LVL_ERROR)
$this->output($text, 'ERROR');
}
/**
* The real output function,
* it can direct output to screen or for example save into a file
* @param $text
* @param $type the type of message, it can for example 'log' or 'err'
*/
protected abstract function output($text, $type='ERROR');
}