Austin Kottke's Code Site

Thoughts about Architecture – Java, C/C++, JS, Objective-C, Swift, Groovy, Grails, (RIP Flash)
Archive for December, 2010

Well, Ive used this logger a million times and thought it would be useful to let others take a look. The main thing this class supports is FILTERING, which is something that a lot of log classes do not have which I find problematic when dealing with a very large project or want to debug on a live server. Check it out: package com.adk.util { import flash.events.Event; import flash.events.EventDispatcher; import flash.net.URLLoader; import flash.net.URLRequest; import flash.utils.*; /**======================================================================= * * Generic logger that provides filtering so you can specify exactly * classes that should be traced out. You do this by adding in a filter * for a specific class using the logger xml file. * * NOTE: * * Load in the logger xml file by listening for the LOADED event * before dispatching and using logging statements. * * @example * *         var logger:FlashLogger = FlashLogger.getLogger( this, “path.to/logger.xml” ); *             logger.addEventListener( FlashLogger.LOADED, onLoggerLoad ); * *        public function onLoggerLoad( event:Event ):void *        { *            var logger:FlashLogger = FlashLogger.getLogger( this ); *            logger.debug(“Test”, “param2”); *        } * * * Specify log filters in logger.xml: * * <?xml version=”1.0″ ?> * <Logger logLevel=”DEBUG”> * <filters>com.adobe, com.adk.util</filters> * </Logger> * * You can add as many filters you want and specify the log level. * * @author Austin Kottke *=======================================================================*/ public class FlashLogger extends EventDispatcher { /*============================================================================ * Events and log types. *============================================================================*/ public static var NONE : uint = 0; public static var INFO : uint = 1; public static var DEBUG : uint = 2; public static var WARN : uint = 3; public static var ERROR : uint = 4; public static var FATAL : uint = 5; /*============================================================================ * Variables *============================================================================*/ public static var LOG_TYPES : Array; private static var logLevel : int; private static var filters : Array = new Array(); private static var filtersLoaded : Boolean = false; private static var created : Boolean = false; public var className : String ; /*============================================================================ * EVENTS *============================================================================*/ public static var LOADED : String = “xmlLoaded”; /********************************************************************************** * Adds in a new filter * * @param aString Adds in a new filter for the logger. **********************************************************************************/ public function addFilter( aString : String ) { FlashLogger.filters.push(aString); trace(“FlashLogger.addFilter(” + aString + “)”); } /********************************************************************************** * Checks if the class is in the filter. * * @return true or false if the class is in the filter or if there are no filters. **********************************************************************************/ private function isClassInFilter( aClassName : String ) : Boolean { for ( var i : Number = 0;i < filters.length;i++ ) if ( aClassName.indexOf(filters[i]) >= 0 ) return true; if ( filters.length == 0 ) return true; return false; } /********************************************************************************** *  Constructor **********************************************************************************/ public function FlashLogger( aClassName : String, loggerXMLPath : String ) { className = aClassName; if ( !created ) { FlashLogger.LOG_TYPES = new Array(“NONE”, “INFO”, “DEBUG”, “WARN”, “ERROR”, “FATAL”); setLogLevel(DEBUG); created =…

So I’ve been doing a lot of java/ajax development recently, and having to compare frameworks was one of the main things I’ve had to do. I used JSF 1.2 actually due to legacy server issues, not 2.0 (which I hear is a lot better) but comparing it with Stripes/Wicket I must say that: 1. JSF has a LOT of issues integrating into existing browsers, 2.0 is probably a bit better but sometimes the pain of having to have ALL tags written for you is VERY troublesome. I recently had to use a rich faces fileupload component and the integration on some browsers has major issues. While it is good to have a very tightly integrated ajax framework it sometimes is painful when trying to integrate in something like the YUI components. 2. Stripes/Wicket are good because they leave a lot of the ajax development to yourself and provide a VERY awesome hands on approach where you can actually write your own code with minimal development time. I find this actually was easier on some other projects. So in a nut shell… Id stick with Stripes/Wicket for a java serverside application as opposed to straight JSF as it is sometimes painful when dealing with all the pre-written javascript components. I guess this brings up a philosophy: 1. A java server side framework should NEVER be so tightly binded to the front-end UI logic WHEN you are depending on browser support. Or provide some alternative to use the latest prototype/ajax libraries. 2. If it is tightly binded,…