Go to the documentation of this file.00001 <?php
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00038 class ilLog
00039 {
00040
00046 var $path;
00047 var $filename;
00048 var $tag;
00049 var $log_format;
00050
00056 var $FATAL;
00057
00063 var $WARNING;
00064
00070 var $MESSAGE;
00071
00081 function ilLog($a_log_path, $a_log_file, $a_tag = "", $a_enabled = true, $a_log_level = NULL)
00082 {
00083
00084 $this->FATAL = 10;
00085 $this->WARNING = 20;
00086 $this->MESSAGE = 30;
00087
00088 $this->default_log_level= $this->WARNING;
00089 $this->current_log_level = $this->setLogLevel($a_log_level);
00090
00091 $this->path = ($a_log_path) ? $a_log_path : ILIAS_ABSOLUTE_PATH;
00092 $this->filename = ($a_log_file) ? $a_log_file : "ilias.log";
00093 $this->tag = ($a_tag == "") ? "unknown" : $a_tag;
00094 $this->enabled = (bool) $a_enabled;
00095 $this->setLogFormat(date("[y-m-d H:i:s] ")."[".$this->tag."] ");
00096
00097 }
00098
00106 function setLogLevel($a_log_level)
00107 {
00108 switch (strtolower($a_log_level))
00109 {
00110 case "fatal":
00111 return $this->FATAL;
00112 case "warning":
00113 return $this->WARNING;
00114 case "message":
00115 return $this->MESSAGE;
00116 default:
00117 return $this->default_log_level;
00118 }
00119 }
00120
00128 function checkLogLevel($a_log_level)
00129 {
00130 if (empty($a_log_level))
00131 return $this->default_log_level;
00132
00133 $level = (int) $a_log_level;
00134
00135 if ($a_log_level != (int) $a_log_level)
00136 return $this->default_log_level;
00137
00138 return $level;
00139 }
00140
00141 function setLogFormat($a_format)
00142 {
00143 $this->log_format = $a_format;
00144 }
00145
00146 function getLogFormat()
00147 {
00148 return $this->log_format;
00149 }
00150
00151 function setPath($a_str)
00152 {
00153 $this->path = $a_str;
00154 }
00155
00156 function setFilename($a_str)
00157 {
00158 $this->filename = $a_str;
00159 }
00160
00161 function setTag($a_str)
00162 {
00163 $this->tag = $a_str;
00164 }
00165
00175 function writeLanguageLog($a_topic,$a_lang_key)
00176 {
00177
00178
00179 $this->write("Language (".$a_lang_key."): topic -".$a_topic."- not present",$this->MESSAGE);
00180 }
00181
00188 function writeWarning($a_message)
00189 {
00190 $this->write("WARNING: ".$a_message);
00191 }
00192
00201 function logError($a_code,$a_msg)
00202 {
00203 switch ($a_code)
00204 {
00205 case "3":
00206 return;
00207 $error_level = "message";
00208 break;
00209
00210 case "2":
00211 $error_level = "warning";
00212 break;
00213
00214 case "1":
00215 $error_level = "fatal";
00216 break;
00217
00218 default:
00219 $error_level = "unknown";
00220 break;
00221 }
00222
00223 $this->write("ERROR (".$error_level."): ".$a_msg);
00224 }
00225
00240 function write($a_msg, $a_log_level = NULL)
00241 {
00242 if ($this->enabled and $this->current_log_level >= $this->checkLogLevel($a_log_level))
00243 {
00244 $fp = @fopen ($this->path."/".$this->filename, "a");
00245
00246 if ($fp == false)
00247 {
00248 die("Logfile: cannot open file. Please give Logfile Writepermissions.");
00249 }
00250
00251 if (fwrite($fp,$this->getLogFormat().$a_msg."\n") == -1)
00252 {
00253 die("Logfile: cannot write to file. Please give Logfile Writepermissions.");
00254 }
00255
00256 fclose($fp);
00257 }
00258 }
00259
00263 function delete()
00264 {
00265 if (@is_file($this->path."/".$this->filename))
00266 {
00267 @unlink($this->path."/".$this->filename);
00268 }
00269 }
00270 }
00271 ?>