Skip to content

[Logger] Update ElasticsearchLogstashHandler documentation #19417

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
78 changes: 69 additions & 9 deletions logging/handlers.rst
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,6 @@ This handler deals directly with the HTTP interface of Elasticsearch. This means
it will slow down your application if Elasticsearch takes time to answer. Even
if all HTTP calls are done asynchronously.

In a development environment, it's fine to keep the default configuration: for
each log, an HTTP request will be made to push the log to Elasticsearch.

In a production environment, it's highly recommended to wrap this handler in a
handler with buffering capabilities (like the ``FingersCrossedHandler`` or
``BufferHandler``) in order to call Elasticsearch only once with a bulk push. For
even better performance and fault tolerance, a proper `ELK stack`_ is recommended.

To use it, declare it as a service:

.. configuration-block::
Expand Down Expand Up @@ -87,7 +79,10 @@ To use it, declare it as a service:

The ``$elasticsearchVersion`` argument was introduced in Symfony 5.4.

Then reference it in the Monolog configuration:
Then reference it in the Monolog configuration.

In a development environment, it's fine to keep the default configuration: for
each log, an HTTP request will be made to push the log to Elasticsearch:

.. configuration-block::

Expand Down Expand Up @@ -134,4 +129,69 @@ Then reference it in the Monolog configuration:
;
};

In a production environment, it's highly recommended to wrap this handler in a
handler with buffering capabilities (like the `FingersCrossedHandler`_ or
`BufferHandler`_) in order to call Elasticsearch only once with a bulk push. For
even better performance and fault tolerance, a proper `ELK stack`_ is recommended.

.. configuration-block::

.. code-block:: yaml

# config/packages/prod/monolog.yaml
monolog:
handlers:
main:
type: fingers_crossed
handler: es

es:
type: service
id: Symfony\Bridge\Monolog\Handler\ElasticsearchLogstashHandler

.. code-block:: xml

<!-- config/packages/prod/monolog.xml -->
<?xml version="1.0" encoding="UTF-8" ?>
<container xmlns="http://symfony.com/schema/dic/services"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:monolog="http://symfony.com/schema/dic/monolog"
xsi:schemaLocation="http://symfony.com/schema/dic/services
https://symfony.com/schema/dic/services/services-1.0.xsd
http://symfony.com/schema/dic/monolog
https://symfony.com/schema/dic/monolog/monolog-1.0.xsd">

<monolog:config>
<monolog:handler
name="main"
type="fingers_crossed"
handler="es"
/>
<monolog:handler
name="es"
type="service"
id="Symfony\Bridge\Monolog\Handler\ElasticsearchLogstashHandler"
/>
</monolog:config>
</container>

.. code-block:: php

// config/packages/prod/monolog.php
use Symfony\Bridge\Monolog\Handler\ElasticsearchLogstashHandler;
use Symfony\Config\MonologConfig;

return static function (MonologConfig $monolog): void {
$monolog->handler('main')
->type('fingers_crossed')
->handler('es')
;
$monolog->handler('es')
->type('service')
->id(ElasticsearchLogstashHandler::class)
;
};

.. _`BufferHandler`: https://github.com/Seldaek/monolog/blob/main/src/Monolog/Handler/BufferHandler.php
.. _`ELK stack`: https://www.elastic.co/what-is/elk-stack
.. _`FingersCrossedHandler`: https://github.com/Seldaek/monolog/blob/main/src/Monolog/Handler/FingersCrossedHandler.php