diff --git a/CHANGELOG-3.1.md b/CHANGELOG-3.1.md index eb9050ae2..44a964a7e 100644 --- a/CHANGELOG-3.1.md +++ b/CHANGELOG-3.1.md @@ -3,6 +3,7 @@ ## Added - [#6483](https://github.com/hyperf/hyperf/pull/6483) [#6487] (https://github.com/hyperf/hyperf/pull/6487) Added new ways to register crontab. +- [#6488](https://github.com/hyperf/hyperf/pull/6488) Added the default implement for `Psr\Log\LoggerInterface`. ## Optimized diff --git a/src/coordinator/src/Timer.php b/src/coordinator/src/Timer.php index f361e99a2..d6095f189 100644 --- a/src/coordinator/src/Timer.php +++ b/src/coordinator/src/Timer.php @@ -11,7 +11,7 @@ declare(strict_types=1); */ namespace Hyperf\Coordinator; -use Hyperf\Contract\StdoutLoggerInterface; +use Psr\Log\LoggerInterface; use Throwable; use function Hyperf\Coroutine\go; @@ -28,7 +28,7 @@ class Timer private static int $round = 0; - public function __construct(private ?StdoutLoggerInterface $logger = null) + public function __construct(private ?LoggerInterface $logger = null) { } diff --git a/src/crontab/src/Strategy/Executor.php b/src/crontab/src/Strategy/Executor.php index 3ffe5535f..28559f8c4 100644 --- a/src/crontab/src/Strategy/Executor.php +++ b/src/crontab/src/Strategy/Executor.php @@ -21,10 +21,12 @@ use Hyperf\Crontab\Event\AfterExecute; use Hyperf\Crontab\Event\BeforeExecute; use Hyperf\Crontab\Event\FailToExecute; use Hyperf\Crontab\Exception\InvalidArgumentException; +use Hyperf\Crontab\LoggerInterface; use Hyperf\Crontab\Mutex\ServerMutex; use Hyperf\Crontab\Mutex\TaskMutex; use Psr\Container\ContainerInterface; use Psr\EventDispatcher\EventDispatcherInterface; +use Psr\Log\LoggerInterface as PsrLoggerInterface; use RuntimeException; use Symfony\Component\Console\Input\ArrayInput; use Symfony\Component\Console\Output\NullOutput; @@ -34,7 +36,7 @@ use function Hyperf\Support\make; class Executor { - protected ?StdoutLoggerInterface $logger = null; + protected ?PsrLoggerInterface $logger = null; protected ?TaskMutex $taskMutex = null; @@ -46,7 +48,9 @@ class Executor public function __construct(protected ContainerInterface $container) { - if ($container->has(StdoutLoggerInterface::class)) { + if ($container->has(LoggerInterface::class)) { + $this->logger = $container->get(LoggerInterface::class); + } elseif ($container->has(StdoutLoggerInterface::class)) { $this->logger = $container->get(StdoutLoggerInterface::class); } if ($container->has(EventDispatcherInterface::class)) { diff --git a/src/logger/src/ConfigProvider.php b/src/logger/src/ConfigProvider.php index 9fa4464e6..87f505558 100644 --- a/src/logger/src/ConfigProvider.php +++ b/src/logger/src/ConfigProvider.php @@ -11,11 +11,16 @@ declare(strict_types=1); */ namespace Hyperf\Logger; +use Psr\Log\LoggerInterface; + class ConfigProvider { public function __invoke(): array { return [ + 'dependencies' => [ + LoggerInterface::class => fn ($container) => $container->get(LoggerFactory::class)->make(), + ], 'publish' => [ [ 'id' => 'config', diff --git a/src/logger/tests/ConfigProviderTest.php b/src/logger/tests/ConfigProviderTest.php deleted file mode 100644 index 38b2886e5..000000000 --- a/src/logger/tests/ConfigProviderTest.php +++ /dev/null @@ -1,39 +0,0 @@ -assertSame([ - 'publish' => [ - [ - 'id' => 'config', - 'description' => 'The config for logger.', - 'source' => $dir . '/../publish/logger.php', - 'destination' => BASE_PATH . '/config/autoload/logger.php', - ], - ], - ], (new ConfigProvider())()); - } -}