Looking for logging examples

Chris's Avatar

Chris

21 Oct, 2014 03:25 AM

I'm trying to understand how to do logging. Are there any examples, especially with as3commons logging.

  1. Support Staff 1 Posted by Ondina D.F. on 21 Oct, 2014 12:56 PM

    Ondina D.F.'s Avatar
    • robotlegs Logger:

    just inject an ILogger (robotlegs.bender.framework.api.ILogger) into a class and
    use it like this:

    logger.info("Your Message", [someParameter, anotherParameter]);

    • For as3commons Logger, I guess that you can create a mapping like this:
    LOGGER_FACTORY.setup = new SimpleTargetSetup(new TraceTarget());
    var as3Log:ILogger = getLogger("as3commons", "LOGGER::");
    injector.map(ILogger).toValue(as3Log);
    

    and then inject the ILogger (org.as3commons.logging.api.ILogger) where you need it.

    If you want to have an as3commons logger that traces the class name automatically, you can create your own LoggerProvider (similar to robotlegs' LoggerProvider https://github.com/robotlegs/robotlegs-framework/blob/master/src/ro...) like this:

    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
        {
        }
    }
    

    You map your logger to the provider:

    injector.map(ILogger).toProvider(new CustomLoggerProvider());
    

    and inject an ILogger where you need it.

    hth

  2. Ondina D.F. closed this discussion on 05 Dec, 2014 11:50 AM.

Comments are currently closed for this discussion. You can start a new one.

Keyboard shortcuts

Generic

? Show this help
ESC Blurs the current field

Comment Form

r Focus the comment reply box
^ + ↩ Submit the comment

You can use Command ⌘ instead of Control ^ on Mac