From 9b5edeb65b1fa8ec70996b3b543fb27e20699b51 Mon Sep 17 00:00:00 2001 From: David Neilsen Date: Wed, 22 Apr 2020 11:42:59 +1200 Subject: [PATCH 1/2] Remove global constant and throw an exception instead if not set --- src/pg/constants/Config.php | 2 +- src/pg/utils/LoggingUtil.php | 4 ++++ 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/src/pg/constants/Config.php b/src/pg/constants/Config.php index b748475..490e5ae 100755 --- a/src/pg/constants/Config.php +++ b/src/pg/constants/Config.php @@ -25,7 +25,7 @@ class Config /** * @var string */ - static $monologLogfile = PROJECT . '/logs/app.log'; + static $monologLogfile = null; /** * This holds unique uuid v4 diff --git a/src/pg/utils/LoggingUtil.php b/src/pg/utils/LoggingUtil.php index 9b26d4f..7fb71aa 100755 --- a/src/pg/utils/LoggingUtil.php +++ b/src/pg/utils/LoggingUtil.php @@ -11,6 +11,7 @@ use Monolog\Handler\StreamHandler; use Monolog\Logger; use paytmpg\pg\constants\Config; + use paytmpg\pg\exceptions\SDKException; /** * Class LoggingUtil @@ -40,6 +41,9 @@ protected function __construct() public static function addLog($severity, $className, $msg) { if (!isset(static::$logger)) { + if (!Config::$monologLogfile) { + throw new SDKException('Monolog log file not set'); + } static::$logger = new Logger(Config::$monologName); $stream = new StreamHandler(Config::$monologLogfile, Config::$monologLevel); $formatter = new LineFormatter(null, null, false, true); From 3e721816d62db41b44f4e9dce3a890a28b0d4390 Mon Sep 17 00:00:00 2001 From: David Neilsen Date: Wed, 22 Apr 2020 11:54:59 +1200 Subject: [PATCH 2/2] Fix circular dependency --- src/pg/utils/LoggingUtil.php | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/pg/utils/LoggingUtil.php b/src/pg/utils/LoggingUtil.php index 7fb71aa..f1dbabd 100755 --- a/src/pg/utils/LoggingUtil.php +++ b/src/pg/utils/LoggingUtil.php @@ -11,7 +11,6 @@ use Monolog\Handler\StreamHandler; use Monolog\Logger; use paytmpg\pg\constants\Config; - use paytmpg\pg\exceptions\SDKException; /** * Class LoggingUtil @@ -42,7 +41,7 @@ public static function addLog($severity, $className, $msg) { if (!isset(static::$logger)) { if (!Config::$monologLogfile) { - throw new SDKException('Monolog log file not set'); + throw new \Exception('Monolog log file not set'); } static::$logger = new Logger(Config::$monologName); $stream = new StreamHandler(Config::$monologLogfile, Config::$monologLevel);