symfony 3.4에서 설명한 것처럼 MonologBundle
및 다른 모든 서비스에서 제공하는 logger
서비스는 기본적으로 개인용으로 설정됩니다. [sic]
이 문제를 해결하려면 권장되는 방법은 종속성 삽입을 사용하는 것입니다. http://symfony.com/doc/3.4/logging.html
namespace AppBundle/Controller;
use Psr\Log\LoggerInterface;
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
class DefaultController extends Controller
{
public function indexAction(LoggerInterface $logger)
{
$logger->info('Your Message');
}
}
소스 코드 참조 : autowire
을 사용하는 경우 의존성 삽입 (Dependency Injection)을 사용할 수 https://github.com/symfony/monolog-bundle/blob/v3.1.0/Resources/config/monolog.xml#L17
서비스에 대한 정의.
#app/config/services.yml
services:
# default configuration for services in *this* file
_defaults:
# automatically injects dependencies in your services
autowire: true
# automatically registers your services as commands, event subscribers, etc.
autoconfigure: true
# this means you cannot fetch services directly from the container via $container->get()
# if you need to do this, you can override this setting on individual services
public: false
# makes classes in src/AppBundle available to be used as services
# this creates a service per class whose id is the fully-qualified class name
AppBundle\:
resource: '../../src/AppBundle/*'
# you can exclude directories or files
# but if a service is unused, it's removed anyway
exclude: '../../src/AppBundle/{Entity,Repository,Tests}'
#optionally declare individual service as public
#AppBundle\Service\MyService:
# public: true
#alternatively declare the namespace explicitly as public
#AppBundle\Service\:
# resource: '../../src/AppBundle/Service/*'
# public: true
[sic] 그런 다음 서비스에 종속성을 주입하기 위해, 당신은 생성자에 인수 타입 힌트를 추가 할 수 있습니다. autowire
을 사용하지
namespace AppBundle\Service;
use Psr\Log\LoggerInterface;
class MyService
{
private $logger;
public function __construct(LoggerInterface $logger)
{
$this->logger = $logger;
}
}
경우, 수동으로 로거 별칭을 주입하는 서비스를 정의 할 수 있습니다. 또한
#app/config/services.yml
services:
AppBundle\Service\MyService:
arguments: ['@logger']
public: true
이 컨테이너에서 공개적으로 액세스 할 수 있도록 로거 별칭을 강제로, 당신은 당신의 응용 프로그램 서비스 구성에서 서비스 별칭을 다시 선언 할 수 있습니다.
#app/config/services.yml
services:
#...
logger:
alias: 'monolog.logger'
public: true
귀하의 코드없이 특별히 도와 드릴 수 없지만 오류 메시지가 무엇이 잘못되었는지를 알려줍니다. Symfony 서비스와 종속성 삽입은 3.2에서 3.4 사이에서 크게 변경되었습니다.https://symfony.com/doc/current/service_container/3.3-di-changes.html – MEmerson
오, 죄송합니다. 코드에서 죄송합니다. 로거 서비스와 전화 정보를 얻으려고합니다. –
그렇게하지 마십시오. 로거를 당기는 위치를 나타내는 코드를 사용하여 질문을 업데이트하십시오. 그리고 아마도 우리는 변화를 제안 할 수 있습니다. – Cerad