ILIAS  release_5-3 Revision v5.3.23-19-g915713cf615
Monolog\Handler\BufferHandler Class Reference

Buffers all records until closing the handler and then pass them as batch. More...

+ Inheritance diagram for Monolog\Handler\BufferHandler:
+ Collaboration diagram for Monolog\Handler\BufferHandler:

Public Member Functions

 __construct (HandlerInterface $handler, $bufferLimit=0, $level=Logger::DEBUG, $bubble=true, $flushOnOverflow=false)
 
 handle (array $record)
 {Handles a record.All records may be passed to this method, and the handler should discard those that it does not want to handle.The return value of this function controls the bubbling process of the handler stack. Unless the bubbling is interrupted (by returning true), the Logger class will keep on calling further handlers in the stack with a given log record.
Parameters
array$recordThe record to handle
Returns
Boolean true means that this handler handled the record, and that bubbling is not permitted. false means the record was either not processed or that this handler allows bubbling.
} More...
 
 flush ()
 
 __destruct ()
 
 close ()
 {} More...
 
 clear ()
 Clears the buffer without flushing any messages down to the wrapped handler. More...
 
- Public Member Functions inherited from Monolog\Handler\AbstractHandler
 __construct ($level=Logger::DEBUG, $bubble=true)
 
 isHandling (array $record)
 {Checks whether the given record will be handled by this handler.This is mostly done for performance reasons, to avoid calling processors for nothing.Handlers should still check the record levels within handle(), returning false in isHandling() is no guarantee that handle() will not be called, and isHandling() might not be called for a given record.
Parameters
array$recordPartial log record containing only a level key
Returns
Boolean
} More...
 
 handleBatch (array $records)
 {Handles a set of records at once.
Parameters
array$recordsThe records to handle (an array of record arrays)
} More...
 
 close ()
 Closes the handler. More...
 
 pushProcessor ($callback)
 {Adds a processor in the stack.
Parameters
callable$callback
Returns
self
} More...
 
 popProcessor ()
 {Removes the processor on top of the stack and returns it.
Returns
callable
} More...
 
 setFormatter (FormatterInterface $formatter)
 {Sets the formatter.
Parameters
FormatterInterface$formatter
Returns
self
} More...
 
 getFormatter ()
 {Gets the formatter.
Returns
FormatterInterface
} More...
 
 setLevel ($level)
 Sets minimum logging level at which this handler will be triggered. More...
 
 getLevel ()
 Gets minimum logging level at which this handler will be triggered. More...
 
 setBubble ($bubble)
 Sets the bubbling behavior. More...
 
 getBubble ()
 Gets the bubbling behavior. More...
 
 __destruct ()
 

Protected Attributes

 $handler
 
 $bufferSize = 0
 
 $bufferLimit
 
 $flushOnOverflow
 
 $buffer = array()
 
 $initialized = false
 
- Protected Attributes inherited from Monolog\Handler\AbstractHandler
 $level = Logger::DEBUG
 
 $bubble = true
 
 $formatter
 
 $processors = array()
 

Additional Inherited Members

- Protected Member Functions inherited from Monolog\Handler\AbstractHandler
 getDefaultFormatter ()
 Gets the default formatter. More...
 

Detailed Description

Buffers all records until closing the handler and then pass them as batch.

This is useful for a MailHandler to send only one mail per request instead of sending one per log message.

Author
Christophe Coevoet stof@.nosp@m.notk.nosp@m..org

Definition at line 24 of file BufferHandler.php.

Constructor & Destructor Documentation

◆ __construct()

Monolog\Handler\BufferHandler::__construct ( HandlerInterface  $handler,
  $bufferLimit = 0,
  $level = Logger::DEBUG,
  $bubble = true,
  $flushOnOverflow = false 
)
Parameters
HandlerInterface$handlerHandler.
int$bufferLimitHow many entries should be buffered at most, beyond that the oldest items are removed from the buffer.
int$levelThe minimum logging level at which this handler will be triggered
Boolean$bubbleWhether the messages that are handled can bubble up the stack or not
Boolean$flushOnOverflowIf true, the buffer is flushed when the max size has been reached, by default oldest entries are discarded

Definition at line 40 of file BufferHandler.php.

References Monolog\Handler\AbstractHandler\$bubble, Monolog\Handler\BufferHandler\$bufferLimit, Monolog\Handler\BufferHandler\$flushOnOverflow, Monolog\Handler\BufferHandler\$handler, and Monolog\Handler\AbstractHandler\$level.

41  {
42  parent::__construct($level, $bubble);
43  $this->handler = $handler;
44  $this->bufferLimit = (int) $bufferLimit;
45  $this->flushOnOverflow = $flushOnOverflow;
46  }

◆ __destruct()

Monolog\Handler\BufferHandler::__destruct ( )

Definition at line 94 of file BufferHandler.php.

95  {
96  // suppress the parent behavior since we already have register_shutdown_function()
97  // to call close(), and the reference contained there will prevent this from being
98  // GC'd until the end of the request
99  }

Member Function Documentation

◆ clear()

Monolog\Handler\BufferHandler::clear ( )

Clears the buffer without flushing any messages down to the wrapped handler.

Definition at line 112 of file BufferHandler.php.

References array.

Referenced by Monolog\Handler\DeduplicationHandler\flush(), and Monolog\Handler\BufferHandler\flush().

113  {
114  $this->bufferSize = 0;
115  $this->buffer = array();
116  }
Create styles array
The data for the language used.
+ Here is the caller graph for this function:

◆ close()

Monolog\Handler\BufferHandler::close ( )

{}

Definition at line 104 of file BufferHandler.php.

References Monolog\Handler\BufferHandler\flush().

105  {
106  $this->flush();
107  }
+ Here is the call graph for this function:

◆ flush()

Monolog\Handler\BufferHandler::flush ( )

Definition at line 84 of file BufferHandler.php.

References Monolog\Handler\BufferHandler\clear().

Referenced by Monolog\Handler\BufferHandler\close(), and Monolog\Handler\BufferHandler\handle().

85  {
86  if ($this->bufferSize === 0) {
87  return;
88  }
89 
90  $this->handler->handleBatch($this->buffer);
91  $this->clear();
92  }
clear()
Clears the buffer without flushing any messages down to the wrapped handler.
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ handle()

Monolog\Handler\BufferHandler::handle ( array  $record)

{Handles a record.All records may be passed to this method, and the handler should discard those that it does not want to handle.The return value of this function controls the bubbling process of the handler stack. Unless the bubbling is interrupted (by returning true), the Logger class will keep on calling further handlers in the stack with a given log record.

Parameters
array$recordThe record to handle
Returns
Boolean true means that this handler handled the record, and that bubbling is not permitted. false means the record was either not processed or that this handler allows bubbling.
}

Implements Monolog\Handler\HandlerInterface.

Definition at line 51 of file BufferHandler.php.

References Monolog\Handler\AbstractHandler\$bubble, array, and Monolog\Handler\BufferHandler\flush().

52  {
53  if ($record['level'] < $this->level) {
54  return false;
55  }
56 
57  if (!$this->initialized) {
58  // __destructor() doesn't get called on Fatal errors
59  register_shutdown_function(array($this, 'close'));
60  $this->initialized = true;
61  }
62 
63  if ($this->bufferLimit > 0 && $this->bufferSize === $this->bufferLimit) {
64  if ($this->flushOnOverflow) {
65  $this->flush();
66  } else {
67  array_shift($this->buffer);
68  $this->bufferSize--;
69  }
70  }
71 
72  if ($this->processors) {
73  foreach ($this->processors as $processor) {
74  $record = call_user_func($processor, $record);
75  }
76  }
77 
78  $this->buffer[] = $record;
79  $this->bufferSize++;
80 
81  return false === $this->bubble;
82  }
Create styles array
The data for the language used.
+ Here is the call graph for this function:

Field Documentation

◆ $buffer

Monolog\Handler\BufferHandler::$buffer = array()
protected

Definition at line 30 of file BufferHandler.php.

◆ $bufferLimit

Monolog\Handler\BufferHandler::$bufferLimit
protected

Definition at line 28 of file BufferHandler.php.

Referenced by Monolog\Handler\BufferHandler\__construct().

◆ $bufferSize

Monolog\Handler\BufferHandler::$bufferSize = 0
protected

Definition at line 27 of file BufferHandler.php.

◆ $flushOnOverflow

Monolog\Handler\BufferHandler::$flushOnOverflow
protected

Definition at line 29 of file BufferHandler.php.

Referenced by Monolog\Handler\BufferHandler\__construct().

◆ $handler

Monolog\Handler\BufferHandler::$handler
protected

Definition at line 26 of file BufferHandler.php.

Referenced by Monolog\Handler\BufferHandler\__construct().

◆ $initialized

Monolog\Handler\BufferHandler::$initialized = false
protected

Definition at line 31 of file BufferHandler.php.


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