之前自己在多个项目中总结了一个log framework,暂时就叫GLLog吧。我觉得很多跟AS3相关的,特别是flex或AIR,需要一个log framework来定义输出信息。flex framework本身也带了个,就是稍显简单。
既然讲到定义输出信息,就不得不考虑目标的多样性,比如trace,普通文本,TextArea,XML,或者远程计算机等等。数是数不过来的,这就需要分离具体实现。
不过在实践过程中,我还发现,输出目标和文本格式最好也分离。比如一行一行的log信息,既可以放到文本文件里,也能显示在TextArea组件中;又如XML格式的log,可以放到本地XML文件,也可以作为dataprovider绑定到某个flex组件中。除此以外,还有一个好处就是,可以将存储和显示分离。格式化的log信息被存储在内存中,按照用户需要才显示或者写入文件。
为了做到让GLLog framework尽量简单和通用,我决定将输出目标排除在外(毕竟种类太过繁多),只提供获得格式化log的接口。
下面是GLLog framework的一个大致结构。
接口GLIWriter就定义了格式化方式(它将会被添加到GLLog并负责格式化信息)。以我自己写的GLPureWriter为例,它的作用就是把log一行一行的窜成字符串(注意:并没有声明输出到哪里)。
package org.gainloss.log
{
import flash.events.Event;
import flash.events.EventDispatcher;
/**
* only pure list
*/
public class GLPureWriter extends EventDispatcher implements GLIWriter
{
public function GLPureWriter()
{
//TODO: implement function
}
private var _list:String = "";
public function pushMsg(msg:String):void
{
//TODO: implement function
_list += msg+"\n"
this.dispatchEvent(new Event("NEWLISTMSG"));
}
[Bindable(name="NEWLISTMSG")]
public function get wholeMsgs():Object
{
//TODO: implement function
return _list;
}
}
}
如果要输出到TextArea显示,可以这么做。
<?xml version="1.0" encoding="utf-8"?>
<mx:Window xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute" width="400" height="300">
<mx:Script>
<![CDATA[
import org.gainloss.log.*;
[Bindable]
private var writer:GLPureWriter = GLLog.getWriterInstance(GLPureWriter) as GLPureWriter;
]]>
</mx:Script>
<mx:VBox [...]
分享到:
相关推荐
自己写 .net Framework
自己封装的framework,里边封装了一些常用的第三方类库。使用起来非常方便
基于Python的robot Framework环境搭建简单一个脚本就搞定!
安装.NET Framework失败后上网找的卸载工具,亲测卸载后可以完成安装.NET Framework。 一下位介绍: ====================== 分享可以完美卸载.NET Framework 1.0~4.5的framework卸载工具。.NET Framework几乎是...
.net framework一键安装工具(自动修复无法安装问题) 所有操作系统(win7/win8/win10...)
appframework分开写html
感谢下载 Microsoft .NET Framework 4.5 注意:Windows 8 和 Windows Server 2012 包括 .NET Framework 4.5。因此,您不必在这些操作系统上安装此软件。 .NET Framework 4.5 是一个针对 .NET Framework 4 的高度...
该工具是自己封装的framework 其中自定义了UIKit的UIActivity和UIActionSheet 后续的自定义UI会持续更新 注意:framework分真机和模拟器 可以通过终端将两者合二为一 适用方法 直接将文件中的framework拖入工程 记得...
.Net Framework 目标包是VS2019开发下载的目标包,包括.net framework3.5 、 .net framework4.0 、 .net framework4.5 vs2022使用.Net Framework4.0方法:,将上述.Net Framework包直接复制粘贴到如下目录下即可:C...
ios中我们写的代码有时不愿意让别人看到,可能对它进行封装,生成一个静态库如典型的.a,还有一种就是和苹果自带的库一样的后缀名为.framework的库,所以我自己生成的framework,里边有一些是我自己整理的方法,具体...
org\springframework\aop org\springframework\beans org\springframework\cache org\springframework\context org\springframework\core org\springframework\dao org\springframework\ejb org\spring...
org.springframework.aop-3.0.4.RELEASE.jar org.springframework.asm-3.0.4.RELEASE.jar org.springframework.aspects-3.0.4.RELEASE.jar org.springframework.beans-3.0.4.RELEASE.jar org.springframework....
Win10系统自带的.net framework版本为4.7,自己安装.NET Framework 4.5.2时会提示:这台计算机中已经安装了 .NET Framework 4.5.2 或版本更高的更新。 解决方法
开发工具 框架JAR spring-framework-4.3.6.RELEASE-dist开发工具 框架JAR spring-framework-4.3.6.RELEASE-dist开发工具 框架JAR spring-framework-4.3.6.RELEASE-dist开发工具 框架JAR spring-framework-4.3.6....
卸载 .NET Framework工具,亲测有效
Create powerful web applications by leveraging the power of this Model-View-Controller-based framework Learn by doing; create a social network from design to deployment Written in a framework and the ...
此工具的主要用途是完全卸载.Net Framework的各种版本,可完美解决.Net Framework安装失败的问题。 .Net Framework安装失败的解决之道:先使用此工具卸载.Net Framework,然后在重新安装.Net Framework,手动至控制...
.NET Framework4.5安装包
This book is an introduction to the well-known Spring Framework that offers an inversion of control container for the Java platform. The Spring Framework is an open source application framework that ...
Table of Contents •Introduction to Zend Framework •Overview •Installation •Learning Zend Framework •Zend Framework Quick Start •Autoloading in Zend Framework •Plugins in Zend Framework •...