Skip to content

Cannot override handlers for test environment #502

@Koitus01

Description

@Koitus01

"symfony/monolog-bundle": "^3.10"
"php": ">=8.2"

I have the monolog.yaml for my dev, stage and prod environments:

monolog:
    handlers:
        console:
            type: stream
            path: 'php://stdout'
            level: info
            channels: [ 'console' ]
        errors:
            type: fingers_crossed
            action_level: warning
            excluded_http_codes: [ 404 ]
            handler: errors_nested
        errors_nested:
            type: gelf
            level: warning
            formatter: Monolog\Formatter\GelfMessageFormatter
            publisher: Gelf\Publisher
            channels: [ '!app' ]
        manual:
            type: gelf
            level: debug
            formatter: Monolog\Formatter\GelfMessageFormatter
            publisher: Gelf\Publisher
            channels: [ 'app' ]

which sends logs in Graylog. But i don't want to use graylog in test environment, so i tried few versions of test/monolog.yaml:

monolog:
    handlers:
        errors:
            type: stream
            path: 'php://stdout'
            level: warning
            channels: ['!app']
        manual:
            type: stream
            path: 'php://stdout'
            level: debug
            channels: [ 'app' ]
monolog:
    handlers:
        errors:
            type: test
        manual:
            type: test
monolog:
    handlers:
        errors:
            type: null
        manual:
            type: null
        main:
            type: stream
            path: "%kernel.logs_dir%/%kernel.environment%.log"
            level: debug
monolog:
    handlers:
        errors:
            type: null
            handler: null
        manual:
            type: null
            handler: null
        main:
            type: stream
            path: "%kernel.logs_dir%/%kernel.environment%.log"
            level: debug

but all of this configs give me an error:

In BaseNode.php line 407:
                                                                                                                                                        
  [Symfony\Component\Config\Definition\Exception\InvalidConfigurationException]                                                                         
  Invalid configuration for path "monolog.handlers.errors": You can only use excluded_http_codes/excluded_404s with a FingersCrossedHandler definition  
                                                                                                                                                        

Exception trace:
  at /application/vendor/symfony/config/Definition/BaseNode.php:407
 Symfony\Component\Config\Definition\BaseNode->finalize() at /application/vendor/symfony/config/Definition/PrototypedArrayNode.php:165
 Symfony\Component\Config\Definition\PrototypedArrayNode->finalizeValue() at /application/vendor/symfony/config/Definition/BaseNode.php:393
 Symfony\Component\Config\Definition\BaseNode->finalize() at /application/vendor/symfony/config/Definition/ArrayNode.php:232
 Symfony\Component\Config\Definition\ArrayNode->finalizeValue() at /application/vendor/symfony/config/Definition/BaseNode.php:393
 Symfony\Component\Config\Definition\BaseNode->finalize() at /application/vendor/symfony/config/Definition/Processor.php:36
 Symfony\Component\Config\Definition\Processor->process() at /application/vendor/symfony/config/Definition/Processor.php:46
 Symfony\Component\Config\Definition\Processor->processConfiguration() at /application/vendor/symfony/dependency-injection/Extension/Extension.php:109
 Symfony\Component\DependencyInjection\Extension\Extension->processConfiguration() at /application/vendor/symfony/monolog-bundle/DependencyInjection/MonologExtension.php:62
 Symfony\Bundle\MonologBundle\DependencyInjection\MonologExtension->load() at /application/vendor/symfony/dependency-injection/Compiler/MergeExtensionConfigurationPass.php:81
 Symfony\Component\DependencyInjection\Compiler\MergeExtensionConfigurationPass->process() at /application/vendor/symfony/http-kernel/DependencyInjection/MergeExtensionConfigurationPass.php:40
 Symfony\Component\HttpKernel\DependencyInjection\MergeExtensionConfigurationPass->process() at /application/vendor/symfony/dependency-injection/Compiler/Compiler.php:73
 Symfony\Component\DependencyInjection\Compiler\Compiler->compile() at /application/vendor/symfony/dependency-injection/ContainerBuilder.php:752
 Symfony\Component\DependencyInjection\ContainerBuilder->compile() at /application/vendor/symfony/http-kernel/Kernel.php:495
 Symfony\Component\HttpKernel\Kernel->initializeContainer() at /application/vendor/symfony/http-kernel/Kernel.php:740
 Symfony\Component\HttpKernel\Kernel->preBoot() at /application/vendor/symfony/http-kernel/Kernel.php:120
 Symfony\Component\HttpKernel\Kernel->boot() at /application/vendor/codeception/module-symfony/src/Codeception/Module/Symfony.php:214
 Codeception\Module\Symfony->_initialize() at /application/vendor/codeception/codeception/src/Codeception/SuiteManager.php:72
 Codeception\SuiteManager->initialize() at /application/vendor/codeception/codeception/src/Codeception/Codecept.php:256
 Codeception\Codecept->runSuite() at /application/vendor/codeception/codeception/src/Codeception/Codecept.php:216
 Codeception\Codecept->run() at /application/vendor/codeception/codeception/src/Codeception/Command/Run.php:435
 Codeception\Command\Run->execute() at /application/vendor/symfony/console/Command/Command.php:279
 Symfony\Component\Console\Command\Command->run() at /application/vendor/symfony/console/Application.php:1029
 Symfony\Component\Console\Application->doRunCommand() at /application/vendor/symfony/console/Application.php:316
 Symfony\Component\Console\Application->doRun() at /application/vendor/symfony/console/Application.php:167
 Symfony\Component\Console\Application->run() at /application/vendor/codeception/codeception/src/Codeception/Application.php:112
 Codeception\Application->run() at /application/vendor/codeception/codeception/app.php:45
 {closure}() at /application/vendor/codeception/codeception/app.php:46
 require() at /application/vendor/codeception/codeception/codecept:7
 include() at /application/vendor/bin/codecept:119

How to properly override monolog.yaml handlers in test or other environments?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions