Selective Logging

dan's Avatar


13 Jun, 2014 09:29 PM

I have logging across a large project. While debugging I want to enable/disable logging for certain classes at runtime. I'm not really sure what's involved to make that happen. Any pointers?

As an example, I'd like to be able to disable the logger statements at runtime from a command without having to modify the Turkey or the Tesla classes below. 'gobble, gobble' ); 'zoom zoom' );

  1. 1 Posted by matej on 14 Jun, 2014 04:48 AM

    matej's Avatar

    logger.logLevel = LogLevel.Error

    Inject logger in your configuration for good placement :)

    S poštovanjem,
    Matej Šimunić

  2. 2 Posted by dan on 15 Jun, 2014 01:42 AM

    dan's Avatar

    Thanks but I have a mix of debug and info statements i want to disable for
    a specific class yet still see info and debug from others. I was hoping to
    do this from a command at runtime. Classes already have a logger
    instance... maybe I just need a more powerful log file analyzer that can
    filter those classes out.... Thought I might be able to check where the log
    statements are sent and skip if they match a list of classes.

  3. 3 Posted by dan on 19 Jun, 2014 09:46 PM

    dan's Avatar

    Had some time to figure this out, here's what I did if someone else finds it useful. This only works if you grab loggers with your class type.

    So to mute a class at runtime, just do the following:

    TraceLogTarget2.mute( ClassName )

    It'd be nice to disable an entire package but haven't had time for that yet.

    class TraceLogTarget2 extends TraceLogTarget
        private static var muteMap:Object = {};
        public static function mute(source:Object):void
            muteMap[source] = 1;
        public static function unmute(source:Object):void
            muteMap[source] = 0;
        public static function unmuteAll():void
            muteMap = {};   
        override public function log(source:Object, level:uint, timestamp:int, message:String, params:Array=null):void
            // skip log if object has been muted
            if( !muteMap.hasOwnProperty( source ) || muteMap[source] == 0 )
                super.log( source, level, timestamp, message, params );
  4. Support Staff 4 Posted by Ondina D.F. on 20 Jun, 2014 06:25 AM

    Ondina D.F.'s Avatar

    Cool! Thanks for sharing your solution with us.

  5. Ondina D.F. closed this discussion on 02 Jul, 2014 07:20 AM.

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

Keyboard shortcuts


? 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