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::
3232 $logger->info('I just got the logger');
3333 $logger->error('An error occurred');
3434
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+
3541 $logger->critical('I left the oven on!', [
3642 // include extra "context" info in your logs
3743 'cause' => 'in_hurry',
@@ -40,6 +46,14 @@ To log a message, inject the default logger in your controller or service::
4046 // ...
4147 }
4248
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+
4357The ``logger `` service has different methods for different logging levels/priorities.
4458See `LoggerInterface `_ for a list of all of the methods on the logger.
4559
You can’t perform that action at this time.
0 commit comments