ILIAS  release_5-2 Revision v5.2.25-18-g3f80b828510
Monolog\Handler\ElasticSearchHandler Class Reference

Elastic Search handler. More...

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

Public Member Functions

 __construct (Client $client, array $options=array(), $level=Logger::DEBUG, $bubble=true)
 
 setFormatter (FormatterInterface $formatter)
 {Sets the formatter.
Parameters
FormatterInterface$formatter
Returns
self
} More...
 
 getOptions ()
 Getter options. More...
 
 handleBatch (array $records)
 {Handles a set of records at once.
Parameters
array$recordsThe records to handle (an array of record arrays)
} More...
 
- Public Member Functions inherited from Monolog\Handler\AbstractProcessingHandler
 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...
 
- 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 Member Functions

 write (array $record)
 
 getDefaultFormatter ()
 
 bulkSend (array $documents)
 Use Elasticsearch bulk API to send list of documents. More...
 
- Protected Member Functions inherited from Monolog\Handler\AbstractProcessingHandler
 write (array $record)
 Writes the record down to the log of the implementing handler. More...
 
 processRecord (array $record)
 Processes a record. More...
 
- Protected Member Functions inherited from Monolog\Handler\AbstractHandler
 getDefaultFormatter ()
 Gets the default formatter. More...
 

Protected Attributes

 $client
 
 $options = array()
 
- Protected Attributes inherited from Monolog\Handler\AbstractHandler
 $level = Logger::DEBUG
 
 $bubble = true
 
 $formatter
 
 $processors = array()
 

Detailed Description

Elastic Search handler.

Usage example:

$client = new (); $options = array( 'index' => 'elastic_index_name', 'type' => 'elastic_doc_type', ); $handler = new ElasticSearchHandler($client, $options); $log = new Logger('application'); $log->pushHandler($handler);

Author
Jelle Vink jelle.nosp@m..vin.nosp@m.k@gma.nosp@m.il.c.nosp@m.om

Definition at line 36 of file ElasticSearchHandler.php.

Constructor & Destructor Documentation

◆ __construct()

Monolog\Handler\ElasticSearchHandler::__construct ( Client  $client,
array  $options = array(),
  $level = Logger::DEBUG,
  $bubble = true 
)
Parameters
Client$clientElastica Client object
array$optionsHandler configuration
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

Definition at line 54 of file ElasticSearchHandler.php.

References Monolog\Handler\AbstractHandler\$bubble, Monolog\Handler\ElasticSearchHandler\$client, Monolog\Handler\AbstractHandler\$level, Monolog\Handler\ElasticSearchHandler\$options, and array.

55  {
56  parent::__construct($level, $bubble);
57  $this->client = $client;
58  $this->options = array_merge(
59  array(
60  'index' => 'monolog', // Elastic index name
61  'type' => 'record', // Elastic document type
62  'ignore_error' => false, // Suppress Elastica exceptions
63  ),
64  $options
65  );
66  }
Create styles array
The data for the language used.

Member Function Documentation

◆ bulkSend()

Monolog\Handler\ElasticSearchHandler::bulkSend ( array  $documents)
protected

Use Elasticsearch bulk API to send list of documents.

Parameters
array$documents
Exceptions

Definition at line 118 of file ElasticSearchHandler.php.

Referenced by Monolog\Handler\ElasticSearchHandler\handleBatch(), and Monolog\Handler\ElasticSearchHandler\write().

119  {
120  try {
121  $this->client->addDocuments($documents);
122  } catch (ExceptionInterface $e) {
123  if (!$this->options['ignore_error']) {
124  throw new \RuntimeException("Error sending messages to Elasticsearch", 0, $e);
125  }
126  }
127  }
+ Here is the caller graph for this function:

◆ getDefaultFormatter()

Monolog\Handler\ElasticSearchHandler::getDefaultFormatter ( )
protected

Definition at line 99 of file ElasticSearchHandler.php.

100  {
101  return new ElasticaFormatter($this->options['index'], $this->options['type']);
102  }

◆ getOptions()

Monolog\Handler\ElasticSearchHandler::getOptions ( )

Getter options.

Returns
array

Definition at line 91 of file ElasticSearchHandler.php.

References Monolog\Handler\ElasticSearchHandler\$options.

◆ handleBatch()

Monolog\Handler\ElasticSearchHandler::handleBatch ( array  $records)

{Handles a set of records at once.

Parameters
array$recordsThe records to handle (an array of record arrays)
}

Implements Monolog\Handler\HandlerInterface.

Definition at line 107 of file ElasticSearchHandler.php.

References Monolog\Handler\ElasticSearchHandler\bulkSend(), and Monolog\Handler\AbstractHandler\getFormatter().

108  {
109  $documents = $this->getFormatter()->formatBatch($records);
110  $this->bulkSend($documents);
111  }
bulkSend(array $documents)
Use Elasticsearch bulk API to send list of documents.
$records
Definition: simple_test.php:22
getFormatter()
{Gets the formatter.FormatterInterface}
+ Here is the call graph for this function:

◆ setFormatter()

Monolog\Handler\ElasticSearchHandler::setFormatter ( FormatterInterface  $formatter)

{Sets the formatter.

Parameters
FormatterInterface$formatter
Returns
self
}

Implements Monolog\Handler\HandlerInterface.

Definition at line 79 of file ElasticSearchHandler.php.

80  {
81  if ($formatter instanceof ElasticaFormatter) {
82  return parent::setFormatter($formatter);
83  }
84  throw new \InvalidArgumentException('ElasticSearchHandler is only compatible with ElasticaFormatter');
85  }

◆ write()

Monolog\Handler\ElasticSearchHandler::write ( array  $record)
protected

Definition at line 71 of file ElasticSearchHandler.php.

References array, and Monolog\Handler\ElasticSearchHandler\bulkSend().

72  {
73  $this->bulkSend(array($record['formatted']));
74  }
bulkSend(array $documents)
Use Elasticsearch bulk API to send list of documents.
Create styles array
The data for the language used.
+ Here is the call graph for this function:

Field Documentation

◆ $client

Monolog\Handler\ElasticSearchHandler::$client
protected

◆ $options

Monolog\Handler\ElasticSearchHandler::$options = array()
protected

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