@@ -59,6 +59,7 @@ allows you to log the messages in several ways easily.
59
59
60
60
.. code-block :: yaml
61
61
62
+ # app/config/config.yml
62
63
monolog :
63
64
handlers :
64
65
applog :
@@ -75,8 +76,10 @@ allows you to log the messages in several ways easily.
75
76
syslog :
76
77
type : syslog
77
78
level : error
79
+
78
80
.. code-block :: xml
79
81
82
+ <!-- app/config/config.xml -->
80
83
<container xmlns =" http://symfony.com/schema/dic/services"
81
84
xmlns : xsi =" http://www.w3.org/2001/XMLSchema-instance"
82
85
xmlns : monolog =" http://symfony.com/schema/dic/monolog"
@@ -109,6 +112,32 @@ allows you to log the messages in several ways easily.
109
112
</monolog : config >
110
113
</container >
111
114
115
+ .. code-block :: php
116
+
117
+ // app/config/config.php
118
+ $container->loadFromExtension('monolog', array(
119
+ 'handlers' => array(
120
+ 'applog' => array(
121
+ 'type' => 'stream',
122
+ 'path' => '/var/log/symfony.log',
123
+ 'level' => 'error',
124
+ ),
125
+ 'main' => array(
126
+ 'type' => 'fingers_crossed',
127
+ 'action_level' => 'warning',
128
+ 'handler' => 'file',
129
+ ),
130
+ 'file' => array(
131
+ 'type' => 'stream',
132
+ 'level' => 'debug',
133
+ ),
134
+ 'syslog' => array(
135
+ 'type' => 'syslog',
136
+ 'level' => 'error',
137
+ ),
138
+ ),
139
+ ));
140
+
112
141
The above configuration defines a stack of handlers which will be called
113
142
in the order where they are defined.
114
143
@@ -137,6 +166,7 @@ easily. Your formatter must implement
137
166
138
167
.. code-block :: yaml
139
168
169
+ # app/config/config.yml
140
170
services :
141
171
my_formatter :
142
172
class : Monolog\Formatter\JsonFormatter
@@ -149,6 +179,7 @@ easily. Your formatter must implement
149
179
150
180
.. code-block :: xml
151
181
182
+ <!-- app/config/config.xml -->
152
183
<container xmlns =" http://symfony.com/schema/dic/services"
153
184
xmlns : xsi =" http://www.w3.org/2001/XMLSchema-instance"
154
185
xmlns : monolog =" http://symfony.com/schema/dic/monolog"
@@ -158,6 +189,7 @@ easily. Your formatter must implement
158
189
<services >
159
190
<service id =" my_formatter" class =" Monolog\Formatter\JsonFormatter" />
160
191
</services >
192
+
161
193
<monolog : config >
162
194
<monolog : handler
163
195
name =" file"
@@ -168,6 +200,22 @@ easily. Your formatter must implement
168
200
</monolog : config >
169
201
</container >
170
202
203
+ .. code-block :: php
204
+
205
+ // app/config/config.php
206
+ $container
207
+ ->register('my_formatter', 'Monolog\Formatter\JsonFormatter');
208
+
209
+ $container->loadFromExtension('monolog', array(
210
+ 'handlers' => array(
211
+ 'file' => array(
212
+ 'type' => 'stream',
213
+ 'level' => 'debug',
214
+ 'formatter' => 'my_formatter',
215
+ ),
216
+ ),
217
+ ));
218
+
171
219
Adding some extra data in the log messages
172
220
------------------------------------------
173
221
@@ -243,6 +291,59 @@ using a processor.
243
291
level : debug
244
292
formatter : monolog.formatter.session_request
245
293
294
+ .. code-block :: xml
295
+
296
+ <container xmlns =" http://symfony.com/schema/dic/services"
297
+ xmlns : xsi =" http://www.w3.org/2001/XMLSchema-instance"
298
+ xmlns : monolog =" http://symfony.com/schema/dic/monolog"
299
+ xsi : schemaLocation =" http://symfony.com/schema/dic/services http://symfony.com/schema/dic/services/services-1.0.xsd
300
+ http://symfony.com/schema/dic/monolog http://symfony.com/schema/dic/monolog/monolog-1.0.xsd" >
301
+
302
+ <services >
303
+ <service id =" monolog.formatter.session_request" class =" Monolog\Formatter\LineFormatter" >
304
+ <argument >[%%datetime%%] [%%extra.token%%] %%channel%%.%%level_name%%: %%message%%\n</argument >
305
+ </service >
306
+
307
+ <service id =" monolog.processor.session_request" class =" Acme\MyBundle\SessionRequestProcessor" >
308
+ <argument type =" service" id =" session" />
309
+ <tag name =" monolog.processor" method =" processRecord" />
310
+ </service >
311
+ </services >
312
+
313
+ <monolog : config >
314
+ <monolog : handler
315
+ name =" main"
316
+ type =" stream"
317
+ path =" %kernel.logs_dir%/%kernel.environment%.log"
318
+ level =" debug"
319
+ formatter =" monolog.formatter.session_request"
320
+ />
321
+ </monolog : config >
322
+ </container >
323
+
324
+ .. code-block :: php
325
+
326
+ // app/config/config.php
327
+ $container
328
+ ->register('monolog.formatter.session_request', 'Monolog\Formatter\LineFormatter')
329
+ ->addArgument('[%%datetime%%] [%%extra.token%%] %%channel%%.%%level_name%%: %%message%%\n');
330
+
331
+ $container
332
+ ->register('monolog.processor.session_request', 'Acme\MyBundle\SessionRequestProcessor')
333
+ ->addArgument(new Reference('session'))
334
+ ->addTag('monolog.processor', array('method' => 'processRecord'));
335
+
336
+ $container->loadFromExtension('monolog', array(
337
+ 'handlers' => array(
338
+ 'main' => array(
339
+ 'type' => 'stream',
340
+ 'path' => '%kernel.logs_dir%/%kernel.environment%.log',
341
+ 'level' => 'debug',
342
+ 'formatter' => 'monolog.formatter.session_request',
343
+ ),
344
+ ),
345
+ ));
346
+
246
347
.. note ::
247
348
248
349
If you use several handlers, you can also register the processor at the
0 commit comments