Logging Component

With the logging component we wanted to structure the logging strategy. That's why the component includes a logger interface based on the PSR-3 recommendation.

This component also provides two implementations of the interface: the DirectOutputLogger class which logs to the standard output, and the FileLogger class, which logs to a file.

Changing the logger

$container['wwp.log.log'] = $container->factory(function () {
    return new DirectOutputLogger(); //Or any logger that implements the PSR-3 interface
});

Using the logging component

In your manager, register a service that would use the logger reference from the container, not the class.

public function register(Container $container) { parent::register($container);

$this->addService('mailHandler', function () use($container) {
    return new ServiceThatNeedsToLogThings($container['wwp.log.log']);
});   

}

This will automatically change the logger used in your service if you redefine the logger in the container.

Then in your service you have access to a class that implements the logger interface.