ILIAS  release_4-4 Revision
All Data Structures Namespaces Files Functions Variables Modules Pages
Log_console Class Reference
+ Inheritance diagram for Log_console:
+ Collaboration diagram for Log_console:

Public Member Functions

 Log_console ($name, $ident='', $conf=array(), $level=PEAR_LOG_DEBUG)
 Constructs a new Log_console object. More...
 
 _Log_console ()
 Destructor. More...
 
 open ()
 Open the output stream. More...
 
 close ()
 Closes the output stream. More...
 
 flush ()
 Flushes all pending ("buffered") data to the output stream. More...
 
 log ($message, $priority=null)
 Writes $message to the text console. More...
 
- 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. More...
 
factory ($handler, $name='', $ident='', $conf=array(), $level=PEAR_LOG_DEBUG)
 Attempts to return a concrete Log instance of type $handler. More...
 
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. More...
 
 open ()
 Abstract implementation of the open() method. More...
 
 close ()
 Abstract implementation of the close() method. More...
 
 flush ()
 Abstract implementation of the flush() method. More...
 
 log ($message, $priority=null)
 Abstract implementation of the log() method. More...
 
 emerg ($message)
 A convenience function for logging a emergency event. More...
 
 alert ($message)
 A convenience function for logging an alert event. More...
 
 crit ($message)
 A convenience function for logging a critical event. More...
 
 err ($message)
 A convenience function for logging a error event. More...
 
 warning ($message)
 A convenience function for logging a warning event. More...
 
 notice ($message)
 A convenience function for logging a notice event. More...
 
 info ($message)
 A convenience function for logging a information event. More...
 
 debug ($message)
 A convenience function for logging a debug event. More...
 
 _extractMessage ($message)
 Returns the string representation of the message data. More...
 
 _getBacktraceVars ($depth)
 Using debug_backtrace(), returns the file, line, and enclosing function name of the source code context from which log() was invoked. More...
 
 _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. More...
 
 priorityToString ($priority)
 Returns the string representation of a PEAR_LOG_* integer constant. More...
 
 stringToPriority ($name)
 Returns the the PEAR_LOG_* integer constant for the given string representation of a priority name. More...
 
 MASK ($priority)
 Calculate the log mask for the given priority. More...
 
 UPTO ($priority)
 Calculate the log mask for all priorities up to the given priority. More...
 
 MIN ($priority)
 Calculate the log mask for all priorities greater than or equal to the given priority. More...
 
 MAX ($priority)
 Calculate the log mask for all priorities less than or equal to the given priority. More...
 
 setMask ($mask)
 Set and return the level mask for the current Log instance. More...
 
 getMask ()
 Returns the current level mask. More...
 
 _isMasked ($priority)
 Check if the given priority is included in the current level mask. More...
 
 getPriority ()
 Returns the current default priority. More...
 
 setPriority ($priority)
 Sets the default priority to the specified value. More...
 
 attach (&$observer)
 Adds a Log_observer instance to the list of observers that are listening for messages emitted by this Log instance. More...
 
 detach ($observer)
 Removes a Log_observer instance from the list of observers. More...
 
 _announce ($event)
 Informs each registered observer instance that a new message has been logged. More...
 
 isComposite ()
 Indicates whether this is a composite class. More...
 
 setIdent ($ident)
 Sets this Log instance's identification string. More...
 
 getIdent ()
 Returns the current identification string. More...
 

Data Fields

 $_stream = STDOUT
 
 $_buffering = false
 
 $_buffer = ''
 
 $_lineFormat = '%1$s %2$s [%3$s] %4$s'
 
 $_timeFormat = '%b %d %H:%M:%S'
 
- 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 19 of file console.php.

Member Function Documentation

◆ _Log_console()

Log_console::_Log_console ( )

Destructor.

Definition at line 104 of file console.php.

References close().

105  {
106  $this->close();
107  }
close()
Closes the output stream.
Definition: console.php:129
+ Here is the call graph for this function:

◆ close()

Log_console::close ( )

Closes the output stream.

This results in a call to flush().

public

Since
Log 1.9.0

Definition at line 129 of file console.php.

References flush().

Referenced by _Log_console().

130  {
131  $this->flush();
132  $this->_opened = false;
133  return true;
134  }
flush()
Flushes all pending ("buffered") data to the output stream.
Definition: console.php:142
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ flush()

Log_console::flush ( )

Flushes all pending ("buffered") data to the output stream.

public

Since
Log 1.8.2

Definition at line 142 of file console.php.

Referenced by close().

143  {
144  /*
145  * If output buffering is enabled, dump the contents of the buffer to
146  * the output stream.
147  */
148  if ($this->_buffering && (strlen($this->_buffer) > 0)) {
149  fwrite($this->_stream, $this->_buffer);
150  $this->_buffer = '';
151  }
152 
153  if (is_resource($this->_stream)) {
154  return fflush($this->_stream);
155  }
156 
157  return false;
158  }
+ Here is the caller graph for this function:

◆ log()

Log_console::log (   $message,
  $priority = null 
)

Writes $message to the text console.

Also, passes the message 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

Definition at line 172 of file console.php.

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

173  {
174  /* If a priority hasn't been specified, use the default value. */
175  if ($priority === null) {
176  $priority = $this->_priority;
177  }
178 
179  /* Abort early if the priority is above the maximum logging level. */
180  if (!$this->_isMasked($priority)) {
181  return false;
182  }
183 
184  /* Extract the string representation of the message. */
185  $message = $this->_extractMessage($message);
186 
187  /* Build the string containing the complete log line. */
188  $line = $this->_format($this->_lineFormat,
189  strftime($this->_timeFormat),
190  $priority, $message) . "\n";
191 
192  /*
193  * If buffering is enabled, append this line to the output buffer.
194  * Otherwise, print the line to the output stream immediately.
195  */
196  if ($this->_buffering) {
197  $this->_buffer .= $line;
198  } else {
199  fwrite($this->_stream, $line);
200  }
201 
202  /* Notify observers about this log message. */
203  $this->_announce(array('priority' => $priority, 'message' => $message));
204 
205  return true;
206  }
_announce($event)
Informs each registered observer instance that a new message has been logged.
Definition: Log.php:811
$_priority
Definition: Log.php:69
_isMasked($priority)
Check if the given priority is included in the current level mask.
Definition: Log.php:726
_extractMessage($message)
Returns the string representation of the message data.
Definition: Log.php:417
_format($format, $timestamp, $priority, $message)
Produces a formatted log line based on a format string and a set of variables representing the curren...
Definition: Log.php:530
+ Here is the call graph for this function:

◆ Log_console()

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

Constructs a new Log_console 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 67 of file console.php.

References Log\UPTO().

69  {
70  $this->_id = md5(microtime());
71  $this->_ident = $ident;
72  $this->_mask = Log::UPTO($level);
73 
74  if (!empty($conf['stream'])) {
75  $this->_stream = $conf['stream'];
76  }
77 
78  if (isset($conf['buffering'])) {
79  $this->_buffering = $conf['buffering'];
80  }
81 
82  if (!empty($conf['lineFormat'])) {
83  $this->_lineFormat = str_replace(array_keys($this->_formatMap),
84  array_values($this->_formatMap),
85  $conf['lineFormat']);
86  }
87 
88  if (!empty($conf['timeFormat'])) {
89  $this->_timeFormat = $conf['timeFormat'];
90  }
91 
92  /*
93  * If output buffering has been requested, we need to register a
94  * shutdown function that will dump the buffer upon termination.
95  */
96  if ($this->_buffering) {
97  register_shutdown_function(array(&$this, '_Log_console'));
98  }
99  }
UPTO($priority)
Calculate the log mask for all priorities up to the given priority.
Definition: Log.php:642
+ Here is the call graph for this function:

◆ open()

Log_console::open ( )

Open the output stream.

public

Since
Log 1.9.7

Definition at line 115 of file console.php.

116  {
117  $this->_opened = true;
118  return true;
119  }

Field Documentation

◆ $_buffer

Log_console::$_buffer = ''

Definition at line 40 of file console.php.

◆ $_buffering

Log_console::$_buffering = false

Definition at line 33 of file console.php.

◆ $_lineFormat

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

Definition at line 47 of file console.php.

◆ $_stream

Log_console::$_stream = STDOUT

Definition at line 26 of file console.php.

◆ $_timeFormat

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

Definition at line 56 of file console.php.


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