Symfony 2 Injecting logger service

Viewed 4922

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

When injecting the logger to a service, I get a type error because LoggerInterface expected but Symfony\Bridge\Monolog\Logger given.

Also if I try to inject a custom logger, I get error because of 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"]

Service:

<?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 injecting the logger with @monolog.logger.paymentlog is giving me an error "undefinded service"

Can someone please tell me where I am wrong?

THX a lot.

1 Answers
Related