/**
  * Console logger class constructor
  *
  * @param string $name  The logging channel
  * @param string $level The minimum logging level
  */
 public function __construct($name = 'YourLogger', $level = Logger::DEBUG)
 {
     $filterRules = array(function ($record) {
         if (!array_key_exists('operation', $record['context'])) {
             return false;
         }
         return 'printFooter' === $record['context']['operation'];
     });
     $stream = new RotatingFileHandler(__DIR__ . '/phpunit-growlhandler-php' . PHP_VERSION_ID . '.log', 30);
     $stream->setFilenameFormat('{filename}-{date}', 'Ymd');
     $console = new StreamHandler('php://stdout');
     $console->setFormatter(new LineFormatter("%message%\n", null, true));
     $filter = new FilterHandler($console);
     $handlers = array($filter, $stream);
     try {
         $options = array('resourceDir' => dirname(__DIR__) . '/vendor/pear-pear.php.net/Net_Growl/data/Net_Growl/data', 'defaultIcon' => '80/growl_phpunit.png');
         $growl = new GrowlHandler(array('name' => 'PHPUnit ResultPrinter', 'options' => $options), Logger::NOTICE);
         $growl->setFormatter(new LineFormatter("Growl for Monolog\n" . "%message%"));
         $handlers[] = new CallbackFilterHandler($growl, $filterRules);
     } catch (\Exception $e) {
         // Growl server is probably not started
     }
     parent::__construct($name, $handlers);
 }
 /**
  *  covers Bartlett\Monolog\Handler\GrowlHandler::handle
  *  covers Bartlett\Monolog\Handler\GrowlHandler::pushProcessor
  *  covers Bartlett\Monolog\Handler\GrowlHandler::setFormatter
  */
 public function testHandleUsesProcessors()
 {
     $sender = 'PHP 7.0.0-dev';
     $record = $this->getRecord(Logger::WARNING, 'caution message');
     $record['extra']['sender'] = $sender;
     $formatter = new LineFormatter("%message%\n%level_name%\n%extra.sender%");
     $this->growl->expects($this->any())->method('notify')->with($record['level_name'], $record['channel'], $formatter->format($record));
     $handler = new GrowlHandler($this->growl);
     $handler->setFormatter($formatter);
     $handler->pushProcessor(function ($record) use($sender) {
         $record['extra']['sender'] = $sender;
         // 'PHP ' . phpversion();
         return $record;
     });
     $handler->handle($record);
 }
        return true;
    }
    if (!array_key_exists('exception', $record['context'])) {
        return false;
    }
    return preg_match('/^An error has occured/', $record['message']) === 1;
});
// Create some handlers
$stream = new RotatingFileHandler(__DIR__ . DIRECTORY_SEPARATOR . 'growl_conf.log');
$stream->setFilenameFormat('{filename}-{date}', 'Ymd');
$logger->pushHandler($stream);
try {
    $resourceDir = __DIR__ . DIRECTORY_SEPARATOR . 'images' . DIRECTORY_SEPARATOR;
    $notifications = array(GrowlHandler::DEBUG => array('icon' => $resourceDir . 'green.png'), GrowlHandler::INFO => array('icon' => $resourceDir . 'green.png'), GrowlHandler::NOTICE => array('icon' => $resourceDir . 'yellow.png'), GrowlHandler::WARNING => array('icon' => $resourceDir . 'yellow.png'), GrowlHandler::ERROR => array('icon' => $resourceDir . 'red.png'), GrowlHandler::CRITICAL => array('icon' => $resourceDir . 'red.png'), GrowlHandler::ALERT => array('icon' => $resourceDir . 'red.png'), GrowlHandler::EMERGENCY => array('icon' => $resourceDir . 'red.png'));
    $options = array('AppIcon' => dirname(__DIR__) . '/vendor/pear-pear.php.net/Net_Growl/data/Net_Growl/data/128/growl-starkicon.png');
    $growl = new GrowlHandler(array('name' => 'My Custom Growl', 'notifications' => $notifications, 'options' => $options));
    $growl->setFormatter(new LineFormatter("%message%\n%level_name%"));
    $logger->pushHandler(new CallbackFilterHandler($growl, $filters));
} catch (\Exception $e) {
    // Growl server is probably not started
    echo $e->getMessage(), PHP_EOL, PHP_EOL;
}
// You can now use your logger
$logger->addInfo('My logger is now ready');
// This record won't be stopped by the $filters rules, but by the growl $notifications config
$logger->addDebug('A debug message.');
$logger->addError('An error has occured. Will be logged to file BUT NOT notified by Growl.');
try {
    throw new \RuntimeException();
} catch (\Exception $e) {
    $logger->addCritical('An error has occured. Will be logged to file AND notified by Growl.', array('exception' => $e));