Skip to content

Commit 9250d46

Browse files
ricardclauwouterj
authored andcommitted
some missing formats
1 parent b2a1b38 commit 9250d46

File tree

4 files changed

+283
-63
lines changed

4 files changed

+283
-63
lines changed

cookbook/logging/monolog.rst

Lines changed: 101 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ allows you to log the messages in several ways easily.
5959

6060
.. code-block:: yaml
6161
62+
# app/config/config.yml
6263
monolog:
6364
handlers:
6465
applog:
@@ -75,8 +76,10 @@ allows you to log the messages in several ways easily.
7576
syslog:
7677
type: syslog
7778
level: error
79+
7880
.. code-block:: xml
7981
82+
<!-- app/config/config.xml -->
8083
<container xmlns="http://symfony.com/schema/dic/services"
8184
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
8285
xmlns:monolog="http://symfony.com/schema/dic/monolog"
@@ -109,6 +112,32 @@ allows you to log the messages in several ways easily.
109112
</monolog:config>
110113
</container>
111114
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+
112141
The above configuration defines a stack of handlers which will be called
113142
in the order where they are defined.
114143

@@ -137,6 +166,7 @@ easily. Your formatter must implement
137166

138167
.. code-block:: yaml
139168
169+
# app/config/config.yml
140170
services:
141171
my_formatter:
142172
class: Monolog\Formatter\JsonFormatter
@@ -149,6 +179,7 @@ easily. Your formatter must implement
149179
150180
.. code-block:: xml
151181
182+
<!-- app/config/config.xml -->
152183
<container xmlns="http://symfony.com/schema/dic/services"
153184
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
154185
xmlns:monolog="http://symfony.com/schema/dic/monolog"
@@ -158,6 +189,7 @@ easily. Your formatter must implement
158189
<services>
159190
<service id="my_formatter" class="Monolog\Formatter\JsonFormatter" />
160191
</services>
192+
161193
<monolog:config>
162194
<monolog:handler
163195
name="file"
@@ -168,6 +200,22 @@ easily. Your formatter must implement
168200
</monolog:config>
169201
</container>
170202
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+
171219
Adding some extra data in the log messages
172220
------------------------------------------
173221

@@ -243,6 +291,59 @@ using a processor.
243291
level: debug
244292
formatter: monolog.formatter.session_request
245293
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+
246347
.. note::
247348

248349
If you use several handlers, you can also register the processor at the

cookbook/logging/monolog_email.rst

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,31 @@ it is broken down.
6161
/>
6262
</monolog:config>
6363
</container>
64+
65+
.. code-block:: php
66+
67+
// app/config/config.php
68+
$container->loadFromExtension('monolog', array(
69+
'handlers' => array(
70+
'mail' => array(
71+
'type' => 'fingers_crossed',
72+
'action_level' => 'critical',
73+
'handler' => 'buffered',
74+
),
75+
'buffered' => array(
76+
'type' => 'buffer',
77+
'handler' => 'swift',
78+
),
79+
'swift' => array(
80+
'type' => 'swift_mailer',
81+
'from_email' => 'error@example.com',
82+
'to_email' => 'error@example.com',
83+
'subject' => 'An Error Occurred!',
84+
'level' => 'debug',
85+
),
86+
),
87+
));
88+
6489
6590
The ``mail`` handler is a ``fingers_crossed`` handler which means that
6691
it is only triggered when the action level, in this case ``critical`` is reached.
@@ -154,6 +179,40 @@ get logged on the server as well as the emails being sent:
154179
</monolog:config>
155180
</container>
156181
182+
.. code-block:: php
183+
184+
// app/config/config.php
185+
$container->loadFromExtension('monolog', array(
186+
'handlers' => array(
187+
'main' => array(
188+
'type' => 'fingers_crossed',
189+
'action_level' => 'critical',
190+
'handler' => 'grouped',
191+
),
192+
'grouped' => array(
193+
'type' => 'group',
194+
'members' => array('streamed', 'buffered'),
195+
),
196+
'streamed' => array(
197+
'type' => 'stream',
198+
'path' => '%kernel.logs_dir%/%kernel.environment%.log',
199+
'level' => 'debug',
200+
),
201+
'buffered' => array(
202+
'type' => 'buffer',
203+
'handler' => 'swift',
204+
),
205+
'swift' => array(
206+
'type' => 'swift_mailer',
207+
'from_email' => 'error@example.com',
208+
'to_email' => 'error@example.com',
209+
'subject' => 'An Error Occurred!',
210+
'level' => 'debug',
211+
),
212+
),
213+
));
214+
215+
157216
This uses the ``group`` handler to send the messages to the two
158217
group members, the ``buffered`` and the ``stream`` handlers. The messages will
159218
now be both written to the log file and emailed.

cookbook/templating/global_variables.rst

Lines changed: 57 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -7,19 +7,45 @@ How to Inject Variables into all Templates (i.e. Global Variables)
77
Sometimes you want a variable to be accessible to all the templates you use.
88
This is possible inside your ``app/config/config.yml`` file:
99

10-
.. code-block:: yaml
10+
.. configuration-block::
1111

12-
# app/config/config.yml
13-
twig:
14-
# ...
15-
globals:
16-
ga_tracking: UA-xxxxx-x
12+
.. code-block:: yaml
13+
14+
# app/config/config.yml
15+
twig:
16+
# ...
17+
globals:
18+
ga_tracking: UA-xxxxx-x
19+
20+
.. code-block:: xml
21+
22+
<!-- app/config/config.xml -->
23+
<twig:config ...>
24+
<!-- ... -->
25+
<twig:global key="ga_tracking">UA-xxxxx-x</twig:global>
26+
</twig:config>
27+
28+
.. code-block:: php
29+
30+
// app/config/config.php
31+
$container->loadFromExtension('twig', array(
32+
...,
33+
'globals' => array(
34+
'ga_tracking' => 'UA-xxxxx-x',
35+
),
36+
));
1737
1838
Now, the variable ``ga_tracking`` is available in all Twig templates:
1939

20-
.. code-block:: html+jinja
40+
.. configuration-block::
41+
42+
.. code-block:: html+jinja
43+
44+
<p>The google tracking code is: {{ ga_tracking }}</p>
2145

22-
<p>The google tracking code is: {{ ga_tracking }} </p>
46+
.. code-block:: html+php
47+
48+
<p>The google tracking code is: <?php echo $ga_tracking; ?></p>
2349

2450
It's that easy! You can also take advantage of the built-in :ref:`book-service-container-parameters`
2551
system, which lets you isolate or reuse the value:
@@ -30,12 +56,30 @@ system, which lets you isolate or reuse the value:
3056
[parameters]
3157
ga_tracking: UA-xxxxx-x
3258
33-
.. code-block:: yaml
59+
.. configuration-block::
60+
61+
.. code-block:: yaml
62+
63+
# app/config/config.yml
64+
twig:
65+
globals:
66+
ga_tracking: "%ga_tracking%"
67+
68+
.. code-block:: xml
69+
70+
<!-- app/config/config.xml -->
71+
<twig:config ...>
72+
<twig:global key="ga_tracking">%ga_tracking%</twig:global>
73+
</twig:config>
74+
75+
.. code-block:: php
3476
35-
# app/config/config.yml
36-
twig:
37-
globals:
38-
ga_tracking: "%ga_tracking%"
77+
// app/config/config.php
78+
$container->loadFromExtension('twig', array(
79+
'globals' => array(
80+
'ga_tracking' => '%ga_tracking%',
81+
),
82+
));
3983
4084
The same variable is available exactly as before.
4185

0 commit comments

Comments
 (0)