@@ -25,18 +25,20 @@ it is broken down.
25
25
# action_level: error
26
26
# excluded_404s:
27
27
# - ^/
28
- handler : buffered
29
- buffered :
30
- type : buffer
28
+ handler : deduplicated
29
+ deduplicated :
30
+ type : deduplication
31
31
handler : swift
32
32
swift :
33
33
type : swift_mailer
34
34
35
35
36
36
# or list of recipients
37
37
38
- subject : An Error Occurred!
38
+ subject : ' An Error Occurred! %%message%% '
39
39
level : debug
40
+ formatter : monolog.formatter.html
41
+ content_type : text/html
40
42
41
43
.. code-block :: xml
42
44
@@ -49,8 +51,9 @@ it is broken down.
49
51
http://symfony.com/schema/dic/monolog http://symfony.com/schema/dic/monolog/monolog-1.0.xsd" >
50
52
51
53
<monolog : config >
52
- <!--
53
- To also log 400 level errors (but not 404's):
54
+ <!--
55
+ 500 errors are logged at the critical level,
56
+ to also log 400 level errors (but not 404's):
54
57
action-level="error"
55
58
And add this child inside this monolog:handler
56
59
<monolog:excluded-404>^/</monolog:excluded-404>
@@ -59,23 +62,25 @@ it is broken down.
59
62
name =" mail"
60
63
type =" fingers_crossed"
61
64
action-level =" critical"
62
- handler =" buffered "
65
+ handler =" deduplicated "
63
66
/>
64
67
<monolog : handler
65
- name =" buffered "
66
- type =" buffer "
68
+ name =" deduplicated "
69
+ type =" deduplication "
67
70
handler =" swift"
68
- / >
71
+ >
69
72
<monolog : handler
70
73
name =" swift"
71
74
type =" swift_mailer"
72
75
73
- subject =" An Error Occurred!"
74
- level =" debug" >
76
+ subject =" An Error Occurred! %%message%%"
77
+ level =" debug"
78
+ formatter =" monolog.formatter.html"
79
+ content-type =" text/html" >
75
80
76
81
<monolog : to-email >[email protected] </monolog : to-email >
77
82
78
- <!-- or multiple to-email elements -->
83
+ <!-- or list of recipients -->
79
84
<!--
80
85
<monolog:to-email>[email protected] </monolog:to-email>
81
86
<monolog:to-email>[email protected] </monolog:to-email>
@@ -92,26 +97,29 @@ it is broken down.
92
97
'handlers' => array(
93
98
'mail' => array(
94
99
'type' => 'fingers_crossed',
100
+ // 500 errors are logged at the critical level
95
101
'action_level' => 'critical',
96
102
// to also log 400 level errors (but not 404's):
97
103
// 'action_level' => 'error',
98
104
// 'excluded_404s' => array(
99
105
// '^/',
100
106
// ),
101
- 'handler' => 'buffered ',
107
+ 'handler' => 'deduplicated ',
102
108
),
103
- 'buffered ' => array(
104
- 'type' => 'buffer ',
109
+ 'deduplicated ' => array(
110
+ 'type' => 'deduplication ',
105
111
'handler' => 'swift',
106
112
),
107
113
'swift' => array(
108
- 'type' => 'swift_mailer',
109
- 'from_email' => '[email protected] ',
110
- 'to_email' => '[email protected] ',
114
+ 'type' => 'swift_mailer',
115
+ 'from_email' => '[email protected] ',
116
+ 'to_email' => '[email protected] ',
111
117
// or a list of recipients
112
118
// 'to_email' => array('[email protected] ', '[email protected] ', ...),
113
- 'subject' => 'An Error Occurred!',
114
- 'level' => 'debug',
119
+ 'subject' => 'An Error Occurred! %%message%%',
120
+ 'level' => 'debug',
121
+ 'formatter' => 'monolog.formatter.html',
122
+ 'content_type' => 'text/html',
115
123
),
116
124
),
117
125
));
@@ -121,20 +129,24 @@ it is only triggered when the action level, in this case ``critical`` is reached
121
129
The ``critical `` level is only triggered for 5xx HTTP code errors. If this level
122
130
is reached once, the ``fingers_crossed `` handler will log all messages
123
131
regardless of their level. The ``handler `` setting means that the output
124
- is then passed onto the ``buffered `` handler.
132
+ is then passed onto the ``deduplicated `` handler.
125
133
126
134
.. tip ::
127
135
128
136
If you want both 400 level and 500 level errors to trigger an email,
129
137
set the ``action_level `` to ``error `` instead of ``critical ``. See the
130
138
code above for an example.
131
139
132
- The ``buffered `` handler simply keeps all the messages for a request and
133
- then passes them onto the nested handler in one go. If you do not use this
134
- handler then each message will be emailed separately. This is then passed
135
- to the ``swift `` handler. This is the handler that actually deals with
136
- emailing you the error. The settings for this are straightforward, the
137
- to and from addresses and the subject.
140
+ The ``deduplicated `` handler simply keeps all the messages for a request and
141
+ then passes them onto the nested handler in one go, but only if the records are
142
+ unique over a given period of time (60 seconds by default). If the records are
143
+ duplicates they are simply discarded. Adding this handler reduces the amount of
144
+ notifications to a manageable level, specially in critical failure scenarios.
145
+
146
+ The messages are then passed to the ``swift `` handler. This is the handler that
147
+ actually deals with emailing you the error. The settings for this are
148
+ straightforward, the to and from addresses, the formatter, the content type
149
+ and the subject.
138
150
139
151
You can combine these handlers with other handlers so that the errors still
140
152
get logged on the server as well as the emails being sent:
@@ -152,20 +164,22 @@ get logged on the server as well as the emails being sent:
152
164
handler : grouped
153
165
grouped :
154
166
type : group
155
- members : [streamed, buffered ]
167
+ members : [streamed, deduplicated ]
156
168
streamed :
157
169
type : stream
158
170
path : ' %kernel.logs_dir%/%kernel.environment%.log'
159
171
level : debug
160
- buffered :
161
- type : buffer
172
+ deduplicated :
173
+ type : deduplication
162
174
handler : swift
163
175
swift :
164
176
type : swift_mailer
165
177
166
178
167
- subject : An Error Occurred!
179
+ subject : ' An Error Occurred! %%message%% '
168
180
level : debug
181
+ formatter : monolog.formatter.html
182
+ content_type : text/html
169
183
170
184
.. code-block :: xml
171
185
@@ -188,25 +202,36 @@ get logged on the server as well as the emails being sent:
188
202
type =" group"
189
203
>
190
204
<member type =" stream" />
191
- <member type =" buffered " />
205
+ <member type =" deduplicated " />
192
206
</monolog : handler >
193
207
<monolog : handler
194
208
name =" stream"
195
209
path =" %kernel.logs_dir%/%kernel.environment%.log"
196
210
level =" debug"
197
211
/>
198
212
<monolog : handler
199
- name =" buffered "
200
- type =" buffer "
213
+ name =" deduplicated "
214
+ type =" deduplication "
201
215
handler =" swift"
202
216
/>
203
217
<monolog : handler
204
218
name =" swift"
219
+ type =" swift_mailer"
205
220
206
-
207
- subject =" An Error Occurred!"
221
+ subject =" An Error Occurred! %%message%%"
208
222
level =" debug"
209
- />
223
+ formatter =" monolog.formatter.html"
224
+ content-type =" text/html" >
225
+
226
+ <monolog : to-email >[email protected] </monolog : to-email >
227
+
228
+ <!-- or list of recipients -->
229
+ <!--
230
+ <monolog:to-email>[email protected] </monolog:to-email>
231
+ <monolog:to-email>[email protected] </monolog:to-email>
232
+ ...
233
+ -->
234
+ </monolog : handler >
210
235
</monolog : config >
211
236
</container >
212
237
@@ -222,29 +247,33 @@ get logged on the server as well as the emails being sent:
222
247
),
223
248
'grouped' => array(
224
249
'type' => 'group',
225
- 'members' => array('streamed', 'buffered '),
250
+ 'members' => array('streamed', 'deduplicated '),
226
251
),
227
252
'streamed' => array(
228
253
'type' => 'stream',
229
254
'path' => '%kernel.logs_dir%/%kernel.environment%.log',
230
255
'level' => 'debug',
231
256
),
232
- 'buffered' => array(
233
- 'type' => 'buffer ',
234
- 'handler' => 'swift',
257
+ 'deduplicated' => array(
258
+ 'type' => 'deduplication ',
259
+ 'handler' => 'swift',
235
260
),
236
261
'swift' => array(
237
- 'type' => 'swift_mailer',
238
- 'from_email' => '[email protected] ',
239
- 'to_email' => '[email protected] ',
240
- 'subject' => 'An Error Occurred!',
241
- 'level' => 'debug',
262
+ 'type' => 'swift_mailer',
263
+ 'from_email' => '[email protected] ',
264
+ 'to_email' => '[email protected] ',
265
+ // or a list of recipients
266
+ // 'to_email' => array('[email protected] ', '[email protected] ', ...),
267
+ 'subject' => 'An Error Occurred! %%message%%',
268
+ 'level' => 'debug',
269
+ 'formatter' => 'monolog.formatter.html',
270
+ 'content_type' => 'text/html',
242
271
),
243
272
),
244
273
));
245
274
246
275
This uses the ``group `` handler to send the messages to the two
247
- group members, the ``buffered `` and the ``stream `` handlers. The messages will
276
+ group members, the ``deduplicated `` and the ``stream `` handlers. The messages will
248
277
now be both written to the log file and emailed.
249
278
250
279
.. _Monolog : https://github.com/Seldaek/monolog
0 commit comments