From 11fa34a93dd12fd96fbc1e97db824d165be4e7e4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jaime=20Pe=CC=81rez=20Crespo?= <jaime.perez@uninett.no> Date: Tue, 24 Sep 2019 16:48:28 +0200 Subject: [PATCH] Capture exceptions when trying to initialize the logging handler. This allows us to default to the error log, while also not breaking SSP completely. If we cannot initialize the logging handler, then we resort to the web servers log and log a critical error. This resolves #1194 --- lib/SimpleSAML/Logger.php | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/lib/SimpleSAML/Logger.php b/lib/SimpleSAML/Logger.php index f842c4337..8c88e2a9c 100644 --- a/lib/SimpleSAML/Logger.php +++ b/lib/SimpleSAML/Logger.php @@ -2,6 +2,8 @@ namespace SimpleSAML; +use SimpleSAML\Logger\ErrorLogLoggingHandler; + /** * The main logger class for SimpleSAMLphp. * @@ -443,13 +445,18 @@ class Logger $handler = $known_handlers[$handler]; } - /** @var \SimpleSAML\Logger\LoggingHandlerInterface */ - self::$loggingHandler = new $handler($config); - self::$format = $config->getString('logging.format', self::$format); - self::$loggingHandler->setLogFormat(self::$format); - self::$initializing = false; + try { + /** @var \SimpleSAML\Logger\LoggingHandlerInterface */ + self::$loggingHandler = new $handler($config); + self::$loggingHandler->setLogFormat(self::$format); + self::$initializing = false; + } catch (\Exception $e) { + self::$loggingHandler = new ErrorLogLoggingHandler($config); + self::$initializing = false; + self::log(self::CRIT, $e->getMessage(), false); + } } -- GitLab