• Main Page
  • Related Pages
  • Namespaces
  • Data Structures
  • Files
  • File List
  • Globals

classes/class.ilLog.php

Go to the documentation of this file.
00001 <?php
00002 /*
00003         +-----------------------------------------------------------------------------+
00004         | ILIAS open source                                                           |
00005         +-----------------------------------------------------------------------------+
00006         | Copyright (c) 1998-2001 ILIAS open source, University of Cologne            |
00007         |                                                                             |
00008         | This program is free software; you can redistribute it and/or               |
00009         | modify it under the terms of the GNU General Public License                 |
00010         | as published by the Free Software Foundation; either version 2              |
00011         | of the License, or (at your option) any later version.                      |
00012         |                                                                             |
00013         | This program is distributed in the hope that it will be useful,             |
00014         | but WITHOUT ANY WARRANTY; without even the implied warranty of              |
00015         | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the               |
00016         | GNU General Public License for more details.                                |
00017         |                                                                             |
00018         | You should have received a copy of the GNU General Public License           |
00019         | along with this program; if not, write to the Free Software                 |
00020         | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA. |
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                 // init vars
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                 //TODO: go through logfile and search for the topic
00178                 //only write the log if the error wasn't reported yet
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; // don't log messages
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 } // END class.ilLog
00271 ?>

Generated on Fri Dec 13 2013 09:06:34 for ILIAS Release_3_4_x_branch .rev 46804 by  doxygen 1.7.1