diff --git a/compatibility/DefaultLoggerPsrLogV1.php b/compatibility/DefaultLoggerPsrLogV1.php new file mode 100644 index 00000000..acc4eb8d --- /dev/null +++ b/compatibility/DefaultLoggerPsrLogV1.php @@ -0,0 +1,18 @@ +=5.6", "guzzlehttp/guzzle": "^6.2.1|^7.0", - "psr/log": "^1.1" + "psr/log": "^1.1 || v3.0" }, "require-dev": { "phpunit/phpunit": "^9.0", diff --git a/src/Core/Logger/DefaultLogger.php b/src/Core/Logger/DefaultLogger.php index 8cdcc9df..4e29539a 100644 --- a/src/Core/Logger/DefaultLogger.php +++ b/src/Core/Logger/DefaultLogger.php @@ -2,17 +2,15 @@ namespace UCloud\Core\Logger; -use Psr\Log\LoggerInterface; -use Psr\Log\AbstractLogger; +use ReflectionMethod; -class DefaultLogger extends AbstractLogger implements LoggerInterface -{ - public function log($level, $message, array $context = []) - { - $line = $level . " " . $message; - if (!empty($context)) { - $line = " " . json_encode($context, JSON_PRETTY_PRINT); - } - echo $line . "\n"; +$logMethodReflection = new ReflectionMethod("Psr\Log\AbstractLogger", "log"); +if (version_compare(PHP_VERSION, '8.0.0', '<')) { + include "compatibility/DefaultLoggerPsrLogV1.php"; +} else { + if ($logMethodReflection->hasReturnType()) { + include "compatibility/DefaultLoggerPsrLogV3.php"; + } else { + include "compatibility/DefaultLoggerPsrLogV1.php"; } } diff --git a/src/Core/Logger/DisabledLogger.php b/src/Core/Logger/DisabledLogger.php index 97311067..f5b0f9cc 100644 --- a/src/Core/Logger/DisabledLogger.php +++ b/src/Core/Logger/DisabledLogger.php @@ -1,15 +1,16 @@ hasReturnType()) { + include "compatibility/DisabledLoggerPsrLogV3.php"; + } else { + include "compatibility/DisabledLoggerPsrLogV1.php"; } }