00001 <?php 00002 /*************************************************************************** 00003 * Copyright (C) 2007 by Ivan Y. Khvostishkov * 00004 * * 00005 * This program is free software; you can redistribute it and/or modify * 00006 * it under the terms of the GNU Lesser General Public License as * 00007 * published by the Free Software Foundation; either version 3 of the * 00008 * License, or (at your option) any later version. * 00009 * * 00010 ***************************************************************************/ 00011 00015 abstract class BaseLogger 00016 { 00017 private $level = null; 00018 00022 abstract protected function publish(LogRecord $record); 00023 00027 public function setLevel(LogLevel $level) 00028 { 00029 $this->level = $level; 00030 00031 return $this; 00032 } 00033 00037 public function getLevel() 00038 { 00039 return $this->level; 00040 } 00041 00045 final public function log(LogLevel $level, $message) 00046 { 00047 $this->logRecord( 00048 LogRecord::create()-> 00049 setLevel($level)-> 00050 setMessage($message) 00051 ); 00052 00053 return $this; 00054 } 00055 00059 final public function logRecord(LogRecord $record) 00060 { 00061 $levelMatches = 00062 $this->level === null 00063 || $record->getLevel()->getId() <= $this->level->getId(); 00064 00065 if ($levelMatches && $this->isLoggable($record)) 00066 $this->publish($record); 00067 00068 return $this; 00069 } 00070 00074 protected function isLoggable(LogRecord $record) 00075 { 00076 return true; 00077 } 00078 00082 final public function severe($message) 00083 { 00084 $this->log(LogLevel::severe(), $message); 00085 00086 return $this; 00087 } 00088 00092 final public function warning($message) 00093 { 00094 $this->log(LogLevel::warning(), $message); 00095 00096 return $this; 00097 } 00098 00102 final public function info($message) 00103 { 00104 $this->log(LogLevel::info(), $message); 00105 00106 return $this; 00107 } 00108 00112 final public function config($message) 00113 { 00114 $this->log(LogLevel::config(), $message); 00115 00116 return $this; 00117 } 00118 00122 final public function fine($message) 00123 { 00124 $this->log(LogLevel::fine(), $message); 00125 00126 return $this; 00127 } 00128 00132 final public function finer($message) 00133 { 00134 $this->log(LogLevel::finer(), $message); 00135 00136 return $this; 00137 } 00138 00142 final public function finest($message) 00143 { 00144 $this->log(LogLevel::finest(), $message); 00145 00146 return $this; 00147 } 00148 } 00149 ?>