ILIAS  Release_4_1_x_branch Revision 61804
 All Data Structures Namespaces Files Functions Variables Groups Pages
Log_file Class Reference
+ Inheritance diagram for Log_file:
+ Collaboration diagram for Log_file:

Public Member Functions

 Log_file ($name, $ident= '', $conf=array(), $level=PEAR_LOG_DEBUG)
 Constructs a new Log_file object.
 _Log_file ()
 Destructor.
 _mkpath ($path, $mode=0700)
 Creates the given directory path.
 open ()
 Opens the log file for output.
 close ()
 Closes the log file if it is open.
 flush ()
 Flushes all pending data to the file handle.
 log ($message, $priority=null)
 Logs $message to the output window.
- Public Member Functions inherited from Log
 _classExists ($class)
 Utility function which wraps PHP's class_exists() function to ensure consistent behavior between PHP versions 4 and 5.
factory ($handler, $name= '', $ident= '', $conf=array(), $level=PEAR_LOG_DEBUG)
 Attempts to return a concrete Log instance of type $handler.
singleton ($handler, $name= '', $ident= '', $conf=array(), $level=PEAR_LOG_DEBUG)
 Attempts to return a reference to a concrete Log instance of type $handler, only creating a new instance if no log instance with the same parameters currently exists.
 emerg ($message)
 A convenience function for logging a emergency event.
 alert ($message)
 A convenience function for logging an alert event.
 crit ($message)
 A convenience function for logging a critical event.
 err ($message)
 A convenience function for logging a error event.
 warning ($message)
 A convenience function for logging a warning event.
 notice ($message)
 A convenience function for logging a notice event.
 info ($message)
 A convenience function for logging a information event.
 debug ($message)
 A convenience function for logging a debug event.
 _extractMessage ($message)
 Returns the string representation of the message data.
 _getBacktraceVars ($depth)
 Using debug_backtrace(), returns the file, line, and enclosing function name of the source code context from which log() was invoked.
 _format ($format, $timestamp, $priority, $message)
 Produces a formatted log line based on a format string and a set of variables representing the current log record and state.
 priorityToString ($priority)
 Returns the string representation of a PEAR_LOG_* integer constant.
 stringToPriority ($name)
 Returns the the PEAR_LOG_* integer constant for the given string representation of a priority name.
 MASK ($priority)
 Calculate the log mask for the given priority.
 UPTO ($priority)
 Calculate the log mask for all priorities up to the given priority.
 MIN ($priority)
 Calculate the log mask for all priorities greater than or equal to the given priority.
 MAX ($priority)
 Calculate the log mask for all priorities less than or equal to the given priority.
 setMask ($mask)
 Set and return the level mask for the current Log instance.
 getMask ()
 Returns the current level mask.
 _isMasked ($priority)
 Check if the given priority is included in the current level mask.
 getPriority ()
 Returns the current default priority.
 setPriority ($priority)
 Sets the default priority to the specified value.
 attach (&$observer)
 Adds a Log_observer instance to the list of observers that are listening for messages emitted by this Log instance.
 detach ($observer)
 Removes a Log_observer instance from the list of observers.
 _announce ($event)
 Informs each registered observer instance that a new message has been logged.
 isComposite ()
 Indicates whether this is a composite class.
 setIdent ($ident)
 Sets this Log instance's identification string.
 getIdent ()
 Returns the current identification string.

Data Fields

 $_filename = 'php.log'
 $_fp = false
 $_append = true
 $_locking = false
 $_mode = 0644
 $_dirmode = 0755
 $_lineFormat = '%1$s %2$s [%3$s] %4$s'
 $_timeFormat = '%b %d %H:%M:%S'
 $_eol = "\n"
- Data Fields inherited from Log
 $_opened = false
 $_id = 0
 $_ident = ''
 $_priority = PEAR_LOG_INFO
 $_mask = PEAR_LOG_ALL
 $_listeners = array()
 $_formatMap

Detailed Description

Definition at line 20 of file file.php.

Member Function Documentation

Log_file::_Log_file ( )

Destructor.

Definition at line 152 of file file.php.

References close().

{
if ($this->_opened) {
$this->close();
}
}

+ Here is the call graph for this function:

Log_file::_mkpath (   $path,
  $mode = 0700 
)

Creates the given directory path.

If the parent directories don't already exist, they will be created, too.

This implementation is inspired by Python's os.makedirs function.

Parameters
string$pathThe full directory path to create.
integer$modeThe permissions mode with which the directories will be created.
Returns
True if the full path is successfully created or already exists.

private

Definition at line 174 of file file.php.

References $path.

Referenced by open().

{
/* Separate the last pathname component from the rest of the path. */
$head = dirname($path);
$tail = basename($path);
/* Make sure we've split the path into two complete components. */
if (empty($tail)) {
$head = dirname($path);
$tail = basename($path);
}
/* Recurse up the path if our current segment does not exist. */
if (!empty($head) && !empty($tail) && !is_dir($head)) {
$this->_mkpath($head, $mode);
}
/* Create this segment of the path. */
return @mkdir($head, $mode);
}

+ Here is the caller graph for this function:

Log_file::close ( )

Closes the log file if it is open.

public

Reimplemented from Log.

Definition at line 235 of file file.php.

Referenced by _Log_file().

{
/* If the log file is open, close it. */
if ($this->_opened && fclose($this->_fp)) {
$this->_opened = false;
}
return ($this->_opened === false);
}

+ Here is the caller graph for this function:

Log_file::flush ( )

Flushes all pending data to the file handle.

public

Since
Log 1.8.2

Reimplemented from Log.

Definition at line 251 of file file.php.

{
if (is_resource($this->_fp)) {
return fflush($this->_fp);
}
return false;
}
Log_file::log (   $message,
  $priority = null 
)

Logs $message to the output window.

The message is also passed along to any Log_observer instances that are observing this Log.

Parameters
mixed$messageString or object containing the message to log.
string$priorityThe priority of the message. Valid values are: PEAR_LOG_EMERG, PEAR_LOG_ALERT, PEAR_LOG_CRIT, PEAR_LOG_ERR, PEAR_LOG_WARNING, PEAR_LOG_NOTICE, PEAR_LOG_INFO, and PEAR_LOG_DEBUG.
Returns
boolean True on success or false on failure. public

Reimplemented from Log.

Definition at line 272 of file file.php.

References $_eol, Log\$_priority, $success, Log\_announce(), Log\_extractMessage(), Log\_format(), Log\_isMasked(), and open().

{
/* If a priority hasn't been specified, use the default value. */
if ($priority === null) {
$priority = $this->_priority;
}
/* Abort early if the priority is above the maximum logging level. */
if (!$this->_isMasked($priority)) {
return false;
}
/* If the log file isn't already open, open it now. */
if (!$this->_opened && !$this->open()) {
return false;
}
/* Extract the string representation of the message. */
$message = $this->_extractMessage($message);
/* Build the string containing the complete log line. */
$line = $this->_format($this->_lineFormat,
strftime($this->_timeFormat),
$priority, $message) . $this->_eol;
/* If locking is enabled, acquire an exclusive lock on the file. */
if ($this->_locking) {
flock($this->_fp, LOCK_EX);
}
/* Write the log line to the log file. */
$success = (fwrite($this->_fp, $line) !== false);
/* Unlock the file now that we're finished writing to it. */
if ($this->_locking) {
flock($this->_fp, LOCK_UN);
}
/* Notify observers about this log message. */
$this->_announce(array('priority' => $priority, 'message' => $message));
return $success;
}

+ Here is the call graph for this function:

Log_file::Log_file (   $name,
  $ident = '',
  $conf = array(),
  $level = PEAR_LOG_DEBUG 
)

Constructs a new Log_file object.

Parameters
string$nameIgnored.
string$identThe identity string.
array$confThe configuration array.
int$levelLog messages up to and including this level. public

Definition at line 98 of file file.php.

References Log\UPTO().

{
$this->_id = md5(microtime());
$this->_filename = $name;
$this->_ident = $ident;
$this->_mask = Log::UPTO($level);
if (isset($conf['append'])) {
$this->_append = $conf['append'];
}
if (isset($conf['locking'])) {
$this->_locking = $conf['locking'];
}
if (!empty($conf['mode'])) {
if (is_string($conf['mode'])) {
$this->_mode = octdec($conf['mode']);
} else {
$this->_mode = $conf['mode'];
}
}
if (!empty($conf['dirmode'])) {
if (is_string($conf['dirmode'])) {
$this->_dirmode = octdec($conf['dirmode']);
} else {
$this->_dirmode = $conf['dirmode'];
}
}
if (!empty($conf['lineFormat'])) {
$this->_lineFormat = str_replace(array_keys($this->_formatMap),
array_values($this->_formatMap),
$conf['lineFormat']);
}
if (!empty($conf['timeFormat'])) {
$this->_timeFormat = $conf['timeFormat'];
}
if (!empty($conf['eol'])) {
$this->_eol = $conf['eol'];
} else {
$this->_eol = (strstr(PHP_OS, 'WIN')) ? "\r\n" : "\n";
}
register_shutdown_function(array(&$this, '_Log_file'));
}

+ Here is the call graph for this function:

Log_file::open ( )

Opens the log file for output.

If the specified log file does not already exist, it will be created. By default, new log entries are appended to the end of the log file.

This is implicitly called by log(), if necessary.

public

Reimplemented from Log.

Definition at line 204 of file file.php.

References Log\$_opened, and _mkpath().

Referenced by log().

{
if (!$this->_opened) {
/* If the log file's directory doesn't exist, create it. */
if (!is_dir(dirname($this->_filename))) {
$this->_mkpath($this->_filename, $this->_dirmode);
}
/* Determine whether the log file needs to be created. */
$creating = !file_exists($this->_filename);
/* Obtain a handle to the log file. */
$this->_fp = fopen($this->_filename, ($this->_append) ? 'a' : 'w');
/* We consider the file "opened" if we have a valid file pointer. */
$this->_opened = ($this->_fp !== false);
/* Attempt to set the file's permissions if we just created it. */
if ($creating && $this->_opened) {
chmod($this->_filename, $this->_mode);
}
}
}

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

Field Documentation

Log_file::$_append = true

Definition at line 42 of file file.php.

Log_file::$_dirmode = 0755

Definition at line 64 of file file.php.

Log_file::$_eol = "\n"

Definition at line 87 of file file.php.

Referenced by log().

Log_file::$_filename = 'php.log'

Definition at line 27 of file file.php.

Log_file::$_fp = false

Definition at line 34 of file file.php.

Log_file::$_lineFormat = '%1$s %2$s [%3$s] %4$s'

Definition at line 71 of file file.php.

Log_file::$_locking = false

Definition at line 49 of file file.php.

Log_file::$_mode = 0644

Definition at line 56 of file file.php.

Log_file::$_timeFormat = '%b %d %H:%M:%S'

Definition at line 80 of file file.php.


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