Skip to content

Instantly share code, notes, and snippets.

@squeedee
Created August 1, 2010 20:58
Show Gist options
  • Save squeedee/503760 to your computer and use it in GitHub Desktop.
Save squeedee/503760 to your computer and use it in GitHub Desktop.
Really Helpful commandMap logging for your Robotlegs apps
package com.visfleet.robotlegs {
import com.visfleet.core.isNotNull;
import flash.events.Event;
import flash.events.IEventDispatcher;
import mx.logging.ILogger;
import mx.logging.Log;
import org.robotlegs.base.CommandMap;
import org.robotlegs.core.IInjector;
import org.robotlegs.core.IReflector;
public class LoggingCommandMap extends CommandMap {
private var logger:ILogger;
public function LoggingCommandMap(eventDispatcher:IEventDispatcher, injector:IInjector, reflector:IReflector) {
logger = Log.getLogger("CommandMap");
super(eventDispatcher, injector, reflector);
}
override public function mapEvent(eventType:String, commandClass:Class, eventClass:Class = null, oneshot:Boolean = false):void {
logger.debug("ADD {0} to {1}. Class={2} OneShot={3}",eventType,reflector.getFQCN(commandClass,true),reflector.getFQCN(eventClass,true),oneshot.toString());
super.mapEvent(eventType, commandClass, eventClass, oneshot);
}
override public function unmapEvent(eventType:String, commandClass:Class, eventClass:Class = null):void {
logger.debug("REMOVE {0} from {1}. Class={2}",eventType,reflector.getFQCN(commandClass,true),reflector.getFQCN(eventClass,true));
super.unmapEvent(eventType, commandClass, eventClass);
}
override public function unmapEvents():void {
logger.debug("REMOVE ALL");
super.unmapEvents();
}
override public function execute(commandClass:Class, payload:Object = null, payloadClass:Class = null, named:String = ''):void {
logger.debug("EXEC {0}. Named={1} HasPayload={2}",reflector.getFQCN(commandClass,true),named,isNotNull(payload));
super.execute(commandClass, payload, payloadClass, named);
}
override protected function routeEventToCommand(event:Event, commandClass:Class, oneshot:Boolean, originalEventClass:Class):Boolean {
logger.debug("ROUTE {0} to {1}. OneShot={2}",reflector.getFQCN(event,true),reflector.getFQCN(commandClass,true),oneshot.toString());
return super.routeEventToCommand(event, commandClass, oneshot, originalEventClass);
}
}
}
package com.visfleet.vWork
{
import com.visfleet.robotlegs.LoggingCommandMap;
import flash.display.DisplayObjectContainer;
import mx.logging.Log;
import org.robotlegs.base.ContextEvent;
import org.robotlegs.core.ICommandMap;
import org.robotlegs.mvcs.Context;
public class YourContext extends Context {
public function YourContext(contextView:DisplayObjectContainer=null, autoStartup:Boolean=true) {
super(contextView, autoStartup);
}
override protected function set commandMap(value:ICommandMap):void {
super.commandMap = value;
}
override protected function get commandMap():ICommandMap {
if (Log.isDebug()) {
return _commandMap || (_commandMap = new LoggingCommandMap(eventDispatcher, injector.createChild(), reflector));
} else {
return super.commandMap;
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment