Public Member Functions | Data Fields | Private Member Functions

ilLog Class Reference

logging More...

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= '')
 __destruct ()
 delete ()
 delete logfile

Data Fields

 $path
 $filename
 $tag
 $log_format
 $FATAL
 $WARNING
 $MESSAGE

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 <pgabriel@databay.de>
Version:
Id:
class.ilLog.php 16588 2008-05-08 09:32:37Z akill

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


Constructor & Destructor Documentation

ilLog::__destruct (  ) 

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

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


Member Function Documentation

ilLog::checkLogLevel ( a_log_level  ) 

determine log level

private

Parameters:
integer log level
Returns:
integer checked log level

Definition at line 129 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 297 of file class.ilLog.php.

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

ilLog::getLogFormat (  ) 

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

Referenced by write().

        {
                return $this->log_format;
        }

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

References 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:
integer error level code from PEAR_Error
string error message
See also:
this::write

Definition at line 202 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 266 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 279 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 157 of file class.ilLog.php.

        {
                $this->filename = $a_str;
        }

ilLog::setLogFormat ( a_format  ) 

Definition at line 142 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:
integer log level
Returns:
integer log level

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

Referenced by ilLog().

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

Here is the caller graph for this function:

ilLog::setPath ( a_str  ) 

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

        {
                $this->path = $a_str;
        }

ilLog::setTag ( a_str  ) 

Definition at line 162 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:
string error message
integer log level (optional)

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

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

Referenced by 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:
string public

Definition at line 176 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:
string public

Definition at line 189 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 55 of file class.ilLog.php.

ilLog::$filename

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

ilLog::$log_format

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

ilLog::$MESSAGE

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

ilLog::$path

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

ilLog::$tag

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

ilLog::$WARNING

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


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