ILIAS  release_8 Revision v8.19
All Data Structures Namespaces Files Functions Variables Modules Pages
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.

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

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  }
setLogFormat(string $a_format)
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
+ 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.

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

Referenced by write().

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
+ 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.

Referenced by ilSurveyQuestionpoolExport\buildExportFileXML().

264  : void
265  {
266  if (is_file($this->path . "/" . $this->filename)) {
267  unlink($this->path . "/" . $this->filename);
268  }
269  }
+ Here is the caller graph for this function:

◆ dump()

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

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

References write().

242  : void
243  {
244  $this->write(print_r($a_var, true), $a_log_level);
245  }
write(string $a_msg, $a_log_level=null)
logging
+ Here is the call graph for this function:

◆ getLogFormat()

ilLog::getLogFormat ( )

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

References $log_format.

Referenced by write().

119  : string
120  {
121  return $this->log_format;
122  }
string $log_format
Definition: class.ilLog.php:35
+ 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.

References write().

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  }
write(string $a_msg, $a_log_level=null)
logging
+ Here is the call graph for this function:

◆ logStack()

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

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

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

Referenced by write().

233  : void
234  {
235  try {
236  throw new Exception($a_message);
237  } catch (Exception $e) {
238  $this->write($e->getTraceAsString());
239  }
240  }
write(string $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.

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

Referenced by __construct(), and write().

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.
+ 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.

Referenced by __construct().

114  : void
115  {
116  $this->log_format = $a_format;
117  }
+ Here is the caller graph for this function:

◆ setLogLevel()

ilLog::setLogLevel ( int  $a_log_level)

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

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

Referenced by __construct().

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 $default_log_level
Definition: class.ilLog.php:57
int $FATAL
Log level 10: Log only fatal errors that could lead to serious problems.
Definition: class.ilLog.php:40
int $WARNING
Log level 20: This is the standard log level that is set if no level is given.
Definition: class.ilLog.php:45
int $MESSAGE
Log level 30: Logs messages and notices that are less important for system functionality like not tra...
Definition: class.ilLog.php:50
+ 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.

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

Referenced by dump(), ilObjGlossary\exportFileItems(), ilObjContentObject\exportFileItems(), ilStructureObject\exportXML(), ilObjGlossary\exportXML(), ilObjContentObject\exportXML(), ilObjGlossary\exportXMLGlossaryItems(), ilObjGlossary\exportXMLMediaObjects(), ilObjContentObject\exportXMLMediaObjects(), ilObjContentObject\exportXMLPageObjects(), logError(), logStack(), ilOrgUnitSimpleUserImportGUI\startImport(), ilOrgUnitSimpleImportGUI\startImport(), writeLanguageLog(), and writeWarning().

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  }
getLogFormat()
open()
Open log file.
logStack(string $a_message='')
checkLogLevel($a_log_level)
+ 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.

References write().

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  }
write(string $a_msg, $a_log_level=null)
logging
+ 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.

References write().

167  : void
168  {
169  $this->write("WARNING: " . $a_message);
170  }
write(string $a_msg, $a_log_level=null)
logging
+ 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: