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.
try this:
use Monolog\Logger;
instead of this:
use Symfony\Component\HttpKernel\Log\LoggerInterface;
And after this;
public function __construct(ContainerInterface $container, EntityManager $em, Logger $logger){
insetad of this:
public function __construct(ContainerInterface $container, EntityManager $em, LoggerInterface $logger){
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With