ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
ilLoggingActivity Class Reference

@noinspection PhpIncludeInspection More...

+ Inheritance diagram for ilLoggingActivity:
+ Collaboration diagram for ilLoggingActivity:

Public Member Functions

 __construct (ilNode $a_context)
 Default constructor. More...
 
 setLogFile ($a_log_file)
 Sets the log file name and path. More...
 
 getLogFile ()
 Returns the log file name and path. More...
 
 setLogMessage ($a_log_message)
 Sets the message to be logged. More...
 
 getLogMessage ()
 Returns the currently set log message. More...
 
 setLogLevel ($a_log_level)
 Sets the log level of the message to be logged. More...
 
 getLogLevel ()
 Returns the currently set log level. More...
 
 getContext ()
 Returns the parent object. More...
 
 execute ()
 Executes this action according to its settings. More...
 
 setName ($name)
 
 getName ()
 
 execute ()
 
 getContext ()
 This method returns the context of the element. More...
 
 setName ($name)
 
 getName ()
 

Protected Attributes

 $name
 

Private Member Functions

 checkFileWriteability ($a_log_file)
 Checks if the file is "really really" writeable. More...
 
 checkExtensionValidity ($extension)
 Checks if the given extension is a listed one. More...
 
 checkForExistingLogMessageContent ($a_log_message)
 Checks if an actual log message is set for the instance. More...
 
 determineValidityOfLogLevel ($a_log_level)
 Determines, if the given log level is a valid one. More...
 
 closeFilePointer ($file_pointer)
 Closes the file pointer. More...
 
 writeLogMessage ($file_pointer)
 Writes the instances log message to the logfile. More...
 
 acquireFilePointer ()
 Acquires and returns a file pointer to the instances log file. More...
 

Private Attributes

 $context
 
 $log_file = 'none.log'
 
 $log_message = 'no message set'
 
 $log_level = 'MESSAGE'
 

Detailed Description

@noinspection PhpIncludeInspection

@noinspection PhpIncludeInspection @noinspection PhpIncludeInspection Class ilLoggingActivity

This activity writes a given message with loglevel to the given logfile. Design consideration is to configure the activity at the workflows creation time, since it is triggered on known conditions.

Author
Maximilian Becker mbeck.nosp@m.er@d.nosp@m.ataba.nosp@m.y.de
Version
$Id$

/

Definition at line 23 of file class.ilLoggingActivity.php.

Constructor & Destructor Documentation

◆ __construct()

ilLoggingActivity::__construct ( ilNode  $a_context)

Default constructor.

Parameters
ilNode$a_context

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

51 {
52 $this->context = $a_context;
53 }

Member Function Documentation

◆ acquireFilePointer()

ilLoggingActivity::acquireFilePointer ( )
private

Acquires and returns a file pointer to the instances log file.

Returns
resource File pointer
Exceptions
ilWorkflowFilesystemException

@noinspection PhpIncludeInspection

Definition at line 282 of file class.ilLoggingActivity.php.

283 {
284 $file_pointer = fopen($this->log_file, 'a');
285 if ($file_pointer == null) {
287 require_once './Services/WorkflowEngine/exceptions/ilWorkflowFilesystemException.php';
288 throw new ilWorkflowFilesystemException('Cannot write to filesystem - no pointer returned.', 1000);
289 }
290 return $file_pointer;
291 }
@noinspection PhpIncludeInspection

Referenced by execute().

+ Here is the caller graph for this function:

◆ checkExtensionValidity()

ilLoggingActivity::checkExtensionValidity (   $extension)
private

Checks if the given extension is a listed one.

(One of .log or .txt)

Parameters
$extension
Returns
void
Exceptions
ilWorkflowObjectStateException

@noinspection PhpIncludeInspection

Definition at line 100 of file class.ilLoggingActivity.php.

101 {
102 if ($extension != '.log' && $extension != '.txt') {
104 require_once './Services/WorkflowEngine/exceptions/ilWorkflowObjectStateException.php';
105 throw new ilWorkflowObjectStateException('Illegal extension. Log file must be either .txt or .log.', 1002);
106 }
107 }
@noinspection PhpIncludeInspection

Referenced by setLogFile().

+ Here is the caller graph for this function:

◆ checkFileWriteability()

ilLoggingActivity::checkFileWriteability (   $a_log_file)
private

Checks if the file is "really really" writeable.

Parameters
$a_log_file
Returns
void
Exceptions
ilWorkflowFilesystemException

@noinspection PhpUsageOfSilenceOperatorInspection

@noinspection PhpIncludeInspection

Definition at line 79 of file class.ilLoggingActivity.php.

80 {
82 @$file_handle = fopen($a_log_file, 'a+');
83 if ($file_handle == null) {
85 require_once './Services/WorkflowEngine/exceptions/ilWorkflowFilesystemException.php';
86 throw new ilWorkflowFilesystemException('Could not write to filesystem - no pointer returned.', 1002);
87 }
88 fclose($file_handle);
89 }

Referenced by setLogFile().

+ Here is the caller graph for this function:

◆ checkForExistingLogMessageContent()

ilLoggingActivity::checkForExistingLogMessageContent (   $a_log_message)
private

Checks if an actual log message is set for the instance.

Parameters
$a_log_message
Returns
void
Exceptions
ilWorkflowObjectStateException

@noinspection PhpIncludeInspection

Definition at line 141 of file class.ilLoggingActivity.php.

142 {
143 if ($a_log_message == null || $a_log_message == '') {
145 require_once './Services/WorkflowEngine/exceptions/ilWorkflowObjectStateException.php';
146 throw new ilWorkflowObjectStateException('Log message must not be null or empty.', 1002);
147 }
148 }

Referenced by setLogMessage().

+ Here is the caller graph for this function:

◆ closeFilePointer()

ilLoggingActivity::closeFilePointer (   $file_pointer)
private

Closes the file pointer.

Parameters
$file_pointer
Returns
void
Exceptions
ilWorkflowFilesystemException

@noinspection PhpIncludeInspection

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

251 {
252 if (!fclose($file_pointer)) {
254 require_once './Services/WorkflowEngine/exceptions/ilWorkflowFilesystemException.php';
255 throw new ilWorkflowFilesystemException('Cannot write to filesystem - pointer returned did not close.', 1001);
256 }
257 }

Referenced by execute().

+ Here is the caller graph for this function:

◆ determineValidityOfLogLevel()

ilLoggingActivity::determineValidityOfLogLevel (   $a_log_level)
private

Determines, if the given log level is a valid one.

Log levels are similar to Apache log4j levels.

Parameters
$a_log_level
Returns
bool

Definition at line 190 of file class.ilLoggingActivity.php.

191 {
192 switch (strtolower($a_log_level)) {
193 case 'trace':
194 case 'message':
195 case 'warning':
196 case 'debug':
197 case 'info':
198 case 'fatal':
199 $valid = true;
200 break;
201 default:
202 $valid = false;
203 return $valid;
204 }
205 return $valid;
206 }
$valid

References $valid.

Referenced by setLogLevel().

+ Here is the caller graph for this function:

◆ execute()

ilLoggingActivity::execute ( )

Executes this action according to its settings.

Returns
void

Implements ilActivity.

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

234 {
235 $file_pointer = null;
236 $file_pointer = $this->acquireFilePointer();
237 $this->writeLogMessage($file_pointer);
238 $this->closeFilePointer($file_pointer);
239 }
writeLogMessage($file_pointer)
Writes the instances log message to the logfile.
closeFilePointer($file_pointer)
Closes the file pointer.
acquireFilePointer()
Acquires and returns a file pointer to the instances log file.

References acquireFilePointer(), closeFilePointer(), and writeLogMessage().

+ Here is the call graph for this function:

◆ getContext()

ilLoggingActivity::getContext ( )

Returns the parent object.

Type is ilNode, implements ilWorkflowEngineElement

Returns
ilNode Parent node of this element.

Implements ilWorkflowEngineElement.

Definition at line 223 of file class.ilLoggingActivity.php.

224 {
225 return $this->context;
226 }

References $context.

◆ getLogFile()

ilLoggingActivity::getLogFile ( )

Returns the log file name and path.

Returns
string File name and path of the log file.

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

115 {
116 return $this->log_file;
117 }

References $log_file.

◆ getLogLevel()

ilLoggingActivity::getLogLevel ( )

Returns the currently set log level.

Returns
string

Definition at line 213 of file class.ilLoggingActivity.php.

References $log_level.

◆ getLogMessage()

ilLoggingActivity::getLogMessage ( )

Returns the currently set log message.

Returns
string

Definition at line 155 of file class.ilLoggingActivity.php.

References $log_message.

◆ getName()

ilLoggingActivity::getName ( )
Returns
mixed

Implements ilWorkflowEngineElement.

Definition at line 298 of file class.ilLoggingActivity.php.

299 {
300 return $this->name;
301 }

References $name.

◆ setLogFile()

ilLoggingActivity::setLogFile (   $a_log_file)

Sets the log file name and path.

Parameters
string$a_log_filePath, name and extension of the log file.
Returns
void

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

63 {
64 $extension = substr($a_log_file, strlen($a_log_file) - 4, 4);
65 $this->checkExtensionValidity($extension);
66 $this->checkFileWriteability($a_log_file);
67 $this->log_file = $a_log_file;
68 }
checkExtensionValidity($extension)
Checks if the given extension is a listed one.
checkFileWriteability($a_log_file)
Checks if the file is "really really" writeable.

References checkExtensionValidity(), and checkFileWriteability().

+ Here is the call graph for this function:

◆ setLogLevel()

ilLoggingActivity::setLogLevel (   $a_log_level)

Sets the log level of the message to be logged.

See also
$log_level
Parameters
string$a_log_levelA valid log level.
Returns
void
Exceptions
ilWorkflowObjectStateExceptionon illegal log level.

@noinspection PhpIncludeInspection

Definition at line 171 of file class.ilLoggingActivity.php.

172 {
173 $valid = $this->determineValidityOfLogLevel($a_log_level);
174 if ($valid == false) {
176 require_once './Services/WorkflowEngine/exceptions/ilWorkflowObjectStateException.php';
177 throw new ilWorkflowObjectStateException('Log level must be one of: message, warning, debug, info, fatal.', 1002);
178 }
179 $this->log_level = strtoupper($a_log_level);
180 }
determineValidityOfLogLevel($a_log_level)
Determines, if the given log level is a valid one.

References $valid, and determineValidityOfLogLevel().

+ Here is the call graph for this function:

◆ setLogMessage()

ilLoggingActivity::setLogMessage (   $a_log_message)

Sets the message to be logged.

Parameters
string$a_log_messageText of the log message
Returns
void

Definition at line 126 of file class.ilLoggingActivity.php.

127 {
128 $this->checkForExistingLogMessageContent($a_log_message);
129 $this->log_message = $a_log_message;
130 }
checkForExistingLogMessageContent($a_log_message)
Checks if an actual log message is set for the instance.

References checkForExistingLogMessageContent().

+ Here is the call graph for this function:

◆ setName()

ilLoggingActivity::setName (   $name)
Parameters
string$name
Returns
mixed

Implements ilWorkflowEngineElement.

Definition at line 293 of file class.ilLoggingActivity.php.

294 {
295 $this->name = $name;
296 }

References $name.

◆ writeLogMessage()

ilLoggingActivity::writeLogMessage (   $file_pointer)
private

Writes the instances log message to the logfile.

Parameters
$file_pointer
Returns
void

@noinspection PhpIncludeInspection

Definition at line 266 of file class.ilLoggingActivity.php.

267 {
269 require_once './Services/WorkflowEngine/classes/utils/class.ilWorkflowUtils.php';
270 fwrite($file_pointer, date('Y/m/d H:i:s') . substr((string) ilWorkflowUtils::microtime(), 1, 6) . ' :: ');
271 fwrite($file_pointer, $this->log_level . ' :: ');
272 fwrite($file_pointer, $this->log_message . "\r\n");
273 }

Referenced by execute().

+ Here is the caller graph for this function:

Field Documentation

◆ $context

ilLoggingActivity::$context
private

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

Referenced by getContext().

◆ $log_file

ilLoggingActivity::$log_file = 'none.log'
private

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

Referenced by getLogFile().

◆ $log_level

ilLoggingActivity::$log_level = 'MESSAGE'
private

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

Referenced by getLogLevel().

◆ $log_message

ilLoggingActivity::$log_message = 'no message set'
private

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

Referenced by getLogMessage().

◆ $name

string ilLoggingActivity::$name
protected

Definition at line 43 of file class.ilLoggingActivity.php.

Referenced by getName(), and setName().


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