You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
is there some kind of "best practice" to format throwables before passing to LoggerInterface::* method?
As of monolog, passing an instance of Throwable is "okay", as LoggerInterface::log does not have any native typehint and thus its okay to pass anything and within the NormalizerFormatter that Throwable would be converted (that formatter is used in almost all handlers).
But as I've seen these "by-law" version bumps on e.g. PSR-6, I think there will be a new Version soon, which enforces string typehint.
Are there any suggestions on how to pre-format a Throwable or probably monolog might provide a new Interface which allows to log throwables and using the PSR-3 methods?
The right way to pass throwables IMO is in the $context info as ['exception' => $e]. The message should be a string. This is what PSR-3 advocates too, and monolog will normalize them correctly depending on user preferences, including stack trace or not etc. The caller should not be able to decide this, it should pass the Throwable object together with a meaningful message indicating what happened and that's it.
Monolog version 2
Hey there,
is there some kind of "best practice" to format throwables before passing to
LoggerInterface::*
method?As of monolog, passing an instance of
Throwable
is "okay", asLoggerInterface::log
does not have any native typehint and thus its okay to pass anything and within theNormalizerFormatter
thatThrowable
would be converted (that formatter is used in almost all handlers).But as I've seen these "by-law" version bumps on e.g. PSR-6, I think there will be a new Version soon, which enforces
string
typehint.Are there any suggestions on how to pre-format a Throwable or probably monolog might provide a new Interface which allows to log throwables and using the PSR-3 methods?
Maybe something like this?
The text was updated successfully, but these errors were encountered: