Firephp log appender for log4php

August 30th, 2009

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));
	}
}

Using the C Preprocessor in web application development

January 2nd, 2009

I use a lot of existing tools for managing and building my software projects.  One of those is the C preprocessor (CPP).  It’s been around for years, is available on pretty much every flavor of UNIX/Linux including Mac OS X (with XCode installed), and allows me to write code with logging and tests in-line with the ability to have that code stripped out in my build process by simply using a single setting.  In Javascript for example, I might have some code like this:

function foo(var) {
    //do something with var
    ...
    #if DEBUG_VERSION
    #include "debug.js"
    console.log('foo called with: ' + var);
    #endif
}

Now as part of my build process, I run cpp against this file as either a debug version, or a production version.

Using ‘cpp -P -C -DDEBUG_VERSION=1′ will include the debug.js library, leave comments intact, and leave the console logging statements. Building a production version by preprocessing the source file(s) using ‘cpp -P -DDEBUG_VERSION=0′ strips ALL comments, and does not include any of the conditional code used in the debug version.

This allows me to write and debug code very rapidly, as well as use a lot of notes and comments - and for production, all of that gets removed automagically.  Using this within an Ant build for example, I can combine this task with other tasks (like concatenating multiple Javascript files and compressing them using the YUI compressor) I have a very versatile and easy to use setup.  I will post later about my build process, and using Ant in particular in the next couple of weeks.

Server Status for the iPhone

December 22nd, 2008

I have completed RC1 of the Server Status web application for the iPhone.  I plan on forking the code for another project that will include portions of the SliceHost API for server management.  Download, and details to follow soon, but for now here are a couple of screen shots:

Download

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.