File tree Expand file tree Collapse file tree 1 file changed +14
-0
lines changed Expand file tree Collapse file tree 1 file changed +14
-0
lines changed Original file line number Diff line number Diff line change @@ -32,6 +32,12 @@ To log a message, inject the default logger in your controller or service::
32
32
$logger->info('I just got the logger');
33
33
$logger->error('An error occurred');
34
34
35
+ // log messages can also contain placeholders, which are variable names
36
+ // wrapped in braces whose values are passed as the second argument
37
+ $logger->debug('User {userId} has logged in', [
38
+ 'userId' => $this->getUserId(),
39
+ ]);
40
+
35
41
$logger->critical('I left the oven on!', [
36
42
// include extra "context" info in your logs
37
43
'cause' => 'in_hurry',
@@ -40,6 +46,14 @@ To log a message, inject the default logger in your controller or service::
40
46
// ...
41
47
}
42
48
49
+ Adding placeholders to log messages is recommended because:
50
+
51
+ * It's easier to check log messages because many logging tools group log messages
52
+ that are the same except for some variable values inside them;
53
+ * It's much easier to translate those log messages;
54
+ * It's better for security, because escaping can then be done by the
55
+ implementation in a context-aware fashion.
56
+
43
57
The ``logger `` service has different methods for different logging levels/priorities.
44
58
See `LoggerInterface `_ for a list of all of the methods on the logger.
45
59
You can’t perform that action at this time.
0 commit comments