Specifications

CHAPTER 11
240
Within the application that uses the MyCustomLogger class, define a TraceTarget, as the following example shows:
<?xml version="1.0"?>
<!-- charts/LoadCustomLogger.mxml -->
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" xmlns="*" >
<mx:TraceTarget level="0" includeDate="true" includeTime="true" includeCategory="true"
includeLevel="true">
<mx:filters>
<mx:Array>
<mx:String>*</mx:String>
</mx:Array>
</mx:filters>
</mx:TraceTarget>
<MyCustomLogger/>
</mx:Application>
After running this application, the flashlog.txt file looks similar to the following:
3/9/2006 18:58:05.042 [INFO] MyCustomLogger STARTUP:
Main_3.mcc:MyCustomLogger:preinitialize
3/9/2006 18:58:05.487 [INFO] MyCustomLogger STARTUP: Main_3.mcc:MyCustomLogger:initialize
3/9/2006 18:58:05.557 [INFO] MyCustomLogger STARTUP:
Main_3.mcc:MyCustomLogger:creationComplete
3/9/2006 18:58:05.567 [INFO] MyCustomLogger STARTUP:
Main_3.mcc:MyCustomLogger:updateComplete
3/9/2006 18:58:05.577 [INFO] MyCustomLogger STARTUP:
Main_3.mcc:MyCustomLogger:updateComplete
3/9/2006 18:58:05.577 [INFO] MyCustomLogger STARTUP:
Main_3.mcc:MyCustomLogger:updateComplete
3/9/2006 18:58:06.849 [DEBUG] MyCustomLogger EVENT: Main_3.mcc:MyCustomLogger:mouseOver
3/9/2006 18:58:07.109 [DEBUG] MyCustomLogger EVENT: Main_3.mcc:MyCustomLogger:mouseDown
3/9/2006 18:58:07.340 [DEBUG] MyCustomLogger EVENT: Main_3.mcc:MyCustomLogger:mouseUp
3/9/2006 18:58:07.360 [DEBUG] MyCustomLogger EVENT: Main_3.mcc:MyCustomLogger:click
3/9/2006 18:58:07.610 [DEBUG] MyCustomLogger EVENT: Main_3.mcc:MyCustomLogger:mouseOut
To log a message, you call the appropriate method of the ILogger interface. The ILogger interface defines a method
for each log level:
debug(), info(), warn(), error(), and fatal(). The logger logs messages from these calls
if their levels are at or under the log target’s logging level. If the target’s logging level is set to
all, the logger records
messages when any of these methods are called.
To improve performance, a static method corresponding to each level exists on the Log class, which indicates if
any targets are listening for a specific level. Before you log a message, you can use one of these methods in an
if
statement to avoid running the code. The previous example uses the
Log.isDebug() and Log.isInfo() static
methods to ensure that the messages are of level
INFO or DEBUG before logging them.