I have a new Slim4 application. In the constructor of the router I’m defining a LoggerInterface injectable like this:
$containerBuilder->addDefinitions([
LoggerInterface::class => function (ContainerInterface $c) {
$logger = new Logger('myApp');
I can use this throughout all my normal classes now. However, I want to use the same logger also for the error handler. The errorhandler is set in the index page like this:
$errorHandler = new HttpErrorHandler($callableResolver, $responseFactory);
$errorMiddleware->setDefaultErrorHandler($errorHandler);
My idea is that I want to override the logError function in the errorhandler to use the logger instead of error_log(). What is the best way to pass the logger Interface into this errorhandler? It seems like a basic requirement but I can not find any related documentation.
thanks for the reply. Could you please elaborate? When adding the HttpErrorHandler::class as container definition, how could I inject the logger there, and how would I set this errorhandler as the default errorhandler?