monolog
monolog copied to clipboard
[NormalizerFormatter] Avoid throwing an exception when the toString call fails
HI @Seldaek
This is an improvement of https://github.com/Seldaek/monolog/issues/673
When a __toString method call throws an exception (which should occurs as few as possible), the Normalizer is throwing an exception too. I believe this behavior is wrong because:
- I cannot say monolog to prefer the default behavior over the __toString method
- If I wouldn't have a __toString method, it would have work correctly
Also, I have the following situation when using DoctrineFixtureBundle:
- I wrote a bug in my fixtures
- An exception is thrown
- During this process, monolog try to do some logs
- For the logs, he look for FooObject::__toString() method
- This method return the name of the FooObject which require a database request (because of doctrine lazy proxy)
- The entity is not found in database (of course, since the fixture loading failure)
- The __toString throws an exception
- Monolog crash
- I get the monolog failure instead of the doctrineFixture one to debug correctly my work.
As soon as I comment the toString method in my entity, I get the correct error. Imho, if monolog cannot use the toString method, he shouldn't change the "error behavior" and fallback to jsonEncode like the tostring method doesn't exist.
WDYT ?