-
-
Notifications
You must be signed in to change notification settings - Fork 9.6k
fix ConsoleFormatter - call to a member function format() on string #31326
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix ConsoleFormatter - call to a member function format() on string #31326
Conversation
|
||
namespace Symfony\Bridge\Monolog\Tests\Formatter; | ||
|
||
use DateTime; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we dont use root classes :) should be prefixed with \
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fixed, thank you
The failing tests seem unrelated, they're failing in other PRs too. |
Thank you @keksa. |
…on string (keksa) This PR was merged into the 3.4 branch. Discussion ---------- fix ConsoleFormatter - call to a member function format() on string | Q | A | ------------- | --- | Branch? | 3.4 | Bug fix? | yes | New feature? | no | BC breaks? | maybe | Deprecations? | no | Tests pass? | yes | Fixed tickets | - | License | MIT | Doc PR | - The ConsoleFormatter crashes when there is not a DateTime object in `$record['datetime']`. As this parameter is not documented anywhere (i.e. `FormatterInterface` does not say it must be a DateTime object), I think the proper fix is to check if there is DateTimeInterface object and only call the `format` method then. We use a custom LogProcessor (https://symfony.com/doc/current/logging/processors.html) to add some extra data and format the DateTime in the `$record['datetime']`. We need to format the DateTime in the processor, because we use `JsonFormatter` in prod environment and it does not support changing the date format. We use `ConsoleFormatter` only in dev environment and as the processor is called before the formatter, we get the crash. There were no tests whatsoever for `ConsoleFormatter`, so I've added a basic one, that passes before and after, and another one that tests the crash (failed before, passed after). There is a theoretical BC break, as someone could have sent an object with a `format` method to the formatter and it would have worked, but I'm not sure if it's considered BC break by Symfony, please let me know, if it is. Commits ------- 6488328 fix ConsoleFormatter - call to a member function format() on string
The ConsoleFormatter crashes when there is not a DateTime object in
$record['datetime']
. As this parameter is not documented anywhere (i.e.FormatterInterface
does not say it must be a DateTime object), I think the proper fix is to check if there is DateTimeInterface object and only call theformat
method then.We use a custom LogProcessor (https://symfony.com/doc/current/logging/processors.html) to add some extra data and format the DateTime in the
$record['datetime']
. We need to format the DateTime in the processor, because we useJsonFormatter
in prod environment and it does not support changing the date format. We useConsoleFormatter
only in dev environment and as the processor is called before the formatter, we get the crash.There were no tests whatsoever for
ConsoleFormatter
, so I've added a basic one, that passes before and after, and another one that tests the crash (failed before, passed after).There is a theoretical BC break, as someone could have sent an object with a
format
method to the formatter and it would have worked, but I'm not sure if it's considered BC break by Symfony, please let me know, if it is.