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

non-existent service error when using service handler in one environment, but not another #429

Open
jdevinemt opened this issue Mar 4, 2022 · 0 comments

Comments

@jdevinemt
Copy link

I am using a monolog service handler labeled db in my dev environment, but not in prod. When I try to run the app or a command in the prod environment I receive the error You have requested a non-existent service "monolog.handler.db". The error is resolved when I add the db handler to the prod monolog configuration.

It seems like this might be a bug when building the container where it does not ignore monolog handler services that are used in one environment, but not another.

In my specific case, I will be using the db handler on production, so I can work around this. But it seems like this might not be working as intended.

Here is the configuration that produced the error:

# config/packages/monolog.yaml
monolog:
    channels:
        - deprecation # Deprecations are logged in the dedicated "deprecation" channel when it exists

when@dev:
    monolog:
        handlers:
            db_filter:
                type: filter
                handler: db
                min_level: warning
            db:
                type: service
                id: App\Logging\Handler\DbHandler
            main_file:
                type: stream
                path: "%kernel.logs_dir%/%kernel.environment%.log"
                level: warning
                channels: ["!event"]
            info_filter:
                type: filter
                handler: info_file
                accepted_levels: ['info']
            info_file:
                type: stream
                path: "%kernel.logs_dir%/%kernel.environment%.info.log"
                channels: ['!event']
            debug_filter:
                type: filter
                handler: debug_file
                accepted_levels: ['debug']
            debug_file:
                type: stream
                path: "%kernel.logs_dir%/%kernel.environment%.debug.log"
                channels: ['!event']
            console:
                type: console
                process_psr_3_messages: false
                channels: ["!event", "!doctrine", "!console"]

when@prod:
    monolog:
        handlers:
            main:
                type: fingers_crossed
                action_level: error
                handler: nested
                excluded_http_codes: [404, 405]
                buffer_size: 50 # How many messages should be saved? Prevent memory leaks
            nested:
                type: stream
                path: php://stderr
                level: debug
                formatter: monolog.formatter.json
            console:
                type: console
                process_psr_3_messages: false
                channels: ["!event", "!doctrine"]
            deprecation:
                type: stream
                channels: [deprecation]
                path: php://stderr

Here is the exception:

AH01071: Got error 'PHP message: PHP Fatal error:  Uncaught Symfony\\Component\\DependencyInjection\\Exception\\ServiceNotFoundException: You have requested a non-existent service "monolog.handler.db". in /var/www/html/vendor/symfony/dependency-injection/ContainerBuilder.php:996
Stack trace:
#0 /var/www/html/vendor/symfony/dependency-injection/ContainerBuilder.php(1028): Symfony\\Component\\DependencyInjection\\ContainerBuilder->getDefinition()
#1 /var/www/html/vendor/symfony/monolog-bundle/DependencyInjection/Compiler/AddProcessorsPass.php(39): Symfony\\Component\\DependencyInjection\\ContainerBuilder->findDefinition()
#2 /var/www/html/vendor/symfony/dependency-injection/Compiler/Compiler.php(82): Symfony\\Bundle\\MonologBundle\\DependencyInjection\\Compiler\\AddProcessorsPass->process()
#3 /var/www/html/vendor/symfony/dependency-injection/ContainerBuilder.php(757): Symfony\\Component\\DependencyInjection\\Compiler\\Compiler->compile()
#4 /var/www/html/vendor/symfony/http-ker...
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant