title: Is there a way in Symfony 5.4 to initialize a class at application's boot
body: <p>In a tiny Symfony 5.4 project, I would like to initialize a class (logger) at application's boot. This class will build a singleton object and will give me the possibility to call the logger like this maClass::logger-&gt;error().</p>
  <p>I red a bunch of articles speaking about autowiring. I understand the concept, but in some others classes, I can't use the autowiring, that's why I would like to do that.</p>
  <p>Here my new class:</p>
  <pre><code>&lt;?php
  
  namespace App\Core\Service;
  
  use Psr\Log\LoggerInterface;
  
  class CoreService
  {
      private LoggerInterface $logger;
  
      private static LoggerInterface $loggerSingleton;
  
      public function __construct(LoggerInterface $logger)
      {
          $this-&gt;logger = $logger;
  
          $this-&gt;initStatic();
      }
  
      public function initStatic()
      {
          self::$loggerSingleton = $this-&gt;logger;
      }
  
      public static function logger(): LoggerInterface
      {
          return self::$loggerSingleton;
      }
  }
  </code></pre>
  <p>Is there a way to do that?</p>
  <p>Thanks.</p>