Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Document logger configuration #680

Closed
ghost opened this issue Mar 6, 2021 · 17 comments
Closed

Document logger configuration #680

ghost opened this issue Mar 6, 2021 · 17 comments

Comments

@ghost
Copy link

ghost commented Mar 6, 2021

In the developer documentation of using Contao as a Symfony bundle there is no documentation of installing and configuring Monolog. https://docs.contao.org/dev/getting-started/initial-setup/symfony-application/contao-4.9/

I think Monolog is needed because in the Contao backend I get the following error:

Symfony\Component\DependencyInjection\Exception\ServiceNotFoundException:
You have requested a non-existent service "monolog.logger.contao".
@fritzmg
Copy link
Contributor

fritzmg commented Mar 6, 2021

@bytehead can you have a look at this?

@bytehead
Copy link
Member

bytehead commented Mar 8, 2021

I'll check!

@fritzmg
Copy link
Contributor

fritzmg commented Mar 8, 2021

It's now adjusted: #683

@fritzmg fritzmg closed this as completed Mar 8, 2021
@ghost
Copy link
Author

ghost commented Mar 17, 2021

I added the contao handler to my monolog config. Now I get the following error message:

The "monolog.logger.contao" 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.

@bytehead
Copy link
Member

What does this output in your installation?

$ php bin/console debug:container monolog.logger.contao

Information for Service "monolog.logger.contao"
===============================================

 ---------------- ---------------------------------------------------------------------------------- 
  Option           Value                                                                             
 ---------------- ---------------------------------------------------------------------------------- 
  Service ID       monolog.logger.contao                                                             
  Class            Symfony\Bridge\Monolog\Logger                                                     
  Tags             -                                                                                 
  Calls            pushProcessor, pushProcessor, pushHandler, pushHandler, pushHandler, pushHandler  
  Public           yes                                                                               
  Synthetic        no                                                                                
  Lazy             no                                                                                
  Shared           yes                                                                               
  Abstract         no                                                                                
  Autowired        no                                                                                
  Autoconfigured   no                                                                                
 ---------------- ---------------------------------------------------------------------------------- 

@bytehead
Copy link
Member

The "monolog.logger.contao" service or alias has been removed or inlined when the container was compiled.

This can't be the case actually:

https://github.com/contao/contao/blob/c0d004eced89c222004481d4e12f885c8c8debe7/core-bundle/src/DependencyInjection/Compiler/MakeServicesPublicPass.php#L29

@bytehead
Copy link
Member

So I guess the error is somewhere else.

@ghost
Copy link
Author

ghost commented Mar 19, 2021

The output of the console command is:

 ---------------- --------------------------------------------------------------------- 
  Option           Value                                                                
 ---------------- --------------------------------------------------------------------- 
  Service ID       monolog.logger.contao                                                
  Class            Symfony\Bridge\Monolog\Logger                                        
  Tags             -                                                                    
  Calls            pushProcessor, pushProcessor, pushHandler, pushHandler, pushHandler  
  Public           no                                                                   
  Synthetic        no                                                                   
  Lazy             no                                                                   
  Shared           yes                                                                  
  Abstract         no                                                                   
  Autowired        no                                                                   
  Autoconfigured   no                                                                   
 ---------------- --------------------------------------------------------------------- 

The service is not public. How can I make it public?

@bytehead
Copy link
Member

The service should be made public by Contao's MakeServicesPublicPass. Can you debug this line to see, if the service monolog.logger.contao is available at compile time?

@ghost
Copy link
Author

ghost commented Mar 19, 2021

I added the following dd:

if (!$container->hasDefinition($service)) {
    dd($service);
    continue;
}

It was never called so I added a dd at the start of the methode:

public function process(ContainerBuilder $container): void
{
    dd('test');
    // ...
}    

It was not called either.

@bytehead
Copy link
Member

That explains why your service is not public. What about this line?

@ghost
Copy link
Author

ghost commented Mar 19, 2021

That is also not called. That is very strange. I thought that I can not have a Contao backend if the ContaoCoreBundle is not initialized. But I have a backend.

@bytehead
Copy link
Member

That's really strange. How does your AppKernel look like?

@ghost
Copy link
Author

ghost commented Mar 19, 2021

namespace App;

use Symfony\Bundle\FrameworkBundle\Kernel\MicroKernelTrait;
use Symfony\Component\Config\Loader\LoaderInterface;
use Symfony\Component\Config\Resource\FileResource;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\HttpKernel\Kernel as BaseKernel;
use Symfony\Component\Routing\RouteCollectionBuilder;

class Kernel extends BaseKernel
{
    use MicroKernelTrait;

    private const CONFIG_EXTS = '.{php,xml,yaml,yml}';

    public function registerBundles(): iterable
    {
        $contents = require $this->getProjectDir().'/config/bundles.php';
        foreach ($contents as $class => $envs) {
            if ($envs[$this->environment] ?? $envs['all'] ?? false) {
                yield new $class();
            }
        }
    }

    public function getProjectDir(): string
    {
        return \dirname(__DIR__);
    }

    protected function configureContainer(ContainerBuilder $container, LoaderInterface $loader): void
    {
        $container->addResource(new FileResource($this->getProjectDir().'/config/bundles.php'));
        $container->setParameter('container.dumper.inline_class_loader', \PHP_VERSION_ID < 70400 || $this->debug);
        $container->setParameter('container.dumper.inline_factories', true);
        $confDir = $this->getProjectDir().'/config';

        $loader->load($confDir.'/{packages}/*'.self::CONFIG_EXTS, 'glob');
        $loader->load($confDir.'/{packages}/'.$this->environment.'/*'.self::CONFIG_EXTS, 'glob');
        $loader->load($confDir.'/{services}'.self::CONFIG_EXTS, 'glob');
        $loader->load($confDir.'/{services}_'.$this->environment.self::CONFIG_EXTS, 'glob');
    }

    protected function configureRoutes(RouteCollectionBuilder $routes): void
    {
        $confDir = $this->getProjectDir().'/config';

        $routes->import($confDir.'/{routes}/'.$this->environment.'/*'.self::CONFIG_EXTS, '/', 'glob');
        $routes->import($confDir.'/{routes}/*'.self::CONFIG_EXTS, '/', 'glob');
        $routes->import($confDir.'/{routes}'.self::CONFIG_EXTS, '/', 'glob');
    }
}

@ghost
Copy link
Author

ghost commented Mar 19, 2021

That is the normal Symfony Kernel. I did not do the steps in "Enable Cache and Front End Preview" in the documentation because I thought this was not mandatory.

@bytehead
Copy link
Member

Hmm. Looks like the contao/core-bundle should be loaded then 🤔

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants