ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
ilLog Class Reference

This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Learning e.V. More...

+ Collaboration diagram for ilLog:

Public Member Functions

 __construct (string $a_log_path, string $a_log_file, string $a_tag="", bool $a_enabled=true, ?int $a_log_level=null)
 
 setLogLevel (int $a_log_level)
 
 checkLogLevel ($a_log_level)
 
 setLogFormat (string $a_format)
 
 getLogFormat ()
 
 setPath (string $a_str)
 
 setFilename (string $a_str)
 
 setTag (string $a_str)
 
 writeLanguageLog (string $a_topic, string $a_lang_key)
 special language checking routine More...
 
 writeWarning (string $a_message)
 special warning message More...
 
 logError (string $a_code, string $a_msg)
 this function is automatically called by class.ilErrorHandler in case of an error To log manually please use $this::write More...
 
 write (string $a_msg, $a_log_level=null)
 logging More...
 
 logStack (string $a_message='')
 
 dump ($a_var, ?int $a_log_level=null)
 
 delete ()
 delete logfile More...
 

Protected Attributes

int $default_log_level
 
int $current_log_level
 
bool $enabled
 

Private Member Functions

 open ()
 Open log file. More...
 

Private Attributes

string $path = ''
 
string $filename = ''
 
string $tag = ''
 
string $log_format = ''
 
int $FATAL
 Log level 10: Log only fatal errors that could lead to serious problems. More...
 
int $WARNING
 Log level 20: This is the standard log level that is set if no level is given. More...
 
int $MESSAGE
 Log level 30: Logs messages and notices that are less important for system functionality like not translated language values. More...
 
 $fp = null
 

Detailed Description

This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Learning e.V.

ILIAS is licensed with the GPL-3.0, see https://www.gnu.org/licenses/gpl-3.0.en.html You should have received a copy of said license along with the source code, too.

If this is not the case or you just want to try ILIAS, you'll find us at: https://www.ilias.de https://github.com/ILIAS-eLearning

Deprecated:
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 30 of file class.ilLog.php.

Constructor & Destructor Documentation

◆ __construct()

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

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

67 {
68 // init vars
69
70 $this->FATAL = ilLogLevel::CRITICAL;
71 $this->WARNING = ilLogLevel::WARNING;
72 $this->MESSAGE = ilLogLevel::INFO;
73
74 $this->default_log_level = $this->WARNING;
75 $this->current_log_level = $this->setLogLevel($a_log_level ?? $this->default_log_level);
76
77 $this->path = ($a_log_path) ?: ILIAS_ABSOLUTE_PATH;
78 $this->filename = ($a_log_file) ?: "ilias.log";
79 $this->tag = ($a_tag == "") ? "unknown" : $a_tag;
80 $this->enabled = $a_enabled;
81 $this->setLogFormat(date("[y-m-d H:i:s] ") . "[" . $this->tag . "] ");
82 $this->open();
83 }
open()
Open log file.
int $WARNING
Log level 20: This is the standard log level that is set if no level is given.
Definition: class.ilLog.php:45
setLogLevel(int $a_log_level)
Definition: class.ilLog.php:85
setLogFormat(string $a_format)

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

+ Here is the call graph for this function:

Member Function Documentation

◆ checkLogLevel()

ilLog::checkLogLevel (   $a_log_level)
Parameters
int$a_log_level

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

102 : int
103 {
104 if (empty($a_log_level)) {
106 }
107 $level = (int) $a_log_level;
108 if ($a_log_level != (int) $a_log_level) {
110 }
111 return $level;
112 }
int $default_log_level
Definition: class.ilLog.php:57

References $default_log_level, and ILIAS\Repository\int().

Referenced by write().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ delete()

ilLog::delete ( )

delete logfile

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

264 : void
265 {
266 if (is_file($this->path . "/" . $this->filename)) {
267 unlink($this->path . "/" . $this->filename);
268 }
269 }

◆ dump()

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

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

242 : void
243 {
244 $this->write(print_r($a_var, true), $a_log_level);
245 }
write(string $a_msg, $a_log_level=null)
logging

References write().

+ Here is the call graph for this function:

◆ getLogFormat()

ilLog::getLogFormat ( )

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

119 : string
120 {
121 return $this->log_format;
122 }
string $log_format
Definition: class.ilLog.php:35

References $log_format.

Referenced by write().

+ Here is the caller graph for this function:

◆ logError()

ilLog::logError ( string  $a_code,
string  $a_msg 
)

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

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

176 : void
177 {
178 switch ($a_code) {
179 case "3":
180 return; // don't log messages
181
182 case "2":
183 $error_level = "warning";
184 break;
185
186 case "1":
187 $error_level = "fatal";
188 break;
189
190 default:
191 $error_level = "unknown";
192 break;
193 }
194 $this->write("ERROR (" . $error_level . "): " . $a_msg);
195 }

References write().

+ Here is the call graph for this function:

◆ logStack()

ilLog::logStack ( string  $a_message = '')

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

233 : void
234 {
235 try {
236 throw new Exception($a_message);
237 } catch (Exception $e) {
238 $this->write($e->getTraceAsString());
239 }
240 }

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.

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

250 : void
251 {
252 if (!$this->fp) {
253 $this->fp = @fopen($this->path . "/" . $this->filename, "a");
254 }
255
256 if (!$this->fp && $this->enabled) {
257 throw new ilLogException('Unable to open log file for writing. Please check setup path to log file and possible write access.');
258 }
259 }
ILIAS Log exception class.

Referenced by __construct(), and write().

+ Here is the caller graph for this function:

◆ setFilename()

ilLog::setFilename ( string  $a_str)

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

135 : void
136 {
137 $this->filename = $a_str;
138
139 // on filename change reload close current file
140 if ($this->fp) {
141 fclose($this->fp);
142 $this->fp = null;
143 }
144 }

◆ setLogFormat()

ilLog::setLogFormat ( string  $a_format)

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

114 : void
115 {
116 $this->log_format = $a_format;
117 }

Referenced by __construct().

+ Here is the caller graph for this function:

◆ setLogLevel()

ilLog::setLogLevel ( int  $a_log_level)

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

85 : int
86 {
87 switch (strtolower($a_log_level)) {
88 case "fatal":
89 return $this->FATAL;
90 case "warning":
91 return $this->WARNING;
92 case "message":
93 return $this->MESSAGE;
94 default:
96 }
97 }
int $FATAL
Log level 10: Log only fatal errors that could lead to serious problems.
Definition: class.ilLog.php:40
int $MESSAGE
Log level 30: Logs messages and notices that are less important for system functionality like not tra...
Definition: class.ilLog.php:50

References $default_log_level, $FATAL, $MESSAGE, and $WARNING.

Referenced by __construct().

+ Here is the caller graph for this function:

◆ setPath()

ilLog::setPath ( string  $a_str)

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

124 : void
125 {
126 $this->path = $a_str;
127
128 // on filename change reload close current file
129 if ($this->fp) {
130 fclose($this->fp);
131 $this->fp = null;
132 }
133 }

◆ setTag()

ilLog::setTag ( string  $a_str)

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

146 : void
147 {
148 $this->tag = $a_str;
149 }

◆ write()

ilLog::write ( string  $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

Parameters
?int$a_log_level

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

211 : void
212 {
213 $a_log_level = (int) $a_log_level;
214 if ($this->enabled and $this->current_log_level >= $this->checkLogLevel($a_log_level)) {
215 $this->open();
216
217 if ($this->fp == false) {
218 //die("Logfile: cannot open file. Please give Logfile Writepermissions.");
219 }
220
221 if (fwrite($this->fp, $this->getLogFormat() . $a_msg . "\n") == -1) {
222 //die("Logfile: cannot write to file. Please give Logfile Writepermissions.");
223 }
224
225 // note: logStack() calls write() again, so do not make this call
226 // if no log level is given
227 if ($a_log_level == $this->FATAL) {
228 $this->logStack();
229 }
230 }
231 }
logStack(string $a_message='')
checkLogLevel($a_log_level)
getLogFormat()

References checkLogLevel(), getLogFormat(), ILIAS\Repository\int(), logStack(), and open().

Referenced by dump(), ilObjContentObject\exportFileItems(), ilObjContentObject\exportXMLMediaObjects(), ilObjContentObject\exportXMLPageObjects(), 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 ( string  $a_topic,
string  $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

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

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

References write().

+ Here is the call graph for this function:

◆ writeWarning()

ilLog::writeWarning ( string  $a_message)

special warning message

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

167 : void
168 {
169 $this->write("WARNING: " . $a_message);
170 }

References write().

+ Here is the call graph for this function:

Field Documentation

◆ $current_log_level

int ilLog::$current_log_level
protected

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

◆ $default_log_level

int ilLog::$default_log_level
protected

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

Referenced by checkLogLevel(), and setLogLevel().

◆ $enabled

bool ilLog::$enabled
protected

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

◆ $FATAL

int ilLog::$FATAL
private

Log level 10: Log only fatal errors that could lead to serious problems.

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

Referenced by setLogLevel().

◆ $filename

string ilLog::$filename = ''
private

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

◆ $fp

ilLog::$fp = null
private

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

◆ $log_format

string ilLog::$log_format = ''
private

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

Referenced by getLogFormat().

◆ $MESSAGE

int ilLog::$MESSAGE
private

Log level 30: Logs messages and notices that are less important for system functionality like not translated language values.

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

Referenced by setLogLevel().

◆ $path

string ilLog::$path = ''
private

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

◆ $tag

string ilLog::$tag = ''
private

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

◆ $WARNING

int ilLog::$WARNING
private

Log level 20: This is the standard log level that is set if no level is given.

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

Referenced by __construct(), and setLogLevel().


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