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
Using version 2.x I would need to lower $errorLogLevel in HttpApiListener listener from LogLevel::ERROR to LogLevel::WARNING.
The procedure I followed works using PHP-DI (see below), I would like to know if it is the correct one or if there is a better approach.
useInpsyde\Wonolog\HookListener\HttpApiListener;
add_action(
'wonolog.setup',
function (Inpsyde\Wonolog\Configurator$config) use ($container) {
$config->disableDefaultHookListeners(
HttpApiListener::class
)
->addActionListener(
$container->get(HttpApiListener::class)
)
;
}
);
Initially I also tried to create a custom HttpApiListener class that extended Inpsyde\Wonolog\HookListener\HttpApiListener by overriding the __construct(int $errorLogLevel = LogLevel::WARNING), but then I realized that the Inpsyde\Wonolog\HookListener\HttpApiListener class is defined as final.
The default listener classes are final because Wonolog instantiates them using new $listener() so if classes would be extended, the constructor could be extended in a non-compatible way (e.g. requiring mandatory parameters), PHP would not complain, but then a fatal error would happen.
The approach you use looks fine to me. In the end, it is like you want to use a custom listener, but that happens to use the same class as the default handler.
Maybe it would be nice to have a filter to change the log level, so that the constructor could look like:
Hi @gmazzap, and thanks for your help!
I think it could be a useful thing to have filters to alter the LogLevels of the default listeners.
The alternative routes (e.g. dependecy injector) are not always easily accessible to everyone, or not everyone knows how to do it, so I would find it useful to provide more options available.
Description of the bug
Using version 2.x I would need to lower
$errorLogLevel
inHttpApiListener
listener fromLogLevel::ERROR
toLogLevel::WARNING
.The procedure I followed works using PHP-DI (see below), I would like to know if it is the correct one or if there is a better approach.
Initially I also tried to create a custom
HttpApiListener
class that extendedInpsyde\Wonolog\HookListener\HttpApiListener
by overriding the__construct(int $errorLogLevel = LogLevel::WARNING)
, but then I realized that theInpsyde\Wonolog\HookListener\HttpApiListener
class is defined asfinal
.Reproduction instructions
.
Expected behavior
.
Environment info
Relevant log output
No response
Additional context
No response
Code of Conduct
The text was updated successfully, but these errors were encountered: