Creating a custom logging event

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. Danieyis

    Hola, ya hice los pasos y me sale bien pero solo ene l entorno de desarrollo que puede ser

  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 Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: