Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 2e2ef98

Browse files
committed
Merge branch '5.4' into 6.3
* 5.4: Update ElasticsearchLogstashHandler documentation
2 parents 7014f03 + 1f1d6a4 commit 2e2ef98

File tree

1 file changed

+69
-9
lines changed

1 file changed

+69
-9
lines changed

logging/handlers.rst

Lines changed: 69 additions & 9 deletions
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::
@@ -83,7 +75,10 @@ To use it, declare it as a service:
8375
])
8476
;
8577
86-
Then reference it in the Monolog configuration:
78+
Then reference it in the Monolog configuration.
79+
80+
In a development environment, it's fine to keep the default configuration: for
81+
each log, an HTTP request will be made to push the log to Elasticsearch:
8782

8883
.. configuration-block::
8984

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

0 commit comments

Comments
 (0)