ILIAS  release_4-4 Revision
All Data Structures Namespaces Files Functions Variables Modules Pages
ilLog Class Reference

logging More...

+ Collaboration diagram for ilLog:

Public Member Functions

 ilLog ($a_log_path, $a_log_file, $a_tag="", $a_enabled=true, $a_log_level=NULL)
 constructor More...
 
 setLogLevel ($a_log_level)
 set global log level More...
 
 checkLogLevel ($a_log_level)
 determine log level More...
 
 setLogFormat ($a_format)
 
 getLogFormat ()
 
 setPath ($a_str)
 
 setFilename ($a_str)
 
 setTag ($a_str)
 
 writeLanguageLog ($a_topic, $a_lang_key)
 special language checking routine More...
 
 writeWarning ($a_message)
 special warning message More...
 
 logError ($a_code, $a_msg)
 this function is automatically called by class.ilErrorHandler in case of an error To log manually please use $this::write public More...
 
 write ($a_msg, $a_log_level=NULL)
 logging More...
 
 logStack ($a_message='')
 
 dump ($a_var, $a_log_level=NULL)
 Dump a variable to the log. More...
 
 __destruct ()
 
 delete ()
 delete logfile More...
 

Data Fields

 $path
 
 $filename
 
 $tag
 
 $log_format
 
 $FATAL
 
 $WARNING
 
 $MESSAGE
 
 $fp = false
 

Private Member Functions

 open ()
 Open log file. More...
 

Detailed Description

logging

this class provides a logging feature to the application this class is easy to use. call the constructor with e.g. $log = new Log(); you can give a filename if you want, else the defaultfilename is used.

Author
Peter Gabriel pgabr.nosp@m.iel@.nosp@m.datab.nosp@m.ay.d.nosp@m.e
Version
Id
class.ilLog.php 16024 2008-02-19 13:07:07Z akill

Definition at line 18 of file class.ilLog.php.

Constructor & Destructor Documentation

◆ __destruct()

ilLog::__destruct ( )

Definition at line 299 of file class.ilLog.php.

300  {
301  @fclose($this->fp);
302  }

Member Function Documentation

◆ checkLogLevel()

ilLog::checkLogLevel (   $a_log_level)

determine log level

private

Parameters
integerlog level
Returns
integer checked log level

Definition at line 114 of file class.ilLog.php.

Referenced by write().

115  {
116  if (empty($a_log_level))
117  return $this->default_log_level;
118 
119  $level = (int) $a_log_level;
120 
121  if ($a_log_level != (int) $a_log_level)
122  return $this->default_log_level;
123 
124  return $level;
125  }
+ Here is the caller graph for this function:

◆ delete()

ilLog::delete ( )

delete logfile

Definition at line 309 of file class.ilLog.php.

Referenced by ilSurveyQuestionpoolExport\buildExportFileXML().

310  {
311  if (@is_file($this->path."/".$this->filename))
312  {
313  @unlink($this->path."/".$this->filename);
314  }
315  }
+ Here is the caller graph for this function:

◆ dump()

ilLog::dump (   $a_var,
  $a_log_level = NULL 
)

Dump a variable to the log.

Parameters

Definition at line 276 of file class.ilLog.php.

References write().

277  {
278  $this->write(print_r($a_var, true), $a_log_level);
279  }
write($a_msg, $a_log_level=NULL)
logging
+ Here is the call graph for this function:

◆ getLogFormat()

ilLog::getLogFormat ( )

Definition at line 132 of file class.ilLog.php.

References $log_format.

Referenced by write().

133  {
134  return $this->log_format;
135  }
+ Here is the caller graph for this function:

◆ ilLog()

ilLog::ilLog (   $a_log_path,
  $a_log_file,
  $a_tag = "",
  $a_enabled = true,
  $a_log_level = NULL 
)

constructor

set the filename

Parameters
string
Returns
boolean public
Exceptions
ilLogException

Definition at line 64 of file class.ilLog.php.

References $WARNING, ILIAS_ABSOLUTE_PATH, open(), setLogFormat(), and setLogLevel().

65  {
66  // init vars
67  $this->FATAL = 10;
68  $this->WARNING = 20;
69  $this->MESSAGE = 30;
70 
71  $this->default_log_level= $this->WARNING;
72  $this->current_log_level = $this->setLogLevel($a_log_level);
73 
74  $this->path = ($a_log_path) ? $a_log_path : ILIAS_ABSOLUTE_PATH;
75  $this->filename = ($a_log_file) ? $a_log_file : "ilias.log";
76  $this->tag = ($a_tag == "") ? "unknown" : $a_tag;
77  $this->enabled = (bool) $a_enabled;
78 
79  $this->setLogFormat(@date("[y-m-d H:i:s] ")."[".$this->tag."] ");
80 
81  $this->open();
82 
83  }
setLogFormat($a_format)
open()
Open log file.
setLogLevel($a_log_level)
set global log level
Definition: class.ilLog.php:92
const ILIAS_ABSOLUTE_PATH
+ Here is the call graph for this function:

◆ logError()

ilLog::logError (   $a_code,
  $a_msg 
)

this function is automatically called by class.ilErrorHandler in case of an error To log manually please use $this::write public

Parameters
integererror level code from PEAR_Error
stringerror message
See also
this::write

Definition at line 194 of file class.ilLog.php.

References write().

195  {
196  switch ($a_code)
197  {
198  case "3":
199  return; // don't log messages
200  $error_level = "message";
201  break;
202 
203  case "2":
204  $error_level = "warning";
205  break;
206 
207  case "1":
208  $error_level = "fatal";
209  break;
210 
211  default:
212  $error_level = "unknown";
213  break;
214  }
215 
216  $this->write("ERROR (".$error_level."): ".$a_msg);
217  }
write($a_msg, $a_log_level=NULL)
logging
+ Here is the call graph for this function:

◆ logStack()

ilLog::logStack (   $a_message = '')

Definition at line 258 of file class.ilLog.php.

References write().

Referenced by write().

259  {
260  try
261  {
262  throw new Exception($a_message);
263  }
264  catch(Exception $e)
265  {
266  $this->write($e->getTraceAsString());
267  }
268  }
write($a_msg, $a_log_level=NULL)
logging
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ open()

ilLog::open ( )
private

Open log file.

Exceptions
ilLogException

Definition at line 285 of file class.ilLog.php.

Referenced by ilLog(), and write().

286  {
287  if(!$this->fp)
288  {
289  $this->fp = @fopen ($this->path."/".$this->filename, "a");
290  }
291 
292  if (!$this->fp && $this->enabled)
293  {
294  include_once("./Services/Logging/exceptions/class.ilLogException.php");
295  throw new ilLogException('Unable to open log file for writing. Please check setup path to log file and possible write access.');
296  }
297  }
ILIAS Log exception class.
+ Here is the caller graph for this function:

◆ setFilename()

ilLog::setFilename (   $a_str)

Definition at line 142 of file class.ilLog.php.

143  {
144  $this->filename = $a_str;
145 
146  // on filename change reload close current file
147  if($this->fp)
148  {
149  fclose($this->fp);
150  $this->fp = null;
151  }
152  }

◆ setLogFormat()

ilLog::setLogFormat (   $a_format)

Definition at line 127 of file class.ilLog.php.

Referenced by ilLog().

128  {
129  $this->log_format = $a_format;
130  }
+ Here is the caller graph for this function:

◆ setLogLevel()

ilLog::setLogLevel (   $a_log_level)

set global log level

private

Parameters
integerlog level
Returns
integer log level

Definition at line 92 of file class.ilLog.php.

References $FATAL, $MESSAGE, and $WARNING.

Referenced by ilLog().

93  {
94  switch (strtolower($a_log_level))
95  {
96  case "fatal":
97  return $this->FATAL;
98  case "warning":
99  return $this->WARNING;
100  case "message":
101  return $this->MESSAGE;
102  default:
103  return $this->default_log_level;
104  }
105  }
+ Here is the caller graph for this function:

◆ setPath()

ilLog::setPath (   $a_str)

Definition at line 137 of file class.ilLog.php.

138  {
139  $this->path = $a_str;
140  }

◆ setTag()

ilLog::setTag (   $a_str)

Definition at line 154 of file class.ilLog.php.

155  {
156  $this->tag = $a_str;
157  }

◆ write()

ilLog::write (   $a_msg,
  $a_log_level = NULL 
)

logging

this method logs anything you want. It appends a line to the given logfile. Datetime and client id is appended automatically You may set the log level in each call. Leave blank to use default log level specified in ilias.ini: [log] level = "<level>" possible values are fatal,warning,message

public

Parameters
stringerror message
integerlog level (optional)

Definition at line 233 of file class.ilLog.php.

References checkLogLevel(), getLogFormat(), logStack(), and open().

Referenced by dump(), logError(), logStack(), ilBenchmark\save(), ilOrgUnitSimpleImportGUI\startImport(), writeLanguageLog(), and writeWarning().

234  {
235  if ($this->enabled and $this->current_log_level >= $this->checkLogLevel($a_log_level))
236  {
237  $this->open();
238 
239  if ($this->fp == false)
240  {
241  //die("Logfile: cannot open file. Please give Logfile Writepermissions.");
242  }
243 
244  if (fwrite($this->fp,$this->getLogFormat().$a_msg."\n") == -1)
245  {
246  //die("Logfile: cannot write to file. Please give Logfile Writepermissions.");
247  }
248 
249  // note: logStack() calls write() again, so do not make this call
250  // if no log level is given
251  if ($a_log_level == $this->FATAL)
252  {
253  $this->logStack();
254  }
255  }
256  }
getLogFormat()
open()
Open log file.
checkLogLevel($a_log_level)
determine log level
logStack($a_message='')
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ writeLanguageLog()

ilLog::writeLanguageLog (   $a_topic,
  $a_lang_key 
)

special language checking routine

only add a log entry to the logfile if there isn't a log entry for the topic

Parameters
stringpublic

Definition at line 168 of file class.ilLog.php.

References write().

169  {
170  //TODO: go through logfile and search for the topic
171  //only write the log if the error wasn't reported yet
172  $this->write("Language (".$a_lang_key."): topic -".$a_topic."- not present",$this->MESSAGE);
173  }
write($a_msg, $a_log_level=NULL)
logging
+ Here is the call graph for this function:

◆ writeWarning()

ilLog::writeWarning (   $a_message)

special warning message

Parameters
stringpublic

Definition at line 181 of file class.ilLog.php.

References write().

182  {
183  $this->write("WARNING: ".$a_message);
184  }
write($a_msg, $a_log_level=NULL)
logging
+ Here is the call graph for this function:

Field Documentation

◆ $FATAL

ilLog::$FATAL

Definition at line 36 of file class.ilLog.php.

Referenced by setLogLevel().

◆ $filename

ilLog::$filename

Definition at line 27 of file class.ilLog.php.

◆ $fp

ilLog::$fp = false

Definition at line 52 of file class.ilLog.php.

◆ $log_format

ilLog::$log_format

Definition at line 29 of file class.ilLog.php.

Referenced by getLogFormat().

◆ $MESSAGE

ilLog::$MESSAGE

Definition at line 50 of file class.ilLog.php.

Referenced by setLogLevel().

◆ $path

ilLog::$path

Definition at line 26 of file class.ilLog.php.

◆ $tag

ilLog::$tag

Definition at line 28 of file class.ilLog.php.

◆ $WARNING

ilLog::$WARNING

Definition at line 43 of file class.ilLog.php.

Referenced by ilLog(), and setLogLevel().


The documentation for this class was generated from the following file: