Skip to content

Commit 446d6e5

Browse files
committed
Merge branch '5.4' into 6.2
* 5.4: docs(logging): add placeholders for dynamic data
2 parents 0c44766 + 1c33f40 commit 446d6e5

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed

logging.rst

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff 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+
4357
The ``logger`` service has different methods for different logging levels/priorities.
4458
See `LoggerInterface`_ for a list of all of the methods on the logger.
4559

0 commit comments

Comments
 (0)