In order to create a logging event that logs specific data to a seperate file, simply create a sfFileLogger instance and connect it to your application’s event dispatcher.

In apps/frontend/config/frontendConfiguration.class.php

class frontendConfiguration extends sfApplicationConfiguration
{
  public function configure()
  {
    $mylogger = new sfFileLogger(new sfEventDispatcher, array(
      ’file=> $this->getRootDir()./log/mylog.log‘
    ));
    $this->dispatcher->connect(‘mylog.log‘, array($mylogger, ‘listenToLogEvent‘));
  }
}

Now, you can log into that file by notifying the event from anywhere in your application :

 

$dispatcher = sfContext::getInstance()->getEventDispatcher();
$dispatcher->notify(new sfEvent($this, ‘mylog.log‘, array(‘hello‘)));

  1. 1 Logging on 1.1 tasks « Symfony scales and arpeggios

    [...] scales and arpeggios Symfony development blog About « Logging in Symfony 1.1 Creating a custom logging event [...]




Leave a Comment