$app = new \Slim\App(['settings' => ['displayErrorDetails' => true]]); $container = $app->getContainer(); $container['logger'] = function ($c) { ... return $logger; }; $app->addErrorMiddleware(true, true, true, $container['logger']);
这将捕获所有Slim应用程序错误,并输出到配置的日志文件中,以便进行排查和解决问题。