Skip to content

Commit ffa7f83

Browse files
committed
[Monolog] Added documentation about ElasticsearchLogstashHandler
1 parent def3df3 commit ffa7f83

File tree

2 files changed

+106
-0
lines changed

2 files changed

+106
-0
lines changed

logging.rst

Lines changed: 1 addition & 0 deletions
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

Lines changed: 105 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,105 @@
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 dials 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
22+
(https://www.elastic.co/what-is/elk-stack) stack is recommended.
23+
24+
To use it, declare it as a service:
25+
26+
27+
.. configuration-block::
28+
29+
.. code-block:: yaml
30+
31+
# config/services.yaml
32+
services:
33+
Symfony\Bridge\Monolog\Handler\ElasticsearchLogstashHandler: ~
34+
35+
.. code-block:: xml
36+
37+
<!-- config/services.xml -->
38+
<?xml version="1.0" encoding="UTF-8" ?>
39+
<container xmlns="http://symfony.com/schema/dic/services"
40+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
41+
xmlns:monolog="http://symfony.com/schema/dic/monolog"
42+
xsi:schemaLocation="http://symfony.com/schema/dic/services
43+
https://symfony.com/schema/dic/services/services-1.0.xsd
44+
http://symfony.com/schema/dic/monolog
45+
https://symfony.com/schema/dic/monolog/monolog-1.0.xsd">
46+
47+
<services>
48+
<service id="Symfony\Bridge\Monolog\Handler\ElasticsearchLogstashHandler" />
49+
</services>
50+
</container>
51+
52+
.. code-block:: php
53+
54+
// config/services.php
55+
use App\Logger\SessionRequestProcessor;
56+
use Monolog\Formatter\LineFormatter;
57+
58+
$container->register('Symfony\\Bridge\\Monolog\\Handler\\ElasticsearchLogstashHandler');
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+
// config/packages/prod/monolog.php
98+
$container->loadFromExtension('monolog', [
99+
'handlers' => [
100+
'es' => [
101+
'type' => 'service',
102+
'id' => 'Symfony\\Bridge\\Monolog\\Handler\\ElasticsearchLogstashHandler',
103+
],
104+
],
105+
]);

0 commit comments

Comments
 (0)