title: Symfony - Accessing Service from Custom Class
body: <p>I am trying to log information with Monolog library from a Custom Class that I have created that is called Common. </p>
  
  <p>I have included logger as an argument in service.yml for that class</p>
  
  <pre><code>parameters:
  services:
     appbundle.helper.common:
     class: AppBundle\Helpers\Common
     arguments: ['@doctrine','@logger']
  </code></pre>
  
  <p>I have also initialized the Logger Interface for that class.</p>
  
  <pre><code>    private $dataEntityManager;
      private $suppEntityManager;
      private $curation;
      private $innerDoctrine;
      private $logger;
  
      /**
       * Common constructor.
       * @param ManagerRegistry $doctrine
       */
      public function __construct(ManagerRegistry $doctrine, LoggerInterface $logger)
      {
          $this-&gt;dataEntityManager = $doctrine-&gt;getManager();
          $this-&gt;suppEntityManager = $doctrine-&gt;getManager('gtsupp');
          $this-&gt;curation = new Curation($doctrine);
          $this-&gt;innerDoctrine = $doctrine;
          $this-&gt;logger = $logger;
      }
      public function detail($a, $b, $c, $d, $e, $f = "", $g = true, $h = true)
      {
  
         $this-&gt;logger-&gt;error('Type not supplied in Common detail ' . __LINE__ . " for descriptor: " . $b);
  
       }
  </code></pre>
  
  <p>The problem is that each time I want to use class::Common <strong>I have to provide the logger</strong> in Class's constructor.</p>
  
  <pre><code>    class DefaultController extends Controller
      {
          /**
           * @Route("/", name="homepage")
           */
          public function indexAction(Request $request)
          {
              $common = new Common($this-&gt;getDoctrine(), $this-&gt;get('logger'));
              $common-&gt;detail('a', 'b', 'c', 'd', 'e');
  
              return $this-&gt;render('default/index.html.twig', [
                  'base_dir' =&gt; realpath($this-&gt;getParameter('kernel.root_dir') . '/..') . DIRECTORY_SEPARATOR,
              ]);
          }
      }
  </code></pre>
  
  <p>P.S.
  Same problem occurs with doctrine. I have to pass it every time I call Common class as you can see above. </p>