Skip to content

Commit 1f1d6a4

Browse files
committed
minor #19417 [Logger] Update ElasticsearchLogstashHandler documentation (alamirault)
This PR was merged into the 5.4 branch. Discussion ---------- [Logger] Update ElasticsearchLogstashHandler documentation Try fix #19412 1) Add link to Monolog source code for `FingersCrossedHandler` and `BufferHandler` 2) Add an example for production recommendation (Not tested but inspired by https://symfony.com/doc/current/logging.html#handlers-that-modify-log-entries example) Commits ------- 07a9c8b Update ElasticsearchLogstashHandler documentation
2 parents 69aa9e7 + 07a9c8b commit 1f1d6a4

File tree

1 file changed

+69
-9
lines changed

1 file changed

+69
-9
lines changed

logging/handlers.rst

+69-9
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,6 @@ This handler deals directly with the HTTP interface of Elasticsearch. This means
88
it will slow down your application if Elasticsearch takes time to answer. Even
99
if all HTTP calls are done asynchronously.
1010

11-
In a development environment, it's fine to keep the default configuration: for
12-
each log, an HTTP request will be made to push the log to Elasticsearch.
13-
14-
In a production environment, it's highly recommended to wrap this handler in a
15-
handler with buffering capabilities (like the ``FingersCrossedHandler`` or
16-
``BufferHandler``) in order to call Elasticsearch only once with a bulk push. For
17-
even better performance and fault tolerance, a proper `ELK stack`_ is recommended.
18-
1911
To use it, declare it as a service:
2012

2113
.. configuration-block::
@@ -87,7 +79,10 @@ To use it, declare it as a service:
8779

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

90-
Then reference it in the Monolog configuration:
82+
Then reference it in the Monolog configuration.
83+
84+
In a development environment, it's fine to keep the default configuration: for
85+
each log, an HTTP request will be made to push the log to Elasticsearch:
9186

9287
.. configuration-block::
9388

@@ -134,4 +129,69 @@ Then reference it in the Monolog configuration:
134129
;
135130
};
136131
132+
In a production environment, it's highly recommended to wrap this handler in a
133+
handler with buffering capabilities (like the `FingersCrossedHandler`_ or
134+
`BufferHandler`_) in order to call Elasticsearch only once with a bulk push. For
135+
even better performance and fault tolerance, a proper `ELK stack`_ is recommended.
136+
137+
.. configuration-block::
138+
139+
.. code-block:: yaml
140+
141+
# config/packages/prod/monolog.yaml
142+
monolog:
143+
handlers:
144+
main:
145+
type: fingers_crossed
146+
handler: es
147+
148+
es:
149+
type: service
150+
id: Symfony\Bridge\Monolog\Handler\ElasticsearchLogstashHandler
151+
152+
.. code-block:: xml
153+
154+
<!-- config/packages/prod/monolog.xml -->
155+
<?xml version="1.0" encoding="UTF-8" ?>
156+
<container xmlns="http://symfony.com/schema/dic/services"
157+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
158+
xmlns:monolog="http://symfony.com/schema/dic/monolog"
159+
xsi:schemaLocation="http://symfony.com/schema/dic/services
160+
https://symfony.com/schema/dic/services/services-1.0.xsd
161+
http://symfony.com/schema/dic/monolog
162+
https://symfony.com/schema/dic/monolog/monolog-1.0.xsd">
163+
164+
<monolog:config>
165+
<monolog:handler
166+
name="main"
167+
type="fingers_crossed"
168+
handler="es"
169+
/>
170+
<monolog:handler
171+
name="es"
172+
type="service"
173+
id="Symfony\Bridge\Monolog\Handler\ElasticsearchLogstashHandler"
174+
/>
175+
</monolog:config>
176+
</container>
177+
178+
.. code-block:: php
179+
180+
// config/packages/prod/monolog.php
181+
use Symfony\Bridge\Monolog\Handler\ElasticsearchLogstashHandler;
182+
use Symfony\Config\MonologConfig;
183+
184+
return static function (MonologConfig $monolog): void {
185+
$monolog->handler('main')
186+
->type('fingers_crossed')
187+
->handler('es')
188+
;
189+
$monolog->handler('es')
190+
->type('service')
191+
->id(ElasticsearchLogstashHandler::class)
192+
;
193+
};
194+
195+
.. _`BufferHandler`: https://github.com/Seldaek/monolog/blob/main/src/Monolog/Handler/BufferHandler.php
137196
.. _`ELK stack`: https://www.elastic.co/what-is/elk-stack
197+
.. _`FingersCrossedHandler`: https://github.com/Seldaek/monolog/blob/main/src/Monolog/Handler/FingersCrossedHandler.php

0 commit comments

Comments
 (0)