@@ -32,11 +32,8 @@ 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 (wrap the placeholder name with braces)
36
- // these placeholders are useful for logging tools, which can aggregate log messages
37
- // that are the same except for some variable values inside them, for translation
38
- // systems in order to create localized messages, and for security because escaping
39
- // can then be done by the implementation in a context-aware fashion
35
+ // log messages can also contain placeholders, which are variable names
36
+ // wrapped in braces whose values are passed as the second argument
40
37
$logger->debug('User {userId} has logged in', [
41
38
'userId' => $this->getUserId(),
42
39
]);
@@ -49,6 +46,14 @@ To log a message, inject the default logger in your controller or service::
49
46
// ...
50
47
}
51
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
+
52
57
The ``logger `` service has different methods for different logging levels/priorities.
53
58
See `LoggerInterface `_ for a list of all of the methods on the logger.
54
59
0 commit comments