Created
November 27, 2010 18:57
-
-
Save Stray/718163 to your computer and use it in GitHub Desktop.
Easy logging in robotlegs through events
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // code required in your context startup - this uses Config::Variables to set the logger at compile time, | |
| // but you could just swap it in/out as required and do away with the if/else etc | |
| commandMap.mapEvent(LoggingEvent.LOG_EVENT, UpdateLogCommand, LoggingEvent); | |
| if(CONFIG::HiddenLogging) | |
| { | |
| injector.mapSingletonOf(ILoggingService, TraceLoggingService); | |
| } | |
| else if(CONFIG::EmailLogging) | |
| { | |
| injector.mapSingletonOf(ILoggingService, EmailLoggingService); | |
| } | |
| else | |
| { | |
| var hideableLogTextView:HideableLogTextView = new HideableLogTextView(); | |
| contextView.addChild(hideableLogTextView); | |
| var logTextField:TextField = hideableLogTextView.logTextField; | |
| // you can map any textfield to this value | |
| injector.mapValue(TextField, logTextField, "logTextField"); | |
| injector.mapSingletonOf(ILoggingService, TextFieldLoggingService); | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| package utils.loggingmodule.api { | |
| import flash.events.Event; | |
| public class LoggingEvent extends Event { | |
| //-------------------------------------- | |
| // CLASS CONSTANTS | |
| //-------------------------------------- | |
| public static const LOG_EVENT : String = "logEvent"; | |
| public static const LEVEL_DEBUG : String = "Debug"; | |
| public static const LEVEL_WARNING : String = "Warning"; | |
| public static const LEVEL_ERROR : String = "Error"; | |
| public static const LEVEL_INFO : String = "Info"; | |
| public static const LEVEL_FATAL : String = "Fatal" | |
| private var _level:String; | |
| private var _message:String; | |
| private var _sender:String; | |
| private var _dateTimeString:String; | |
| //-------------------------------------- | |
| // CONSTRUCTOR | |
| //-------------------------------------- | |
| /** | |
| * @constructor | |
| */ | |
| public function LoggingEvent( type:String, message:String, level:String, sender:*, bubbles:Boolean=true, cancelable:Boolean=false ) | |
| { | |
| _message = message; | |
| _level = level; | |
| _sender = Object(sender).toString(); | |
| _dateTimeString = new Date().toString(); | |
| super(type, bubbles, cancelable); | |
| } | |
| //-------------------------------------- | |
| // GETTER/SETTERS | |
| //-------------------------------------- | |
| public function get level():String{ | |
| return _level; | |
| } | |
| public function get message():String{ | |
| return _message; | |
| } | |
| public function get sender():String{ | |
| return _sender; | |
| } | |
| public function get dateTimeString():String{ | |
| return _dateTimeString; | |
| } | |
| override public function toString():String{ | |
| var str:String = _dateTimeString + "::" + _level + " -> [" + _message + "] by " + _sender; | |
| return str; | |
| } | |
| //-------------------------------------- | |
| // PUBLIC METHODS | |
| //-------------------------------------- | |
| override public function clone() : Event { | |
| return new LoggingEvent(type, _message, _level, _sender, bubbles, cancelable); | |
| } | |
| } | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| package utils.loggingmodule.restricted.controller { | |
| import org.robotlegs.mvcs.Command; | |
| import utils.loggingmodule.restricted.services.ILoggingService; | |
| import utils.modules.loggingmodule.api.LoggingEvent; | |
| public class UpdateLogCommand extends Command{ | |
| [Inject] | |
| public var loggingService:ILoggingService; | |
| [Inject] | |
| public var loggingEvent:LoggingEvent; | |
| public function UpdateLogCommand() { | |
| } | |
| override public function execute():void { | |
| loggingService.logEvent(loggingEvent); | |
| } | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment