- @berdir opened merge request.
Our setup has heavy logging enabled via \Drupal::logger($channel)->debug($message)
and this appears to be wrapped with Ultimate Cron's LogEntry
.
On line 115, the class takes a variable and passes it through a t()
string which is bad practise:
public function log($message, $variables = array(), $level = RfcLogLevel::NOTICE) {
if ($variables !== NULL && gettype($message) === 'string') {
$message = t($message, $variables);
}
A warning is also emitted:
phpcs: Only string literals should be passed to t() where possible
.
This also causes our locales_source
table flooded with erroneous string translations with tons of variations like the below:
@"response":{"statusCode":200,"headers":{"Cache-Control":{"0":"no-cache, no-store, private, must-revalidate","Content-Type":@"0":"application\/json;charset=utf-8","Date":@"0":"Mon, 05 Jul 2021 14:33:42 GMT","Server":@"0":"Apache-Coyote\/1.1","set-cookie":@"0":"_csrf=0NQxvg51h51-lCghvX3gcMho; Path=\/","Vary":@"0":"Accept-Encoding","X-Application-Context":@"0":"api-gateway:aws,redis:8443","X-Content-Type-Options":@"0":"nosniff","X-Frame-Options":@"0":"DENY","1":"DENY","X-SL-RequestId":@"0":"babdf359-7f2f-475a-80fa-70c40v2a489f","X-XSS-Protection":@"0":"1; mode=block","1":"1; mode=block","Content-Length":@"0":"51","Connection":@"0":"keep-alive"},"body":"@\"response\":{\"code\":\"SUCCESS\",\"data\":{\"items\":[]}}"}}
hook_cron()
t()
It looks like the if clause is needlessly ran through when $variables
is being checked as NULL
where in all cases through my testing has been an empty array.
Changing this to !empty($variables)
gets rid of the problem in my case, and aligned with the executing code block at /src/Logger/WatchdogLogger.php
ahead of the logging at LogMessageParserInterface::parseMessagePlaceholders()
but still suggests maybe for a better alternative on the usage of t()
here.
Agree on a solution, write a patch / MR and review.
N/A
N/A
N/A
Needs review
2.0
Code
The change is currently missing an automated test that fails when run with the original code, and succeeds when the bug has been fixed.
Not all content is available!
It's likely this issue predates Contrib.social: some issue and comment data are missing.