Symfony 2 Import Registration Service

I am having a strange problem using the logger service in symfony 2:

When entering the logger into the service, I get a type error because the LoggerInterface is expected, but Symfony \ Bridge \ Monolog \ Logger is listed.

Also, if I try to enter a custom logger, I get an error because of the undefined service.

Here is my code:

confiy.yml

monolog:
channels: ['payment']
handlers:
    paymentlog:
        type: stream
        path: "%kernel.logs_dir%/payment.log"
        level: debug
        channels: [payment]

      

service.yml

#payment_services
  payment.gateway_payments:
    class: AppBundle\Service\paymentService
    arguments: ["@service_container", "@doctrine.orm.entity_manager", "@logger"]

      

Services:

<?php

  namespace AppBundle\Service;

  use Symfony\Component\DependencyInjection\ContainerInterface;
  use Doctrine\ORM\EntityManager;
  use Symfony\Component\HttpKernel\Log\LoggerInterface;

  class paymentService {

    private $container;
    private $em;
    private $logger;

    public function __construct(ContainerInterface $container, EntityManager $em, LoggerInterface $logger){
    $this->container = $container;
    $this->em = $em;
    $this->logger = $logger;
}

      

Also, logging in with @ monolog.logger.paymentlog gives me an "undefinded service" error

Can someone please tell me where am I going wrong?

thanks a lot.

+3


source to share


1 answer


try this:

use Monolog\Logger;

      

instead of this:

use Symfony\Component\HttpKernel\Log\LoggerInterface;

      



And after that

public function __construct(ContainerInterface $container, EntityManager $em, Logger $logger){

      

Pasting this:

public function __construct(ContainerInterface $container, EntityManager $em, LoggerInterface $logger){

      

+3


source







All Articles