Since D8 introduced PSR-3 logging, our logging system supports both legacy-style placeholders prefixed by "@", "!", or "%", and the standard single-brace wrapped placeholders. PSR-3 placeholders are converted to legacy style in LogMessageParser::parseMessagePlaceholders().
However, the conversion being performed is not entirely correct, as it prevents messages containing braces beyond the placeholders from being kept, because the transformation is too eager. Case in point: logging information about a route error like:
$logger->error('Incorrect parameter {{foo}} in path {path}: {value}', ['foo' => 'bar', 'path' => '/baz', 'value' => 'quux']);
- Expected result: "Incorrect parameter {bar} in path /baz: quux"
- Actual result: "Incorrect parameter @{foo} in path /baz: quux
Assigned to dblog since the core component list does not include the logger component.
Comments
Comment #2
fgmPatch seems to work on manual tests. Checking with the whole test suite.
Comment #4
fgmSeems to be a random test bot fluke: the fail does not appear to have anything to do with the patch.
Comment #5
dagmarIt seems this changes are unintended. And probably the cause of the test failure.
Comment #6
fgmOh, you're right, of course, thanks. Rerolled.
Comment #7
googletorp commentedAdded test case to patch from #6 and a test only patch.
Comment #8
googletorp commentedComment #9
fgmNice to have a test for dblog. However, the issue is more generic, since it is in the logger component, not in dblog itself. It would be even nicer to add a more generic test using a test logger backend so that this handling would be more generic.
Comment #11
dagmarThere is an intent of make a generic logger here: #2862282: Add a test logger channel for test base classes to use. In order to have a unified interface with at least dblog, I proposed to finish first #2458191: Provide a storage backend for dblog module
This docs seems duplicated, and does not illustrate the idea behind this test.
Comment #12
fgmFWIW, the MongoDB Logger/Watchdog, at least in D7 includes actual unit tests mocking the actual connection. We could have the same here, I suspect.
Comment #13
googletorp commentedSo I
- Added test for LogMessageParser service.
- Fixed the copy/paste comment in the new DBLog test
Uploadet, patch, test only patch and interdiff.
You could argue that DbLog test is not strictly needed, since we have a test in the parser class. Since we did write the code and the DbLog was were the bug surfaced, I think that it makes sense to keep the test to verify that the change fixed the issue.
Comment #15
googletorp commentedUpdating status back to NR - seems like test failed due to some database issues on test machine.
Comment #16
googletorp commentedComment #17
googletorp commentedComment #18
dagmarThis comment now also includes twigs placeholders.
If we are going to test this. I would like to see also all the other placeholders like
@placeholder,%placeholderand:placeholderThose cases are covered here #2760031: Log messages won't appear translated if they have special characters in them. My proposal then is remove the method testMessageParsing from this patch and move the twig case to #2760031 after this patch be committed.
There is a typo at the end of this string.
Comment #19
googletorp commented18.1 => {{foo}} and {foo} are both PSR3 placeholders it's basically PLACEHOLDER and {PLACEHOLDER}, so no need to update.
18.2 => What we are testing is convention of {{foo}} => {@foo} - the output of other kind out placeholders are outside of the scope for this issue
18.3 => I corrected typo by removing the new test and simply changing the double PSR3 tests to have single and double {} variants.
New files attached
Comment #20
googletorp commentedOps forgot to change status
Comment #22
dagmarSo, I've been playing with this patch and seems is working fine. However, when I try this new patch together with #2760031: Log messages won't appear translated if they have special characters in them, I see the following message:
Which makes sense since
{{ value }}cannot be translated See: https://www.drupal.org/node/2047135Therefore, if we commit this feature, as is (which works) then #2760031: Log messages won't appear translated if they have special characters in them will be blocked forever.
I'm attaching the patch with the 2 patches in the same file.
Comment #24
googletorp commented#22 Merging two issues is probably a bad idea. This issue doesn't touch tranlations of variables. Today {foo} works but {{foor}} doesn't - since {{foo}} is converted to @{foo} instead of {@foo}.
If this issue gives new issues to #2760031, we should handle it there and try to merge these two issues as they aren't related to each other.
I'm removing the patch uploaded in #22 so we can continue with the proposed fix #19.
Comment #25
cburschkaThe patch in #19 looks good. Simple regex fix, and the tests seem to cover it correctly.
Note: As per https://github.com/php-fig/fig-standards/blob/master/accepted/PSR-3-logg...,
Should we make this "SHOULD" mandatory and use
[A-Za-z0-9_.]instead of[^\{}]? Other than that I believe this is ready.Comment #26
dagmarI know, my intention just was to point out that the this patch has side effects.
I'm tagging this with
Needs framework manager reviewto decide if we want to decide that logs cannot be translated anymore. I might be wrong, but as I mentioned in #22, showing{{ twig }}will make impossible to translate logs.Comment #30
mxr576Comment #33
dagmarLong time passed since I reviewed this issue. My concerns about translations were not valid. I manually applied the patch (does not apply anymore) and managed to translate the log without issues.
This seems good to go in my opinion. But the patch does not apply anymore to 9.3.x
Comment #34
suresh prabhu parkala commentedRe-rolled patch against 9.3.x. Please review.
Comment #35
dagmarThe patch that needs a reroll is this one. #19
Comment #36
ankithashettyRe-rolled the patch in #19 as requested in #35, thanks!
Comment #37
dagmarThanks @ankithashetty
I think this looks good. There is a question about if the current pattern should be modified, but since this fix the original issue I think this qualifies as a follow up with more tests. #25
Comment #38
alexpottCommitted and pushed f653102333 to 9.3.x and 0865322d5b to 9.2.x. Thanks!
The escaping here is a a little inconsistent but it doesn't matter. I think curly braces only have meaning if there is a number after them so quite possibly all the escaping is unnecessary which would helpful with readability.
Comment #41
googletorp commentedWow, 4 years later and it's in, I forgot I ever worked on this, thanks @dagmar for doing the work to get this over the finish line :)