0

I need to get the list of available channels from monolog configuration file , whene i try to inject these parameters into my custom service like this

logger:
    class: App\Services\Logger
    arguments:
        $channels: '%monolog.channels%'

i got

You have requested a non-existent parameter "monolog.channels".

is odd that symfony don't provide a simple way to access all configurations (even for other bundles like monolog )

is their a way to do this or am i missing something ?

  • You are correct in concluding that Symfony does not automatically expose all configuration as parameters. Each bundle takes it's configuration values and then defines whatever services it needs. In some cases a bundle will expose configuration as parameters but it is up to the bundle. `bin/console debug:container --parameters` will tell you what parameters are available. It might be instructive to take a look at the monolog bundle's extension to see how it handles configuration. – Cerad Jan 26 '22 at 15:30
  • @Cerad thanks for the reply . Unfortunately monolog don't expose the needed configurations . Indeed the bundle extension is where the parameters are injected , so i think it will be a good approach to somehow extend the load method and manually inject the needed parameters . Is there a clean way to do this ? . I'm also considering to parse the configuration file using YAML parser to go around this problem but i don't know if it's recommanded – mohamed ali Jenni Jan 27 '22 at 09:31
  • The 'best' approach would probably be to figure which monolog service has the list of channels and pull it from there. If the config file really has all the info you need (and remember the monolog bundle could easily be adding additional channels) then you could parse it directly in your own extension. Definitely a hack. Have you looked at the monolog package documentation itself? Not the Symfony wrapper. Might discover a different approach to whatever it is that you want to do. – Cerad Jan 27 '22 at 14:47

0 Answers0