Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

346
Views
How to change the visibility for the "logger" service on Symfony?

I have recently upgraded from Symfony 3.4 to 4.4

The codebase is really large and there are a lot of references to container->get('logger') from all over the place.

I have been trying to make this service public, but not having any luck with any examples I can find. Error:

The "logger" service or alias has been removed or inlined when the container was compiled. You should either make it public, or stop using the container directly and use dependency injection instead.

In my service.yml I have tried this with no luck:

Psr\Log\LoggerInterface:
 public: true

Psr\Log\LoggerInterface:
 alias: 'logger'
 public: true

Psr\Log\LoggerInterface:
 alias: 'monolog.logger'
 public: true

How can I make the logger service public?

NOTE: in the upgrade from 3.4->4.4 we did not update the codebase to use Symfony Flex

over 4 years ago · Santiago Trujillo
1 answers
Answer question

0

You would do this with a Compiler Pass. (Docs are for 4.4, since that's the version you are using, current docs are here).

Change your application Kernel so it implements CompilerPassInterface, and on the process() method you can manipulate the service container directly:

// src/Kernel.php
namespace App;

use Symfony\Bundle\FrameworkBundle\Kernel\MicroKernelTrait;
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\HttpKernel\Kernel as BaseKernel;

class Kernel extends BaseKernel implements CompilerPassInterface
{
    use MicroKernelTrait;

    // ...

    public function process(ContainerBuilder $container): void
    {
        $container->getDefinition('monolog.logger')->setPublic(true);
    }
}

In any case, if I were you I'd investigate using something like Rector to automatically update your code. It even includes a rule for this specific use-case, converting the (ab)use of injected container and public services into proper dependency injection.

over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!