Skip to content

Commit 57702b8

Browse files
committed
Merge branch '4.4'
* 4.4: [Monolog] Added documentation about ElasticsearchLogstashHandler
2 parents de2a554 + c091d99 commit 57702b8

File tree

2 files changed

+108
-0
lines changed

2 files changed

+108
-0
lines changed

logging.rst

+1
Original file line numberDiff line numberDiff line change
@@ -366,6 +366,7 @@ Learn more
366366
logging/channels_handlers
367367
logging/formatter
368368
logging/processors
369+
logging/handlers
369370
logging/monolog_exclude_http_codes
370371
logging/monolog_console
371372

logging/handlers.rst

+107
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,107 @@
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+
.. configuration-block::
26+
27+
.. code-block:: yaml
28+
29+
# config/services.yaml
30+
services:
31+
Symfony\Bridge\Monolog\Handler\ElasticsearchLogstashHandler: ~
32+
33+
.. code-block:: xml
34+
35+
<!-- config/services.xml -->
36+
<?xml version="1.0" encoding="UTF-8" ?>
37+
<container xmlns="http://symfony.com/schema/dic/services"
38+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
39+
xmlns:monolog="http://symfony.com/schema/dic/monolog"
40+
xsi:schemaLocation="http://symfony.com/schema/dic/services
41+
https://symfony.com/schema/dic/services/services-1.0.xsd
42+
http://symfony.com/schema/dic/monolog
43+
https://symfony.com/schema/dic/monolog/monolog-1.0.xsd">
44+
45+
<services>
46+
<service id="Symfony\Bridge\Monolog\Handler\ElasticsearchLogstashHandler"/>
47+
</services>
48+
</container>
49+
50+
.. code-block:: php
51+
52+
// config/services.php
53+
use App\Logger\SessionRequestProcessor;
54+
use Monolog\Formatter\LineFormatter;
55+
use Symfony\Bridge\Monolog\Handler\ElasticsearchLogstashHandler;
56+
57+
$container->register(ElasticsearchLogstashHandler::class);
58+
59+
Then reference it in the Monolog configuration:
60+
61+
.. configuration-block::
62+
63+
.. code-block:: yaml
64+
65+
# config/packages/prod/monolog.yaml
66+
monolog:
67+
handlers:
68+
es:
69+
type: service
70+
id: Symfony\Bridge\Monolog\Handler\ElasticsearchLogstashHandler
71+
72+
.. code-block:: xml
73+
74+
<!-- config/packages/prod/monolog.xml -->
75+
<?xml version="1.0" encoding="UTF-8" ?>
76+
<container xmlns="http://symfony.com/schema/dic/services"
77+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
78+
xmlns:monolog="http://symfony.com/schema/dic/monolog"
79+
xsi:schemaLocation="http://symfony.com/schema/dic/services
80+
https://symfony.com/schema/dic/services/services-1.0.xsd
81+
http://symfony.com/schema/dic/monolog
82+
https://symfony.com/schema/dic/monolog/monolog-1.0.xsd">
83+
84+
<monolog:config>
85+
<monolog:handler
86+
name="es"
87+
type="service"
88+
id="Symfony\Bridge\Monolog\Handler\ElasticsearchLogstashHandler"
89+
/>
90+
</monolog:config>
91+
</container>
92+
93+
.. code-block:: php
94+
95+
// config/packages/prod/monolog.php
96+
use Symfony\Bridge\Monolog\Handler\ElasticsearchLogstashHandler;
97+
98+
$container->loadFromExtension('monolog', [
99+
'handlers' => [
100+
'es' => [
101+
'type' => 'service',
102+
'id' => ElasticsearchLogstashHandler::class,
103+
],
104+
],
105+
]);
106+
107+
.. _`ELK stack`: https://www.elastic.co/what-is/elk-stack

0 commit comments

Comments
 (0)