@@ -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 ::
@@ -83,7 +75,10 @@ To use it, declare it as a service:
83
75
])
84
76
;
85
77
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:
87
82
88
83
.. configuration-block ::
89
84
@@ -130,4 +125,69 @@ Then reference it in the Monolog configuration:
130
125
;
131
126
};
132
127
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
133
192
.. _`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