This post describes steps required to enable logging in Symfony project in production enviroment.
By default logging is disabled in prod enviroment, and if you want to enable it, you need to edit settings.yml and factories.yml files in your app directory.
In settings.yml set parameter logging_enabled to true:
[php]
# /app/frontend/config/settings.yml
prod:
.settings:
no_script_name: true
logging_enabled: true
[/php]
In factories.yml change logger class param to sfAggregateLogger:
[php]
# /app/frontend/config/factories.yml
prod:
logger:
class: sfAggregateLogger
param:
level: err
loggers: ~
[/php]
Note that param level is set to err. This means that only error level messages will be written to log file. If you have a high traffic web service running, this may be the best setting to use.
Important: Although it may appear logical to use sfFileLogger class, this causes error 500 in my project.
If you’re having problems with logging in production when using logger fron sfContext like this:
[php]
sfContext::getInstance()->getLogger()->err(‘My Error Message’);
[/php]
you may want to customize factories.yml further to explicitly specify what type of logger is used :
[php]
# /app/frontend/config/factories.yml
prod:
logger:
class: sfAggregateLogger
param:
level: err
loggers:
sf_file_debug:
class: sfFileLogger
param:
level: err
file: %SF_LOG_DIR%/%SF_APP%_%SF_ENVIRONMENT%.log
[/php]