Proposal - encourage use of PSR-3 log placeholders when logging variable values with Civi::log()
Reference: Link to docs about PSR-3 placeholders
Currently Civi::log() is implemented by CRM_Core_Error_Log which is a minimal implementation of PSR-3 logging. Currently to represent non-string variable values in log messages you either need to flatten them to a string first, or, you can pass them in the $context parameter, but that whole array just gets print_r'd and any intended use of placeholders in the actual message string is ignored and the placeholder word is output literally. It's useful, just doesn't encourage the use of placeholders, which are desired so that other log implementations can reformat the values as they see fit. It's desirable for string variable values too - implementations can choose to just insert inline into the output in place of the placeholder, or not. And if it wants it could choose to do that just for strings, and only reformat non-string objects separately.
There aren't that many calls to Civi::log yet in core, so it might not be a huge task. Or at least going forward encourage the use of placeholders for variables, and clean up existing usage as it comes up.
By placeholders I mean something like:
Civi::log()->error('Hello {name}, how are you today?', ['name' => $username]);
instead of
Civi::log()->error("Hello $username, how are you today?");
Also think about how any core implementation affects drupal watchdog, which also is slightly different in drupal 7 vs 8. See also https://github.com/civicrm/civicrm-core/pull/18864#issuecomment-722199365
Related to that, most other languages' logging frameworks have a queue of log listeners, so that you can log to multiple targets at once. I'm not sure if it's just because this is all a retrofit to existing civi code or if I just haven't figured out how to do it, but it seems like you can only have one log listener at a time? The drupal watchdog part is hardcoded in debug_log_message().