Reputation: 1579
I use fosrestBundle with monolog logger to create a custom log. I added this conf in config_dev.yml :
monolog:
handlers:
main:
type: fingers_crossed
action_level: error
handler: nested
nested:
type: stream
path: "%kernel.logs_dir%/%kernel.environment%.log"
level: debug
console:
type: console
myCustomLog:
type: stream
path: "%kernel.logs_dir%/myCustomLog%kernel.environment%.log"
channels: [myCustomLog]
So i did the same in my other environments config files (config_prod.yml, config_qualif.yml ...)
The problem is that may config_prod or config_qualif are not used.
I had this error :
PHP Fatal error: Uncaught Symfony\\Component\\DependencyInjection\\Exception\\ServiceNotFoundException: You have requested a non-existent service "monolog.logger.myCustomLog". in /var/www/myWebSite/vendor/symfony/symfony/src/Symfony/Component/DependencyInjection/ContainerBuilder.php:816\nStack trace:\n#0
I moved my monolog conf in the config.yml file and it works in all environments but this is not a good solution.
Can you help me to understand how to correctly use environments config file, because i am not sure what i did is good ? And i am not sure fosrestbundle uses the right environments config file.
My apache conf looks like this for prod environment:
ServerAdmin webmaster@localhost
DocumentRoot /var/www/myWebSite/web
<IfModule dir_module>
DirectoryIndex app.php
</IfModule>
<Directory /var/www/myWebSite/web>
Options Indexes FollowSymLinks
AllowOverride All
Require all granted
<IfModule mod_rewrite.c>
Options +FollowSymlinks
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ /app.php [QSA,L]
</IfModule>
</Directory>
for qualif environment, the rewrite rules is :
RewriteRule ^(.*)$ /app_qualif.php [QSA,L]
And in app.php i have this line :
$kernel = new AppKernel('prod', false);
And in app_qualif.php i have this line :
$kernel = new AppKernel('qualif', false);
thanks for your help
Upvotes: 0
Views: 180
Reputation: 1579
Ok i solved the problem.
Config files works fine.
The problem came from the command line system. When i called a command i was using this syntax :
php app/console app:my-command
But using this, symfony doesn't know the environment config to use. Now i launch my commands with this syntax :
php app/console --env=prod app:my-command
Upvotes: 1
Reputation: 46
You set your custom category channel for monolog. You should register a service to handle it. You have two solution :
1) create your own service and tag it as a monolog channel handler as explain here : http://symfony.com/doc/current/reference/dic_tags.html#dic-tags-monolog
2) Since monolog 2.4 you can register directly your new channel to monolog in config.yml :
monolog:
channels: ["myCustomLog"]
handlers:
main:
type: fingers_crossed
action_level: error
handler: nested
nested:
type: stream
path: "%kernel.logs_dir%/%kernel.environment%.log"
level: debug
console:
type: console
myCustomLog:
type: stream
path: "%kernel.logs_dir%/myCustomLog%kernel.environment%.log"
channels: [myCustomLog]
Monolog will create automaticaly the service monolog.looger.mycustomlog
Upvotes: 0