ILIAS  release_5-2 Revision v5.2.25-18-g3f80b828510
ilLoggingActivity Class Reference

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 ()
 

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

PhpIncludeInspection

PhpIncludeInspection 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

PhpIncludeInspection

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

Referenced by execute().

289  {
290  $file_pointer = fopen( $this->log_file, 'a' );
291  if ( $file_pointer == null )
292  {
294  require_once './Services/WorkflowEngine/exceptions/ilWorkflowFilesystemException.php';
295  throw new ilWorkflowFilesystemException( 'Cannot write to filesystem - no pointer returned.', 1000 );
296  }
297  return $file_pointer;
298  }
+ 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

PhpIncludeInspection

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

Referenced by setLogFile().

102  {
103  if ( $extension != '.log' && $extension != '.txt' )
104  {
106  require_once './Services/WorkflowEngine/exceptions/ilWorkflowObjectStateException.php';
107  throw new ilWorkflowObjectStateException( 'Illegal extension. Log file must be either .txt or .log.', 1002 );
108  }
109  }
+ 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

PhpUsageOfSilenceOperatorInspection

PhpIncludeInspection

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

Referenced by setLogFile().

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

PhpIncludeInspection

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

Referenced by setLogMessage().

144  {
145  if ( $a_log_message == null || $a_log_message == '' )
146  {
148  require_once './Services/WorkflowEngine/exceptions/ilWorkflowObjectStateException.php';
149  throw new ilWorkflowObjectStateException( 'Log message must not be null or empty.', 1002 );
150  }
151  }
+ 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

PhpIncludeInspection

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

Referenced by execute().

256  {
257  if ( !fclose( $file_pointer ) )
258  {
260  require_once './Services/WorkflowEngine/exceptions/ilWorkflowFilesystemException.php';
261  throw new ilWorkflowFilesystemException( 'Cannot write to filesystem - pointer returned did not close.', 1001 );
262  }
263  }
+ 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 194 of file class.ilLoggingActivity.php.

References $valid.

Referenced by setLogLevel().

195  {
196  switch ( strtolower( $a_log_level ) )
197  {
198  case 'trace':
199  case 'message':
200  case 'warning':
201  case 'debug':
202  case 'info':
203  case 'fatal':
204  $valid = true;
205  break;
206  default:
207  $valid = false;
208  return $valid;
209  }
210  return $valid;
211  }
$valid
+ 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 238 of file class.ilLoggingActivity.php.

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

239  {
240  $file_pointer = null;
241  $file_pointer = $this->acquireFilePointer();
242  $this->writeLogMessage( $file_pointer );
243  $this->closeFilePointer( $file_pointer );
244  }
writeLogMessage( $file_pointer)
Writes the instances log message to the logfile.
acquireFilePointer()
Acquires and returns a file pointer to the instances log file.
closeFilePointer( $file_pointer)
Closes the file pointer.
+ 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 228 of file class.ilLoggingActivity.php.

References $context.

229  {
230  return $this->context;
231  }

◆ getLogFile()

ilLoggingActivity::getLogFile ( )

Returns the log file name and path.

Returns
string File name and path of the log file.

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

References $log_file.

117  {
118  return $this->log_file;
119  }

◆ getLogLevel()

ilLoggingActivity::getLogLevel ( )

Returns the currently set log level.

Returns
string

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

References $log_level.

219  {
220  return $this->log_level;
221  }

◆ getLogMessage()

ilLoggingActivity::getLogMessage ( )

Returns the currently set log message.

Returns
string

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

References $log_message.

159  {
160  return $this->log_message;
161  }

◆ getName()

ilLoggingActivity::getName ( )
Returns
mixed

Implements ilWorkflowEngineElement.

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

References $name.

306  {
307  return $this->name;
308  }

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

References checkExtensionValidity(), and checkFileWriteability().

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

PhpIncludeInspection

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

References $valid, and determineValidityOfLogLevel().

175  {
176  $valid = $this->determineValidityOfLogLevel( $a_log_level );
177  if ($valid == false)
178  {
180  require_once './Services/WorkflowEngine/exceptions/ilWorkflowObjectStateException.php';
181  throw new ilWorkflowObjectStateException('Log level must be one of: message, warning, debug, info, fatal.', 1002);
182  }
183  $this->log_level = strtoupper($a_log_level);
184  }
$valid
determineValidityOfLogLevel( $a_log_level)
Determines, if the given log level is a valid one.
+ 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 128 of file class.ilLoggingActivity.php.

References checkForExistingLogMessageContent().

129  {
130  $this->checkForExistingLogMessageContent( $a_log_message );
131  $this->log_message = $a_log_message;
132  }
checkForExistingLogMessageContent( $a_log_message)
Checks if an actual log message is set for the instance.
+ Here is the call graph for this function:

◆ setName()

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

Implements ilWorkflowEngineElement.

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

References $name.

301  {
302  $this->name = $name;
303  }

◆ writeLogMessage()

ilLoggingActivity::writeLogMessage (   $file_pointer)
private

Writes the instances log message to the logfile.

Parameters
$file_pointer
Returns
void

PhpIncludeInspection

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

References date.

Referenced by execute().

273  {
275  require_once './Services/WorkflowEngine/classes/utils/class.ilWorkflowUtils.php';
276  fwrite( $file_pointer, date( 'Y/m/d H:i:s' ).substr( (string)ilWorkflowUtils::microtime(), 1, 6 ).' :: ' );
277  fwrite( $file_pointer, $this->log_level.' :: ' );
278  fwrite( $file_pointer, $this->log_message."\r\n" );
279  }
date( 'd-M-Y', $objPHPExcel->getProperties() ->getCreated())
+ 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

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: