包括两部分吧:
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