title: Using custom logger service in AuthenticationHandler class in Symfony2
body: <p><strong>In brief I am trying to use a logger service that I defined inside a custom handler service.</strong></p>
  
  <p><strong>My config.yml</strong></p>
  
  <pre><code>services:
  authentication_handler:
      class: Panasonic\LoginBundle\Handler\AuthenticationHandler
      arguments: [ @custom_logger ]
  
  custom_logger:
      class: Monolog\Logger
      arguments: [login]
      calls:
          - [ pushHandler, [ @custom_logger_stream ]]
  
  custom_logger_stream:
      class: Monolog\Handler\RotatingFileHandler
      arguments: [ %kernel.logs_dir%/test.log, 30, 200 ]
  </code></pre>
  
  <p>The "services:" is well indented in my code, dnt worry.</p>
  
  <p><strong>My Bundle/Handler/AuthenticationHandler</strong></p>
  
  <pre><code>namespace Panasonic\LoginBundle\Handler;
  
  use Monolog\Logger;
  use Symfony\Component\Security\Http\Authentication\AuthenticationSuccessHandlerInterface;
  use Symfony\Component\Security\Core\Authentication\Token\TokenInterface;
  use Symfony\Component\HttpFoundation\Request;
  use Symfony\Component\HttpFoundation\Response;
  
  class AuthenticationHandler implements AuthenticationSuccessHandlerInterface
  {
  
  private $custom_logger;
  
  public function __constructor(Logger $custom_logger)
  {
      $this-&gt;custom_logger = $custom_logger;
  }
  
  public function onAuthenticationSuccess(Request $request,
                                          TokenInterface $token)
  {
      $log = $this-&gt;custom_logger;
  
      $log-&gt;addWarning('Foo');
      $log-&gt;addError('Bar');
      die;
  
      //        var_dump($token); die;
      //        var_dump($request-&gt;getSession()); die;
  }
  }
  </code></pre>
  
  <p>I am getting:</p>
  
  <pre><code>Fatal error: Call to a member function addWarning() on a non-object in ... Panasonic\LoginBundle\Handler\AuthenticationHandler.php on line 22
  </code></pre>
  
  <p>Note: I am aware I should return a response in onAuthenticationSuccess, it's in fact uncomplete, but I know it works, I got results from the var_dumps.</p>
  
  <p><strong>I guess the injection is not ok, how should it be done? I can't figure out what to do here. Please help</strong></p>
  
  <p>the references I checked:
  <a href="https://stackoverflow.com/questions/8953721/symfony2-access-services-inside-a-regular-class">Access services inside a regular class</a></p>
  
  <p><a href="http://martinsikora.com/symfony2-and-dependency-injection" rel="nofollow noreferrer">http://martinsikora.com/symfony2-and-dependency-injection</a></p>