gpt4 book ai didi

Symfony Autowiring 独白 channel

转载 作者:行者123 更新时间:2023-12-02 02:23:40 26 4
gpt4 key购买 nike

关注此documentation ,我可以创建许多 channel ,这些 channel 将创建具有以下名称 monolog.logger.<channel_name> 的服务

如何通过 DI 注入(inject)和 Autowiring 将这些服务注入(inject)到我的服务中?

class FooService
{
public function __construct(LoggerInterface $loggerInterface) { }
}

Yaml

#existing
foo_service:
class: AppBundle\Services\FooService
arguments: ["@monolog.logger.barchannel"]
# what I want to do
foo_service:
autowire: true # how to inject @monolog.logger.barchannel ?

最佳答案

Starting from MonologBundle 3.5 you can autowire different Monolog channels by type-hinting your service arguments with the following syntax: Psr\Log\LoggerInterface $<channel>Logger. For example, to inject the service related to the app logger channel use this:

public function __construct(LoggerInterface $appLogger)
{
$this->logger = $appLogger;
}

https://symfony.com/doc/current/logging/channels_handlers.html#monolog-autowire-channels

关于Symfony Autowiring 独白 channel ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43788114/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com