tag:robotlegs.tenderapp.com,2009-10-18:/discussions/robotlegs-2/12471-looking-for-logging-examplesRobotlegs: Discussion 2014-12-05T11:50:48Ztag:robotlegs.tenderapp.com,2009-10-18:Comment/350145632014-10-21T03:25:04Z2014-10-21T03:25:04ZLooking for logging examples<div><p>I'm trying to understand how to do logging. Are there any
examples, especially with as3commons logging.</p></div>Christag:robotlegs.tenderapp.com,2009-10-18:Comment/350145632014-10-21T12:56:23Z2014-10-21T12:56:23ZLooking for logging examples<div><ul>
<li>robotlegs Logger:</li>
</ul>
<p>just inject an ILogger (robotlegs.bender.framework.api.ILogger)
into a class and<br>
use it like this:</p>
<p>logger.info("Your Message", [someParameter,
anotherParameter]);</p>
<ul>
<li>For as3commons Logger, I guess that you can create a mapping
like this:</li>
</ul>
<pre>
<code>LOGGER_FACTORY.setup = new SimpleTargetSetup(new TraceTarget());
var as3Log:ILogger = getLogger("as3commons", "LOGGER::");
injector.map(ILogger).toValue(as3Log);</code>
</pre>
<p>and then inject the ILogger (org.as3commons.logging.api.ILogger)
where you need it.</p>
<p>If you want to have an as3commons logger that traces the class
name automatically, you can create your own LoggerProvider (similar
to robotlegs' LoggerProvider <a href=
"https://github.com/robotlegs/robotlegs-framework/blob/master/src/robotlegs/bender/extensions/enhancedLogging/impl/LoggerProvider.as">
https://github.com/robotlegs/robotlegs-framework/blob/master/src/ro...</a>)
like this:</p>
<pre>
<code>public class CustomLoggerProvider implements DependencyProvider
{
public function apply(targetType: Class, activeInjector:Injector, injectParameters:Dictionary):Object
{
LOGGER_FACTORY.setup = new SimpleTargetSetup(new TraceTarget());
return getLogger(getQualifiedClassName(targetType));
}
public function destroy():void
{
}
}</code>
</pre>
<p>You map your logger to the provider:</p>
<pre>
<code>injector.map(ILogger).toProvider(new CustomLoggerProvider());</code>
</pre>
<p>and inject an ILogger where you need it.</p>
<p>hth</p></div>Ondina D.F.