Flex Logger的Firebug target

之前有介紹過Flex Logger跟ThunderBolt 這兩個Logging Framework,雖然Flex原生的就很好用,但Flex只提供trace Target,不像Thoundbolt有Firebug支援,為了開發方便,筆者寫了一個Flex Logger用的Firebug Target,有興趣可以參考


package idv.gd.utils.logging
{
    import flash.external.ExternalInterface;
    import flash.system.Capabilities;
    
    import mx.core.mx_internal;
    import mx.logging.LogEvent;
    import mx.logging.LogEventLevel;
    import mx.logging.targets.LineFormattedTarget;
    use namespace mx_internal;
    
    /**
     * firebug專用 log target
     * @author GD
     * 
     */    
    public class FirebugTarget extends LineFormattedTarget
    {
        private var formattedMessage:String;
        
        public function FirebugTarget()
        {
            super();
        }
        
        /**
         * 取得格式化後的lineFormatted message (內部method)
         * @param message
         * 
         */        
        override mx_internal function internalLog(message:String):void
        {
            formattedMessage = message;
        }
        
        /**
         * 送出訊息給Firebug
         * @param event
         * 
         */        
        override public function logEvent(event:LogEvent):void
        {
            super.logEvent(event);
            
            var message:String = formattedMessage;
            if (ExternalInterface.available) 
            {
                var level:int = event.level;
                switch (level)
                {
                    case LogEventLevel.DEBUG:
                    {
                        ExternalInterface.call("console.debug", message);
                        break;
                    }
                    case LogEventLevel.ERROR:
                    case LogEventLevel.FATAL:
                    {
                        ExternalInterface.call("console.error", message);
                        break;
                    }
                    case LogEventLevel.INFO:
                    {
                        ExternalInterface.call("console.info", message);
                        break;
                    }
                    case LogEventLevel.WARN:
                    {
                        ExternalInterface.call("console.warn", message);
                        break;
                    }
                    default:
                    {
                        ExternalInterface.call("console.log", message);
                        break;
                    }
                }
            }
            //保留trace
            trace(message);
        }

0 意見 :: Flex Logger的Firebug target