diff --git a/src/Configuration.php b/src/Configuration.php index 632d0ea..747dd96 100644 --- a/src/Configuration.php +++ b/src/Configuration.php @@ -2,7 +2,7 @@ namespace Hypernode\DeployConfiguration; -use Hypernode\DeployConfiguration\Logging\SimpleLogger; +use Hypernode\DeployConfiguration\Logging\LoggingFactory; use Psr\Log\LoggerInterface; use Psr\Log\LogLevel; @@ -157,7 +157,7 @@ class Configuration public function __construct() { - $this->logger = new SimpleLogger(LogLevel::INFO); + $this->logger = LoggingFactory::create(LogLevel::INFO); $this->setDefaultComposerOptions(); } diff --git a/src/Logging/LegacyLogger.php b/src/Logging/LegacyLogger.php new file mode 100644 index 0000000..732671e --- /dev/null +++ b/src/Logging/LegacyLogger.php @@ -0,0 +1,52 @@ + 0, + LogLevel::INFO => 1, + LogLevel::NOTICE => 2, + LogLevel::WARNING => 3, + LogLevel::ERROR => 4, + LogLevel::CRITICAL => 5, + LogLevel::ALERT => 6, + LogLevel::EMERGENCY => 7 + ]; + + /** + * @var int + */ + private $mappedLevel; + + public function __construct(string $level) + { + $this->mappedLevel = self::LEVEL_MAPPING[$level] ?? 1; + } + + /** + * @param mixed $level + * @param string|\Stringable $message + * @param mixed[] $context + * @return void + */ + public function log($level, $message, array $context = array()) + { + if ($this->mapLevelToNumber($level) ?? 1 >= $this->mappedLevel) { + printf("%s (%s)\n", $message, json_encode($context)); + } + } + + private static function mapLevelToNumber(string $level): int + { + return self::LEVEL_MAPPING[$level] ?? 1; + } +} diff --git a/src/Logging/LoggingFactory.php b/src/Logging/LoggingFactory.php new file mode 100644 index 0000000..9a32055 --- /dev/null +++ b/src/Logging/LoggingFactory.php @@ -0,0 +1,19 @@ +mapLevelToNumber($level) ?? 1 >= $this->mappedLevel) { + if ($this->mapLevelToNumber($level) >= $this->mappedLevel) { printf("%s (%s)\n", $message, json_encode($context)); } }