Moodle  2.2.1
http://www.collinsharper.com
C:/xampp/htdocs/moodle/lib/spikephpcoverage/src/util/CoverageLogger.php
Go to the documentation of this file.
00001 <?php
00002 /*
00003  *  $Id: CoverageLogger.php,v 1.2 2010/12/14 17:36:05 moodlerobot Exp $
00004  *  
00005  *  Copyright(c) 2004-2006, SpikeSource Inc. All Rights Reserved.
00006  *  Licensed under the Open Software License version 2.1
00007  *  (See http://www.spikesource.com/license.html)
00008  */
00009 ?>
00010 <?php
00011 
00012     class CoverageLogger {
00013 
00014         private $level;
00015         private $logLevels = array(
00016             "LOG_CRITICAL",
00017             "LOG_ERROR",
00018             "LOG_WARNING",
00019             "LOG_NOTICE",
00020             "LOG_INFO",
00021             "LOG_DEBUG"
00022         );
00023 
00024         public function setLevel($level) {
00025             if(!is_numeric($level)) {
00026                 for($i = 0; $i < count($this->logLevels); $i++) {
00027                     if(strcasecmp($this->logLevels[$i], $level) === 0) {
00028                         $level = $i;
00029                         break;
00030                     }
00031                 }
00032             }
00033             $this->level = $level;
00034         }
00035 
00036         public function critical($str, $file="", $line="") {
00037             if($this->level >= 0) {
00038                 error_log("[CRITICAL] [" . $file . ":" . $line . "] " . $str);
00039             }
00040         }
00041 
00042         public function error($str, $file="", $line="") {
00043             if($this->level >= 1) {
00044                 error_log("[ERROR] [" . $file . ":" . $line . "] " . $str);
00045             }
00046         }
00047 
00048         public function warn($str, $file="", $line="") {
00049             if($this->level >= 2) {
00050                 error_log("[WARNING] [" . $file . ":" . $line . "] " . $str);
00051             }
00052         }
00053 
00054         public function notice($str, $file="", $line="") {
00055             if($this->level >= 3) {
00056                 error_log("[NOTICE] [" . $file . ":" . $line . "] " . $str);
00057             }
00058         }
00059 
00060         public function info($str, $file="", $line="") {
00061             if($this->level >= 4) {
00062                 error_log("[INFO] [" . $file . ":" . $line . "] " . $str);
00063             }
00064         }
00065 
00066         public function debug($str, $file="", $line="") {
00067             if($this->level >= 5) {
00068                 error_log("[DEBUG] [" . $file . ":" . $line . "] " . $str);
00069             }
00070         }
00071 
00072         public function getLevelName($level) {
00073             return $this->logLevels[$level];
00074         }
00075     }
00076 
00077     // testing 
00078     if(isset($_SERVER["argv"][1]) && $_SERVER["argv"][1] == "__main__") {
00079         $logger = new CoverageLogger();
00080         for($i = 0; $i < 6; $i++) {
00081             $logger->setLevel($i);
00082             error_log("############## Level now: " . $i);
00083             $logger->debug("");
00084             $logger->info("");
00085             $logger->notice("");
00086             $logger->warn("");
00087             $logger->error("");
00088             $logger->critical("");
00089         }
00090 
00091         error_log("############# With Level Names");
00092         for($i = 0; $i < 6; $i++) {
00093             $logger->setLevel($logger->getLevelName($i));
00094             error_log("############## Level now: " . $logger->getLevelName($i));
00095             $logger->debug("");
00096             $logger->info("", __FILE__, __LINE__);
00097             $logger->notice("");
00098             $logger->warn("");
00099             $logger->error("");
00100             $logger->critical("");
00101         }
00102     }
00103 ?>
 All Data Structures Namespaces Files Functions Variables Enumerations