zoukankan      html  css  js  c++  java
  • Flex AIR程序日志工具类LogUtil

    Flex默认集成了一个功能齐全的Logging框架,它位于mx.logging包下。as3corelib类库中的类com.adobe.air.logging.FileTarget对Flex logging进行了一定的封装,可以在AIR程序中自由设置日志文件的存储路径以及添加了个清除所有日志的功能。由于实际项目的需求,在FileTarget类的基础上,我进行了再封装。新封装的LogUtils工具类不仅可以控制日志输出的目的地,还可以控制日至输出级别,便于调试和发布。

    鉴于对工具类使用的讲解,简要说明下官方Logging框架。详细信息请参阅官方文档:http://livedocs.adobe.com/flex/3/html/help.html?content=logging_09.html

    The logging API 由下面几部分组成:

    1. Logger:在日志记录框架中使用的记录程序, 提供了接口发送log到一个特定的target,它实现了ILogger接口。
    2. Log target:定义了日志将会被写到哪里。Flex提供了最常用的日志目标TraceTarget。 This log target connects the logging API to the trace system so that log messages are sent to the same location as the output of the trace() method.
    3. Destination: The destination is where the log message is written. Typically, this is a file, but it can also be a console or something else, such as an in-memory object. The default destination for TraceTarget is the flashlog.txt file. You configure this destination on the client.

    LogUtils工具类使用示例:

      LogDemo

    日志输出:

    7/29/2011 10:43:54.292 [INFO] LogDemo preinitializeHandler

    7/29/2011 10:43:54.292 [DEBUG] LogDemo preinitializeHandler

    7/29/2011 10:43:54.292 [INFO] LogDemo initializeHandler

    7/29/2011 10:43:54.292 [DEBUG] LogDemo initializeHandler

    7/29/2011 10:43:54.370 [INFO] LogDemo creationCompleteHandler

    7/29/2011 10:43:54.370 [DEBUG] LogDemo creationCompleteHandler

    7/29/2011 10:43:54.385 [INFO] LogDemo addedToStageHandler

    7/29/2011 10:43:54.385 [DEBUG] LogDemo addedToStageHandler

    7/29/2011 10:43:54.385 [INFO] LogDemo 请跟我说:我是一个优秀的MT

    注: Log target默认的filters为"*",故日志文件可能会打出下面包的类中的日志记录

    mx.rpc.*
    mx.messaging.*
    mx.data.*

    将日志级别 设置为LogEventLevel.ERROR以上,上述包中的日志就基本看不到了

    LogUtil下载地址:https://files.cnblogs.com/god_bless_you/LogUtil.rar

    转载请表明出处:http://www.cnblogs.com/god_bless_you

    作者:God bless you
    本文版权归作者,欢迎转载,但未经作者同意必须保留此段声明,且在文章页面明显位置给出原文连接,否则保留追究法律责任的权利.
  • 相关阅读:
    信息检索笔记
    北大课程(变态心理学)
    My life
    Excel小技巧(随机点名)
    Flask基础
    CTF
    GDB
    LD_PRELOAD
    AFL-数据变异
    AFL入门
  • 原文地址:https://www.cnblogs.com/god_bless_you/p/2120826.html
Copyright © 2011-2022 走看看