Skip to content

Commit d2ae20d

Browse files
committed
minor #12201 [Monolog] Added documentation about ElasticsearchLogstashHandler (lyrixx)
This PR was merged into the 4.4 branch. Discussion ---------- [Monolog] Added documentation about ElasticsearchLogstashHandler Fixes #12198 Commits ------- 0842526 [Monolog] Added documentation about ElasticsearchLogstashHandler
2 parents f420298 + 0842526 commit d2ae20d

File tree

2 files changed

+109
-0
lines changed

2 files changed

+109
-0
lines changed

logging.rst

+1
Original file line numberDiff line numberDiff line change
@@ -371,6 +371,7 @@ Learn more
371371
logging/channels_handlers
372372
logging/formatter
373373
logging/processors
374+
logging/handlers
374375
logging/monolog_exclude_http_codes
375376
logging/monolog_console
376377

logging/handlers.rst

+108
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,108 @@
1+
Handlers
2+
========
3+
4+
ElasticsearchLogstashHandler
5+
----------------------------
6+
7+
.. versionadded:: 4.4
8+
9+
The ``ElasticsearchLogstashHandler`` was introduced in Symfony 4.4.
10+
11+
This handler deals directly with the HTTP interface of Elasticsearch. This means
12+
it will slow down your application if Elasticsearch takes times to answer. Even
13+
if all HTTP calls are done asynchronously.
14+
15+
In a development environment, it's fine to keep the default configuration: for
16+
each log, an HTTP request will be made to push the log to Elasticsearch.
17+
18+
In a production environment, it's highly recommended to wrap this handler in a
19+
handler with buffering capabilities (like the ``FingersCrossedHandler`` or
20+
``BufferHandler``) in order to call Elasticsearch only once with a bulk push. For
21+
even better performance and fault tolerance, a proper `ELK stack`_ is recommended.
22+
23+
To use it, declare it as a service:
24+
25+
26+
.. configuration-block::
27+
28+
.. code-block:: yaml
29+
30+
# config/services.yaml
31+
services:
32+
Symfony\Bridge\Monolog\Handler\ElasticsearchLogstashHandler: ~
33+
34+
.. code-block:: xml
35+
36+
<!-- config/services.xml -->
37+
<?xml version="1.0" encoding="UTF-8" ?>
38+
<container xmlns="http://symfony.com/schema/dic/services"
39+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
40+
xmlns:monolog="http://symfony.com/schema/dic/monolog"
41+
xsi:schemaLocation="http://symfony.com/schema/dic/services
42+
https://symfony.com/schema/dic/services/services-1.0.xsd
43+
http://symfony.com/schema/dic/monolog
44+
https://symfony.com/schema/dic/monolog/monolog-1.0.xsd">
45+
46+
<services>
47+
<service id="Symfony\Bridge\Monolog\Handler\ElasticsearchLogstashHandler"/>
48+
</services>
49+
</container>
50+
51+
.. code-block:: php
52+
53+
// config/services.php
54+
use App\Logger\SessionRequestProcessor;
55+
use Monolog\Formatter\LineFormatter;
56+
use Symfony\Bridge\Monolog\Handler\ElasticsearchLogstashHandler;
57+
58+
$container->register(ElasticsearchLogstashHandler::class);
59+
60+
Then reference it in monolog configuration:
61+
62+
63+
.. configuration-block::
64+
65+
.. code-block:: yaml
66+
67+
# config/packages/prod/monolog.yaml
68+
monolog:
69+
handlers:
70+
es:
71+
type: service
72+
id: Symfony\Bridge\Monolog\Handler\ElasticsearchLogstashHandler
73+
74+
.. code-block:: xml
75+
76+
<!-- config/packages/prod/monolog.xml -->
77+
<?xml version="1.0" encoding="UTF-8" ?>
78+
<container xmlns="http://symfony.com/schema/dic/services"
79+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
80+
xmlns:monolog="http://symfony.com/schema/dic/monolog"
81+
xsi:schemaLocation="http://symfony.com/schema/dic/services
82+
https://symfony.com/schema/dic/services/services-1.0.xsd
83+
http://symfony.com/schema/dic/monolog
84+
https://symfony.com/schema/dic/monolog/monolog-1.0.xsd">
85+
86+
<monolog:config>
87+
<monolog:handler
88+
name="es"
89+
type="service"
90+
id="Symfony\Bridge\Monolog\Handler\ElasticsearchLogstashHandler"
91+
/>
92+
</monolog:config>
93+
</container>
94+
95+
.. code-block:: php
96+
97+
use Symfony\Bridge\Monolog\Handler\ElasticsearchLogstashHandler;
98+
// config/packages/prod/monolog.php
99+
$container->loadFromExtension('monolog', [
100+
'handlers' => [
101+
'es' => [
102+
'type' => 'service',
103+
'id' => ElasticsearchLogstashHandler::class,
104+
],
105+
],
106+
]);
107+
108+
.. _`ELK stack`: https://www.elastic.co/what-is/elk-stack

0 commit comments

Comments
 (0)