flex自定义Log的输出,重写隐藏方法
2008-10-22 10:32
417 查看
flex自带了mx.logging包,跟log4j很像。基本用法挺简单不讲了。
flex同时还实现了两种log的输出方式,在mx.logging.targets包,分别是MiniDebugTarget和TraceTarget(输出到LocalConnection和trace),可是有时候不想用这两种,比如想输出到TextArea显示。注意到这两个都是继承自LineFormattedTarget,看看这类忍不住有点激动了,因为它做了大部分的字符串格式化操作,直接拿来继承就行了。从文档上看它只有logEvent可以重写,而且又不大方便(因为LogEvent里的message不是格式化好的,要了有啥意思)。翻看源码才知道它有一个方法是mx_internal命名空间的,即隐藏的。(不过可以重写)
重写它就显得很简单,看看TraceTarget的源码也是重写它的。下面是自定义输出类
flex同时还实现了两种log的输出方式,在mx.logging.targets包,分别是MiniDebugTarget和TraceTarget(输出到LocalConnection和trace),可是有时候不想用这两种,比如想输出到TextArea显示。注意到这两个都是继承自LineFormattedTarget,看看这类忍不住有点激动了,因为它做了大部分的字符串格式化操作,直接拿来继承就行了。从文档上看它只有logEvent可以重写,而且又不大方便(因为LogEvent里的message不是格式化好的,要了有啥意思)。翻看源码才知道它有一个方法是mx_internal命名空间的,即隐藏的。(不过可以重写)
/** * Descendants of this class should override this method to direct the * specified message to the desired output. * * @param message String containing preprocessed log message which may * include time, date, category, etc. based on property settings, * such as <code>includeDate</code>, <code>includeCategory</code>, * etc. */ mx_internal function internalLog(message:String):void { // override this method to perform the redirection to the desired output }
重写它就显得很简单,看看TraceTarget的源码也是重写它的。下面是自定义输出类
package myvocal.log { import mx.controls.TextArea; import mx.core.mx_internal; import mx.logging.targets.LineFormattedTarget; import mx.logging.LogEventLevel; use namespace mx_internal; public class LogTarget extends LineFormattedTarget { public function LogTarget(tarea:TextArea) { //TODO: implement function super(); this.level = LogEventLevel.INFO; this.includeDate = true; this.includeLevel = true; this.includeTime = true; _textArea = tarea; } private var _textArea:TextArea; mx_internal override function internalLog(message:String):void { _textArea.text += message + "/n"; } } }
相关文章推荐
- iOS开发-重写description方法,自定义控制台(log)信息
- iOS开发-重写description方法,自定义控制台(log)信息
- JTable显示和隐藏列的方法(自定义公用类)
- C#方法重载(overload)方法重写(override)隐藏(new)
- iOS调试技巧之打印输出 -----A: (NSString *)description B:自定义LOG C:使用第三方插件快速打印
- iOS自定义相机输出时崩溃的解决方法+[AVCaptureStillImageOutput jpegStillImageNSDataRepresentation:] - NULL sample buf
- 成员变量隐藏和方法重写5_3 5_4 5_5
- 重写UIView的方法,自定义view
- 自定义Toast, 重写Toast的makeText方法,解决了重复弹toast问题
- 关于FLEX中的隐藏方法(mx_internal)
- [C#]简单重写IComparer接口,实现自己的String.CompareTo 方法,自定义比较规则。
- IE6789浏览器使用console.log类似的方法输出调试内容但又不影响页面正常运行
- Yii2实现log输出到file及database的方法
- 插件: images and custom options,magento添加多图片,自定义选项custom options,catelog,分类的插件以及使用方法!!!
- 自定义view中 通过重写ViewGroup学习onMeasure()和onLayout()方法
- C#方法的重载(overload)、重写(override)、隐藏(new)
- Swift 自定义打印, 自定义输出函数 ,自定义log, Debug
- NSLog显示不全-自定义输出log
- 【ios自学笔记】OC中log信息的输出方法,包含import、字符串、输出日志等知识点
- console.log格式输出全解及console的其他方法