加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

Flex Logger的使用

发布时间:2020-12-15 01:42:51 所属栏目:百科 来源:网络整理
导读:包括两部分吧: private function initLogger():void { ??????????? myLogger = Log.getLogger("MyCustomClass"); ??????? } ??????? private function logLifeCycleEvent(e:Event):void { ??????????? if (Log.isInfo()) { ??????????????? myLogger.info("

包括两部分吧:

private function initLogger():void {
??????????? myLogger = Log.getLogger("MyCustomClass");
??????? }

??????? private function logLifeCycleEvent(e:Event):void {
??????????? if (Log.isInfo()) {
??????????????? myLogger.info(" STARTUP: " + e.target + ":" + e.type);
??????????? }
??????? }

??? private function initLogging():void {
??????????? /* Create a target. */
??????????? var logTarget:TraceTarget = new TraceTarget();

??????????? /* Log only messages for the classes in the mx.rpc.* and
?????????????? mx.messaging packages. */
??????????? logTarget.filters=["mx.rpc.*","mx.messaging.*"];

??????????? /* Log all log levels. */
??????????? logTarget.level = LogEventLevel.ALL;

??????????? /* Add date,time,category,and log level to the output. */
??????????? logTarget.includeDate = true;
??????????? logTarget.includeTime = true;
??????????? logTarget.includeCategory = true;
??????????? logTarget.includeLevel = true;

??????????? /* Begin logging. */
??????????? Log.addTarget(logTarget);
??????? }

最佳实践:
? 1. get Logger by class
??? private static const LOG:ILogger = LogUtil.getLogger(MyClass);
? public static function getLogger(c:Class):ILogger
{
??? var className:String =
??????? getQualifiedClassName(c).replace("::",".")
??? return Log.getLogger(className);
}
? 2. 将LOG声明为 静态常量
? 3. format log string consistently
??? LOG.error(
??? "Something bad has happened: event={0},message={1}",
??? event.type,
??? message);
? 4. 使用filter进行过滤,而不是某些特殊字符
??? target.filters = [ "my.important.package.MyClass" ];
??? target.level = LogEventLevel.INFO;
??? ...
??? LOG.info("My important message");
? 5. 在logger输出前加入 if条件
??? for (var i:int = 0; i<10000; i++)
{
??? if (Log.isDebug())
??? {
??????? LOG.debug("Blah blah blah: i={0}",i);
??? }
}

flex端的日志

blaze-DS日志

参考资料:

?? http://hi.baidu.com/%B1%E0%B3%CCabcd/blog/item/6fe0f7bec1928e0319d81fb2.html

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读