Firephp log appender for log4php

I’ve been using Zend Framework lately on a couple of projects, but I’m not very fond of the framework’s logger (Zend_Log).  There are some nice features of log4php (daily log, rolling log, tcp logger, etc.) that make it by far the best logger out there (and the project has been restarted after a few years of inactivity, with a nice rewrite for PHP5 (svn only at this point)).  I decided to create an appender for Firephp to use during development.  For autoloading, you will need to add it to the class list in Logger.php.

/** Zend_Wildfire_Plugin_FirePhp */
require_once 'Zend/Wildfire/Plugin/FirePhp.php';
 
class LoggerAppenderFirephp extends LoggerAppender {
 
	public function __construct($name = '') {
		parent::__construct($name);
		$this->requiresLayout = false;
	}
 
	public function __destruct() {
       $this->close();
   	}
 
	public function activateOptions() {
		$this->closed = false;
	}
 
	public function close() {
		$this->closed = true;
	}
 
	public function append($event) {
			$level = $event->getLevel();
			$tl = strtolower($level->toString());
			switch($tl) {
				case 'debug':
					$log_level = Zend_Wildfire_Plugin_FirePhp::LOG;
					break;
				case 'info':
					$log_level = Zend_Wildfire_Plugin_FirePhp::INFO;
					break;
				case 'warn':
					$log_level = Zend_Wildfire_Plugin_FirePhp::WARN;
					break;
				case 'error':
					$log_level = Zend_Wildfire_Plugin_FirePhp::ERROR;
					break;
				case 'fatal':
					$log_level = Zend_Wildfire_Plugin_FirePhp::ERROR;
					break;
				default:
					$log_level = Zend_Wildfire_Plugin_FirePhp::INFO;
			}
	        Zend_Wildfire_Plugin_FirePhp::getInstance()->send('[' . $level->toString() . '] - ' . $event->getRenderedMessage(),
	                                                          null,
	                                                          $log_level,
	                                                          array('traceOffset'=>6));
	}
}

Leave a Reply

About Binary Signal

A small web application and software development company located in Portland, Oregon.

Small Business

As a small business owner myself, I am committed to supporting small businesses and using local resources when needed. If you are a small business in the Portland metro area, ask me about a discounted hourly rate.