출처 : http://sjp007.mireene.com/tc/entry/Flex-Log-log4j-%C3%B3%B7%B3-%BB%E7%BF%EB%C7%CF%B1%E2?category=4
///////////////////////////////////////////////////////////////
// LogUtil.as
///////////////////////////////////////////////////////////////
package utils
{
import flash.utils.getQualifiedClassName;
import mx.logging.ILogger;
import mx.logging.Log;
import mx.logging.LogEventLevel;
import mx.logging.targets.TraceTarget;
public class LogUtil
{
public function LogUtil()
{
}
public static function initLogging():void{
//create a Target
var logTarget:TraceTarget = new TraceTarget();
logTarget.filters = ["none"]; //이부분을 적절히 변경해주면 된다. Ex> "comp.*"
//Log all log levels
logTarget.level = LogEventLevel.DEBUG;
//Add category, date, time, and log level to the output
logTarget.includeCategory = false;
logTarget.includeDate = true;
logTarget.includeTime = true;
logTarget.includeLevel = true;
//Begging logging
Log.addTarget(logTarget);
}
public static function getLogger(c:*):ILogger{
var className:String = getQualifiedClassName(c).replace("::", ".");
return Log.getLogger(className);
}
}
}
///////////////////////////////////////////////////////////////
// Main Application
///////////////////////////////////////////////////////////////
<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:fx="http://ns.adobe.com/mxml/2009"
layout="vertical"
xmlns:mx="library://ns.adobe.com/flex/mx" minWidth="955" minHeight="600"
xmlns:comp="comp.*"
creationComplete="creationCompleteHdlr()">
<fx:Declarations>
<!-- Place non-visual elements (e.g., services, value objects) here -->
</fx:Declarations>
<fx:Script>
<![CDATA[
import utils.LogUtil;
private function creationCompleteHdlr():void{
LogUtil.initLogging();
}
]]>
</fx:Script>
<comp:LogComp1/>
<comp:LogComp2/>
</mx:Application>
///////////////////////////////////////////////////////////////
// LogComp1.mxml
///////////////////////////////////////////////////////////////
<?xml version="1.0" encoding="utf-8"?>
<s:Group xmlns:fx="http://ns.adobe.com/mxml/2009"
xmlns:s="library://ns.adobe.com/flex/spark"
xmlns:mx="library://ns.adobe.com/flex/mx" width="400" height="300">
<fx:Declarations>
<!-- Place non-visual elements (e.g., services, value objects) here -->
</fx:Declarations>
<fx:Script>
<![CDATA[
import flash.utils.getQualifiedClassName;
import mx.logging.ILogger;
import mx.logging.Log;
import utils.LogUtil;
private var logger:ILogger = LogUtil.getLogger(this);
private function test():void{
logger.debug("comp1 debug test");
}
]]>
</fx:Script>
<s:Button label="log comp1" click="test()"/>
</s:Group>
///////////////////////////////////////////////////////////////
// LogComp2.mxml
///////////////////////////////////////////////////////////////
<?xml version="1.0" encoding="utf-8"?>
<s:Group xmlns:fx="http://ns.adobe.com/mxml/2009"
xmlns:s="library://ns.adobe.com/flex/spark"
xmlns:mx="library://ns.adobe.com/flex/mx" width="400" height="300">
<fx:Declarations>
<!-- Place non-visual elements (e.g., services, value objects) here -->
</fx:Declarations>
<fx:Script>
<![CDATA[
import mx.logging.ILogger;
import mx.logging.Log;
import utils.LogUtil;
private var logger:ILogger = LogUtil.getLogger(this);
private function test():void{
logger.debug("comp2 debug test");
}
]]>
</fx:Script>
<s:Button label="log comp2" click="test()"/>
</s:Group>