Skip to content

Instantly share code, notes, and snippets.

@skinofstars
Created January 28, 2013 11:59
Show Gist options
  • Save skinofstars/4654952 to your computer and use it in GitHub Desktop.
Save skinofstars/4654952 to your computer and use it in GitHub Desktop.
Just the a quick knock-up to add monolog to a class. You could just instantiate the logger in the function you're debugging, but this makes it easier to bounce around the class.
<?php
use Monolog\Logger;
use Monolog\Handler\StreamHandler;
class foo extends bar
{
private $log = null;
public function __construct($swiftmailer, $service_container)
{
// if your class extends, make sure you check for the parents constructor and pass whatever you need
parent::__construct($swiftmailer, $service_container);
$this->log = new Logger('name');
$this->log->pushHandler(new StreamHandler('/path/to/app/logs/audit.log', Logger::WARNING));
}
public function whateverNeedsDebugging()
{
$this->log->addWarning('Foo');
$this->log->addError('Bar');
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment