@@ -8,14 +8,6 @@ This handler deals directly with the HTTP interface of Elasticsearch. This means
8
8
it will slow down your application if Elasticsearch takes time to answer. Even
9
9
if all HTTP calls are done asynchronously.
10
10
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
-
19
11
To use it, declare it as a service:
20
12
21
13
.. configuration-block ::
@@ -87,7 +79,10 @@ To use it, declare it as a service:
87
79
88
80
The ``$elasticsearchVersion `` argument was introduced in Symfony 5.4.
89
81
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:
91
86
92
87
.. configuration-block ::
93
88
@@ -134,4 +129,69 @@ Then reference it in the Monolog configuration:
134
129
;
135
130
};
136
131
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
137
196
.. _`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