日志包装类

package log
{import com.adobe.air.logging.FileTarget;import flash.filesystem.File;import flash.filesystem.FileMode;import flash.filesystem.FileStream;import mx.logging.ILogger;import mx.logging.Log;import mx.logging.LogEventLevel;/***  AIR程序中记录日志的工具类 (对as3corelib官方类库中类com.adobe.air.logging.FileTarget的封装)*  *  @author Sakura*  博客地址:http://www.cnblogs.com/god_bless_you*/public final class LogUtil{private static var _fileTarget:FileTarget;private static var _level:int = LogEventLevel.ALL;/***  Provides access to the level this target is currently set at.*  Value values are:*    <ul>*      <li><code>LogEventLevel.FATAL (1000)</code> designates events that are very*      harmful and will eventually lead to application failure</li>**      <li><code>LogEventLevel.ERROR (8)</code> designates error events that might*      still allow the application to continue running.</li>**      <li><code>LogEventLevel.WARN (6)</code> designates events that could be*      harmful to the application operation</li>**      <li><code>LogEventLevel.INFO (4)</code> designates informational messages*      that highlight the progress of the application at*      coarse-grained level.</li>**      <li><code>LogEventLevel.DEBUG (2)</code> designates informational*      level messages that are fine grained and most helpful when*      debugging an application.</li>**      <li><code>LogEventLevel.ALL (0)</code> intended to force a target to*      process all messages.</li>*    </ul>*  */public static function get level():int{return _level;}public static function set level(value:int):void{// A change of level may impact the target level for Log.if (checkFileTarget()){Log.removeTarget(_fileTarget);_fileTarget = null;_level = value;        }initLogging();        }private static var _logFilePath:String = File.applicationDirectory.resolvePath( "Logs\\main.log" ).nativePath;
//        File.applicationDirectorypublic static function get logFilePath():String{return _logFilePath;}public static function set logFilePath(value:String):void{if (checkFileTarget()){Log.removeTarget(_fileTarget);_fileTarget = null;_logFilePath = value;        }initLogging();        }private static function getLogger(category:String):ILogger{return Log.getLogger(category);}private static function initLogging():void{if (checkFileTarget())return;trace("logpath:"+_logFilePath);var file:File = new File(_logFilePath);    var filestrm:FileStream = new FileStream;filestrm.open(file,FileMode.WRITE);filestrm.writeInt(0);filestrm.close();trace("清除日志"+file.exists+""+file.nativePath);_fileTarget = new FileTarget(file);                                    _fileTarget.level = _level;                _fileTarget.includeDate = true;_fileTarget.includeTime = true;_fileTarget.includeCategory = true;_fileTarget.includeLevel = true;                Log.addTarget(_fileTarget);}private static function checkFileTarget():Boolean{return (_fileTarget) ? true : false;}private static function generateMessage(message:String,rest:Array):String{for (var i:int = 0; i < rest.length; i++){message = message.replace(new RegExp("\\{"+i+"\\}", "g"), rest[i]);}return message;}/***  Logs the specified data using the <code>LogEventLevel.DEBUG</code>*  level.*  <code>LogEventLevel.DEBUG</code> designates informational level*  messages that are fine grained and most helpful when debugging*  an application.*  *  <p>The string specified for logging can contain braces with an index*  indicating which additional parameter should be inserted*  into the string before it is logged.*  For example "the first additional parameter was {0} the second was {1}"*  will be translated into "the first additional parameter was 10 the*  second was 15" when called with 10 and 15 as parameters.</p>**  @param category The category for which this log sends messages.* *  @param message The information to log.*  This string can contain special marker characters of the form {x},*  where x is a zero based index that will be replaced with*  the additional parameters found at that index if specified.**  @param rest Additional parameters that can be subsituted in the str*  parameter at each "{<code>x</code>}" location, where <code>x</code>*  is an integer (zero based) index value into the Array of values*  specified.* */public static function debug(category:String, message:String, ... rest):void{initLogging();if (Log.isDebug()){var logger:ILogger = getLogger(category);logger.debug(generateMessage(message,rest));}}/***  Logs the specified data using the <code>LogEvent.INFO</code> level.*  <code>LogEventLevel.INFO</code> designates informational messages that *  highlight the progress of the application at coarse-grained level.*  *  <p>The string specified for logging can contain braces with an index*  indicating which additional parameter should be inserted*  into the string before it is logged.*  For example "the first additional parameter was {0} the second was {1}"*  will be translated into "the first additional parameter was 10 the*  second was 15" when called with 10 and 15 as parameters.</p>**  @param category The category for which this log sends messages.* *  @param message The information to log.*  This String can contain special marker characters of the form {x},*  where x is a zero based index that will be replaced with*  the additional parameters found at that index if specified.**  @param rest Additional parameters that can be subsituted in the str*  parameter at each "{<code>x</code>}" location, where <code>x</code>*  is an integer (zero based) index value into the Array of values*  specified.**/public static function info(category:String, message:String, ... rest):void{initLogging();if (Log.isInfo()){    var logger:ILogger = getLogger(category);logger.info(generateMessage(message,rest));}}/***  Logs the specified data using the <code>LogEventLevel.WARN</code> level.*  <code>LogEventLevel.WARN</code> designates events that could be harmful *  to the application operation.*      *  <p>The string specified for logging can contain braces with an index*  indicating which additional parameter should be inserted*  into the string before it is logged.*  For example "the first additional parameter was {0} the second was {1}"*  will be translated into "the first additional parameter was 10 the*  second was 15" when called with 10 and 15 as parameters.</p>*  *  @param category The category for which this log sends messages.* *  @param message The information to log.*  This String can contain special marker characters of the form {x},*  where x is a zero based index that will be replaced with*  the additional parameters found at that index if specified.**  @param rest Aadditional parameters that can be subsituted in the str*  parameter at each "{<code>x</code>}" location, where <code>x</code>*  is an integer (zero based) index value into the Array of values*  specified.**/public static function warn(category:String, message:String, ... rest):void{initLogging();if (Log.isWarn()){    var logger:ILogger = getLogger(category);logger.warn(generateMessage(message,rest));}}/***  Logs the specified data using the <code>LogEventLevel.ERROR</code>*  level.*  <code>LogEventLevel.ERROR</code> designates error events*  that might still allow the application to continue running.*  *  <p>The string specified for logging can contain braces with an index*  indicating which additional parameter should be inserted*  into the string before it is logged.*  For example "the first additional parameter was {0} the second was {1}"*  will be translated into "the first additional parameter was 10 the*  second was 15" when called with 10 and 15 as parameters.</p>**  @param category The category for which this log sends messages.* *  @param message The information to log.*  This String can contain special marker characters of the form {x},*  where x is a zero based index that will be replaced with*  the additional parameters found at that index if specified.**  @param rest Additional parameters that can be subsituted in the str*  parameter at each "{<code>x</code>}" location, where <code>x</code>*  is an integer (zero based) index value into the Array of values*  specified.**/public static function error(category:String, message:String, ... rest):void{initLogging();if (Log.isError()){var logger:ILogger = getLogger(category);logger.error(generateMessage(message,rest));}}/***  Logs the specified data using the <code>LogEventLevel.FATAL</code> *  level.*  <code>LogEventLevel.FATAL</code> designates events that are very *  harmful and will eventually lead to application failure**  <p>The string specified for logging can contain braces with an index*  indicating which additional parameter should be inserted*  into the string before it is logged.*  For example "the first additional parameter was {0} the second was {1}"*  will be translated into "the first additional parameter was 10 the*  second was 15" when called with 10 and 15 as parameters.</p>**  @param category The category for which this log sends messages.* *  @param message The information to log.*  This String can contain special marker characters of the form {x},*  where x is a zero based index that will be replaced with*  the additional parameters found at that index if specified.**  @param rest Additional parameters that can be subsituted in the str*  parameter at each "{<code>x</code>}" location, where <code>x</code>*  is an integer (zero based) index value into the Array of values*  specified.**/public static function fatal(category:String, message:String, ... rest):void{initLogging();if (Log.isFatal()){var logger:ILogger = getLogger(category);logger.fatal(generateMessage(message,rest));}}/***  Clear all logs.*/public static function clear():void{initLogging();_fileTarget.clear();}}
}

需要依赖:as3corelib库

转载于:https://www.cnblogs.com/sagech/p/5671498.html

Flex桌面AIR软件日志添加相关推荐

  1. Linux-Kali——安装软件_添加桌面快捷方式启动器_添加到应用程序菜单_Kali安装Typora

    文章目录 前言 一.下载安装包 二.归档 三.测试运行 四.添加桌面快捷方式(启动器) Ⅰ.使用终端 Ⅱ.添加启动器 五.添加到应用程序菜单 完 前言 记一次安装Typora的操作,系统是Kali 一 ...

  2. 非常实用的桌面排版软件,Affinity Publisher集成了首字下沉、基线网格、艺术文本以及文字装饰等优秀的排版功能

    Affinity Publisher是一款非常实用的桌面排版软件,Affinity Publisher集成了首字下沉.基线网格.艺术文本以及文字装饰等优秀的排版功能,能够为从事书籍.杂志.画册以及海报 ...

  3. 一款功能强大的桌面摄影软件—lightroom classic 2021

    lightroom classic 2021是一款功能强大的桌面摄影软件,让用户可以创作精美绝伦的照片,在桌面上轻松整理所有照片.您的照片并不一定总能完美地展现您要留存的景物,但使用该款软件您可以获得 ...

  4. 软件日志(系统日志)

    自己是个C#菜鸟,写了些小东西,但是调试起来总是很麻烦.后来发现大牛们都用什么"日志"来记录软件执行的操作(好像叫软件日志还是系统日志,我就暂取软件日志),这样便于调试,还有就是在 ...

  5. Windows/Linux 下功能强大的桌面截图软件

    说到桌面截图软件,很多人首先想到的是 QQ 自带的截图,或者更高级功能更强大的 Snipaste 截图工具. 独立版本的 QQ 截图至少我目前没找到官方正式的下载链接,默认需要安装和打开 QQ 才能使 ...

  6. Flex及AIR开发资源集合

    这篇文章是我在平时经常用到或者收藏的相关于Flex与AIR开发的资源集合,在这里列出来给各位共享,同时也是便于以后自己使用.(将来会按照列表资源的URL更新而改动,版本更新就不做更改了) 开发工具 F ...

  7. Joplin笔记 android,Joplin(桌面云笔记软件)

    Joplin是一款桌面云笔记软件,开源而免费,可以处理笔记本中组织的大量笔记,支持Markdown格式,可以直接从应用程序或您自己的文本编辑器中复制.标记和修改! 软件介绍 Joplin是一个免费的开 ...

  8. oppor9桌面布局设置_oppor9添加桌面图标

    oppoR9怎样隐藏桌面图标 机子本身是不带隐藏功能的.如果想隐藏图标,可以下载一个桌面软件再隐藏哦~ oppor9splus桌面图标怎么恢复默认图标? oppor9splus系统可以在手机桌面通过两 ...

  9. 推荐4款最好用的远程桌面访问软件,亲测好评

    远离计算机并不意味着您不能使用它.远程访问软件可让您从远处控制您的计算机或其他人的计算机.这些是我们测试过的顶级远程访问工具. 远程访问软件使您可以随时随地访问计算机上的所有内容.无论您是需要快速检查 ...

  10. 想给你的Mac换个可心的高清壁纸?Mac好用的桌面壁纸软件推荐

    担心找不到好看的Mac壁纸?我想你可能缺少一款好用的Mac高清桌面壁纸软件!每天都要用电脑来学习.工作,每天看到同样的电脑桌面难道不无聊么?给自己的Mac电脑换个好看的高清动态壁纸,每天给自己一个好心 ...

最新文章

  1. python pyOpenGL安装
  2. 0基础学python-零基础直接学习Python入门IT合适吗?
  3. MySQL存储过程详解 mysql 存储过程
  4. Java 洛谷 P1534 不高兴的津津(升级版)
  5. 什么意思_手机HD是什么意思 手机信号区显示hd是什么意思
  6. tensorrt轻松部署高性能dnn推理_部署环境之:tensorRT的插件
  7. Acwing 276. I-区域
  8. 图书推荐(持续更新)
  9. Spark学习之RDD的概念
  10. net.sz.framework 框架 ORM 消消乐超过亿条数据排行榜分析 天王盖地虎
  11. 【vim环境配置】解决ubuntu上 由YouCompleteMe插件配置不当引起的 自动补全失效的问题
  12. 关于SQL语句中的双引号、单引号和
  13. HDFS教程(06)- HDFS纠删码
  14. 一篇文章教你,破解百度网盘加密文件,学会这个举一反二
  15. php screw.so,php_screw
  16. 网购火车票全攻略(新手+进阶+高手级)
  17. IO多路复用和epoll反应堆
  18. 最通俗易懂——TCP/IP协议,让你明明白白!
  19. Qt VTK软件开发问题学习记录
  20. “零售之王”银行数字化转型四大法则

热门文章

  1. JNI传递long时要谨慎,最好是int
  2. 脚本比别人的代码都多
  3. 在项目中经历生死的系统,才会成熟
  4. C++模板实现,支持多维,安全数组的完整代码
  5. priority_queue的优先级设置
  6. 服务器磁盘会影响应用么,想了解服务器磁盘的IO吞吐量,用sqlio 工具会不会对当前服务器有影响...
  7. java锁的粗化,锁优化(自旋锁,锁消除,锁粗化,轻量级锁,偏向锁)(深入理解JAVA虚拟机-学习记录)...
  8. 51单片机如何跳出wile循环_基于proteus的51单片机开发实例(1)
  9. flowable工作流_使用Bash Shell实现flowable配置文件修改定制
  10. java 模拟电梯_java实现的电梯模拟系统