Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

348
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda