ILIAS  Release_4_2_x_branch Revision 61807
 All Data Structures Namespaces Files Functions Variables Groups 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
 setLogLevel ($a_log_level)
 set global log level
 checkLogLevel ($a_log_level)
 determine log level
 setLogFormat ($a_format)
 getLogFormat ()
 setPath ($a_str)
 setFilename ($a_str)
 setTag ($a_str)
 writeLanguageLog ($a_topic, $a_lang_key)
 special language checking routine
 writeWarning ($a_message)
 special warning message
 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
 write ($a_msg, $a_log_level=NULL)
 logging
 logStack ($a_message= '')
 dump ($a_var, $a_log_level=NULL)
 Dump a variable to the log.
 __destruct ()
 delete ()
 delete logfile

Data Fields

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

Private Member Functions

 open ()

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

ilLog::__destruct ( )

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

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

Member Function Documentation

ilLog::checkLogLevel (   $a_log_level)

determine log level

private

Parameters
integerlog level
Returns
integer checked log level

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

Referenced by write().

{
if (empty($a_log_level))
return $this->default_log_level;
$level = (int) $a_log_level;
if ($a_log_level != (int) $a_log_level)
return $this->default_log_level;
return $level;
}

+ Here is the caller graph for this function:

ilLog::delete ( )

delete logfile

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

Referenced by ilSurveyQuestionpoolExport\buildExportFileXML().

{
if (@is_file($this->path."/".$this->filename))
{
@unlink($this->path."/".$this->filename);
}
}

+ Here is the caller graph for this function:

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

Dump a variable to the log.

Parameters
@return

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

References write().

{
$this->write(print_r($a_var, true), $a_log_level);
}

+ Here is the call graph for this function:

ilLog::getLogFormat ( )

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

References $log_format.

Referenced by write().

{
}

+ Here is the caller graph for this function:

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

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

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

{
// init vars
$this->FATAL = 10;
$this->WARNING = 20;
$this->MESSAGE = 30;
$this->default_log_level= $this->WARNING;
$this->current_log_level = $this->setLogLevel($a_log_level);
$this->path = ($a_log_path) ? $a_log_path : ILIAS_ABSOLUTE_PATH;
$this->filename = ($a_log_file) ? $a_log_file : "ilias.log";
$this->tag = ($a_tag == "") ? "unknown" : $a_tag;
$this->enabled = (bool) $a_enabled;
$this->setLogFormat(@date("[y-m-d H:i:s] ")."[".$this->tag."] ");
$this->open();
}

+ Here is the call graph for this function:

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 185 of file class.ilLog.php.

References write().

{
switch ($a_code)
{
case "3":
return; // don't log messages
$error_level = "message";
break;
case "2":
$error_level = "warning";
break;
case "1":
$error_level = "fatal";
break;
default:
$error_level = "unknown";
break;
}
$this->write("ERROR (".$error_level."): ".$a_msg);
}

+ Here is the call graph for this function:

ilLog::logStack (   $a_message = '')

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

References write().

Referenced by write().

{
try
{
throw new Exception($a_message);
}
catch(Exception $e)
{
$this->write($e->getTraceAsString());
}
}

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

ilLog::open ( )
private

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

Referenced by ilLog(), and write().

{
if(!$this->fp)
{
$this->fp = @fopen ($this->path."/".$this->filename, "a");
}
}

+ Here is the caller graph for this function:

ilLog::setFilename (   $a_str)

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

{
$this->filename = $a_str;
}
ilLog::setLogFormat (   $a_format)

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

Referenced by ilLog().

{
$this->log_format = $a_format;
}

+ Here is the caller graph for this function:

ilLog::setLogLevel (   $a_log_level)

set global log level

private

Parameters
integerlog level
Returns
integer log level

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

References $FATAL, $MESSAGE, and $WARNING.

Referenced by ilLog().

{
switch (strtolower($a_log_level))
{
case "fatal":
return $this->FATAL;
case "warning":
case "message":
default:
return $this->default_log_level;
}
}

+ Here is the caller graph for this function:

ilLog::setPath (   $a_str)

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

{
$this->path = $a_str;
}
ilLog::setTag (   $a_str)

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

{
$this->tag = $a_str;
}
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 224 of file class.ilLog.php.

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

Referenced by dump(), logError(), logStack(), writeLanguageLog(), and writeWarning().

{
if ($this->enabled and $this->current_log_level >= $this->checkLogLevel($a_log_level))
{
$this->open();
if ($this->fp == false)
{
//die("Logfile: cannot open file. Please give Logfile Writepermissions.");
}
if (fwrite($this->fp,$this->getLogFormat().$a_msg."\n") == -1)
{
//die("Logfile: cannot write to file. Please give Logfile Writepermissions.");
}
// note: logStack() calls write() again, so do not make this call
// if no log level is given
if ($a_log_level == $this->FATAL)
{
$this->logStack();
}
}
}

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

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 159 of file class.ilLog.php.

References write().

{
//TODO: go through logfile and search for the topic
//only write the log if the error wasn't reported yet
$this->write("Language (".$a_lang_key."): topic -".$a_topic."- not present",$this->MESSAGE);
}

+ Here is the call graph for this function:

ilLog::writeWarning (   $a_message)

special warning message

Parameters
stringpublic

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

References write().

{
$this->write("WARNING: ".$a_message);
}

+ Here is the call graph for this function:

Field Documentation

ilLog::$FATAL

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

Referenced by setLogLevel().

ilLog::$filename

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

ilLog::$fp = false

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

ilLog::$log_format

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

Referenced by getLogFormat().

ilLog::$MESSAGE

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

Referenced by setLogLevel().

ilLog::$path

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

ilLog::$tag

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

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: