ILIAS  release_7 Revision v7.30-3-g800a261c036
ilLog Class Reference

logging More...

+ Collaboration diagram for ilLog:

Public Member Functions

 __construct ($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 @access 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

◆ __construct()

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

constructor

set the filename

Parameters
string
Returns
boolean @access public
Exceptions
ilLogException

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

65 {
66 // init vars
67 include_once './Services/Logging/classes/public/class.ilLogLevel.php';
68
69 $this->FATAL = ilLogLevel::CRITICAL;
70 $this->WARNING = ilLogLevel::WARNING;
71 $this->MESSAGE = ilLogLevel::INFO;
72
73 $this->default_log_level = $this->WARNING;
74 $this->current_log_level = $this->setLogLevel($a_log_level);
75
76 $this->path = ($a_log_path) ? $a_log_path : ILIAS_ABSOLUTE_PATH;
77 $this->filename = ($a_log_file) ? $a_log_file : "ilias.log";
78 $this->tag = ($a_tag == "") ? "unknown" : $a_tag;
79 $this->enabled = (bool) $a_enabled;
80
81 $this->setLogFormat(@date("[y-m-d H:i:s] ") . "[" . $this->tag . "] ");
82
83 $this->open();
84 }
setLogFormat($a_format)
setLogLevel($a_log_level)
set global log level
Definition: class.ilLog.php:93
open()
Open log file.

References $WARNING, ilLogLevel\CRITICAL, ilLogLevel\INFO, open(), setLogFormat(), setLogLevel(), and ilLogLevel\WARNING.

+ Here is the call graph for this function:

◆ __destruct()

ilLog::__destruct ( )

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

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

Member Function Documentation

◆ checkLogLevel()

ilLog::checkLogLevel (   $a_log_level)

determine log level

@access private

Parameters
integerlog level
Returns
integer checked log level

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

115 {
116 if (empty($a_log_level)) {
117 return $this->default_log_level;
118 }
119
120 $level = (int) $a_log_level;
121
122 if ($a_log_level != (int) $a_log_level) {
123 return $this->default_log_level;
124 }
125
126 return $level;
127 }

Referenced by write().

+ Here is the caller graph for this function:

◆ delete()

ilLog::delete ( )

delete logfile

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

307 {
308 if (@is_file($this->path . "/" . $this->filename)) {
309 @unlink($this->path . "/" . $this->filename);
310 }
311 }

◆ dump()

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

Dump a variable to the log.

Parameters

return

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

276 {
277 $this->write(print_r($a_var, true), $a_log_level);
278 }
write($a_msg, $a_log_level=null)
logging

References write().

+ Here is the call graph for this function:

◆ getLogFormat()

ilLog::getLogFormat ( )

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

135 {
136 return $this->log_format;
137 }

References $log_format.

Referenced by write().

+ Here is the caller 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 @access public

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

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

202 {
203 switch ($a_code) {
204 case "3":
205 return; // don't log messages
206 $error_level = "message";
207 break;
208
209 case "2":
210 $error_level = "warning";
211 break;
212
213 case "1":
214 $error_level = "fatal";
215 break;
216
217 default:
218 $error_level = "unknown";
219 break;
220 }
221
222 $this->write("ERROR (" . $error_level . "): " . $a_msg);
223 }

References write().

+ Here is the call graph for this function:

◆ logStack()

ilLog::logStack (   $a_message = '')

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

261 {
262 try {
263 throw new Exception($a_message);
264 } catch (Exception $e) {
265 $this->write($e->getTraceAsString());
266 }
267 }

References Vendor\Package\$e, and write().

Referenced by write().

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

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

Referenced by __construct(), and write().

+ Here is the caller graph for this function:

◆ setFilename()

ilLog::setFilename (   $a_str)

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

151 {
152 $this->filename = $a_str;
153
154 // on filename change reload close current file
155 if ($this->fp) {
156 fclose($this->fp);
157 $this->fp = null;
158 }
159 }

◆ setLogFormat()

ilLog::setLogFormat (   $a_format)

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

130 {
131 $this->log_format = $a_format;
132 }

Referenced by __construct().

+ Here is the caller graph for this function:

◆ setLogLevel()

ilLog::setLogLevel (   $a_log_level)

set global log level

@access private

Parameters
integerlog level
Returns
integer log level

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

94 {
95 switch (strtolower($a_log_level)) {
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 }

References $FATAL, $MESSAGE, and $WARNING.

Referenced by __construct().

+ Here is the caller graph for this function:

◆ setPath()

ilLog::setPath (   $a_str)

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

140 {
141 $this->path = $a_str;
142
143 // on filename change reload close current file
144 if ($this->fp) {
145 fclose($this->fp);
146 $this->fp = null;
147 }
148 }

◆ setTag()

ilLog::setTag (   $a_str)

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

162 {
163 $this->tag = $a_str;
164 }

◆ 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

@access public

Parameters
stringerror message
integerlog level (optional)

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

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

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

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

+ 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
string@access public

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

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

References write().

+ Here is the call graph for this function:

◆ writeWarning()

ilLog::writeWarning (   $a_message)

special warning message

Parameters
string@access public

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

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

References write().

+ 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 __construct(), and setLogLevel().


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