| [ Index ] |
PHP Cross Reference of Limb3 |
[Summary view] [Print] [Text view]
1 <?php 2 /* 3 * $Id: license.txt 13981 2005-03-16 08:09:28Z eespino $ 4 * 5 * Copyright(c) 2004-2005, SpikeSource Inc. All Rights Reserved. 6 * Licensed under the Open Source License version 2.1 7 * (See http://www.spikesource.com/license.html) 8 */ 9 ?> 10 <?php 11 12 class Logger { 13 14 private $level; 15 private $logLevels = array( 16 "LOG_CRITICAL", 17 "LOG_ERROR", 18 "LOG_WARNING", 19 "LOG_NOTICE", 20 "LOG_INFO", 21 "LOG_DEBUG" 22 ); 23 24 public function setLevel($level) { 25 if(!is_numeric($level)) { 26 for($i = 0; $i < count($this->logLevels); $i++) { 27 if(strcasecmp($this->logLevels[$i], $level) === 0) { 28 $level = $i; 29 break; 30 } 31 } 32 } 33 $this->level = $level; 34 } 35 36 public function critical($str, $file="", $line="") { 37 if($this->level >= 0) { 38 error_log("[CRITICAL] [" . $file . ":" . $line . "] " . $str); 39 } 40 } 41 42 public function error($str, $file="", $line="") { 43 if($this->level >= 1) { 44 error_log("[ERROR] [" . $file . ":" . $line . "] " . $str); 45 } 46 } 47 48 public function warn($str, $file="", $line="") { 49 if($this->level >= 2) { 50 error_log("[WARNING] [" . $file . ":" . $line . "] " . $str); 51 } 52 } 53 54 public function notice($str, $file="", $line="") { 55 if($this->level >= 3) { 56 error_log("[NOTICE] [" . $file . ":" . $line . "] " . $str); 57 } 58 } 59 60 public function info($str, $file="", $line="") { 61 if($this->level >= 4) { 62 error_log("[INFO] [" . $file . ":" . $line . "] " . $str); 63 } 64 } 65 66 public function debug($str, $file="", $line="") { 67 if($this->level >= 5) { 68 error_log("[DEBUG] [" . $file . ":" . $line . "] " . $str); 69 } 70 } 71 72 public function getLevelName($level) { 73 return $this->logLevels[$level]; 74 } 75 } 76 77 // testing 78 if(isset($_SERVER["argv"][1]) && $_SERVER["argv"][1] == "__main__") { 79 $logger = new Logger(); 80 for($i = 0; $i < 6; $i++) { 81 $logger->setLevel($i); 82 error_log("############## Level now: " . $i); 83 $logger->debug(""); 84 $logger->info(""); 85 $logger->notice(""); 86 $logger->warn(""); 87 $logger->error(""); 88 $logger->critical(""); 89 } 90 91 error_log("############# With Level Names"); 92 for($i = 0; $i < 6; $i++) { 93 $logger->setLevel($logger->getLevelName($i)); 94 error_log("############## Level now: " . $logger->getLevelName($i)); 95 $logger->debug(""); 96 $logger->info("", __FILE__, __LINE__); 97 $logger->notice(""); 98 $logger->warn(""); 99 $logger->error(""); 100 $logger->critical(""); 101 } 102 } 103 ?>
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
| Generated: Sat Sep 6 04:46:52 2008 | Cross-referenced by PHPXref 0.7 |