11

I'd like to set up an additional log file in symfony, so that some messages (payment processing in my case) would go to a different file from the rest of symfony. Is it possible?

Here's my current log configuration from factories.yml:

all:
  logger:
    param:
      level: debug
      loggers:
        sf_file_debug:
          param:
            level: notice
            file: /var/log/symfony/%SF_ENVIRONMENT%/%SF_APP%.log
j0k
  • 21,914
  • 28
  • 75
  • 84
Mike
  • 111
  • 1
  • 3

3 Answers3

11

daviweb's solution will log messages to both log files,

new separate logger can be created using code:

$logPath = sfConfig::get('sf_log_dir').'/your-custom.log';
$custom_logger = new sfFileLogger(new sfEventDispatcher(), array('file' => $logPath));

$custom_logger->info("My log message!");
WayFarer
  • 1,040
  • 10
  • 19
  • 1
    The important thing here is creating a new instance of Envent dispatcher. If you reference the controller's default event dispatcher, all your logs will go the your custom log file. – Dziamid Jun 08 '11 at 09:28
1
all:
  logger:
    class:   sfAggregateLogger
    param:
      level:   debug
      loggers:
        sf_file_debug:
          class: sfFileLogger
          param:
            level: debug
            file: %SF_LOG_DIR%/%SF_APP%_%SF_ENVIRONMENT%.log
        sf_file_debug_additional:
          class: sfFileLogger
          param:
            level: debug
            file: %SF_LOG_DIR%/%SF_APP%_%SF_ENVIRONMENT%_additional.log
Davide
  • 66
  • 2
0

Check the plugin: sfAdvancedLoggerPlugin. You can do lots of logging things with it.

sfAdvancedLogger allow advanced logging functionality like PHP errors logging, email alerts and conditional logging

j0k
  • 21,914
  • 28
  • 75
  • 84
nacmartin
  • 2,142
  • 18
  • 15