selective_trace

Put this in a RCLog.hx somewhere:

class RCLog {
    
    public static function redirectTraces () {
        
        #if !nme
            haxe.Log.trace = RCLog.trace;
        #end
            
    }
    
    public static var ALLOW_TRACES_FROM = [];
    public static function allowTracesFrom (arr:Array<String>) {
        ALLOW_TRACES_FROM = ALLOW_TRACES_FROM.concat( arr );
    }
    
    static var lastMethod = "";
    public static function trace (v : Dynamic, ?inf : haxe.PosInfos) : Void
    {
        if ( ALLOW_TRACES_FROM.length == 0 ) {
            firebugTrace ( v, inf );
        }
        else for (c in ALLOW_TRACES_FROM) {
            if (c == inf.className.split(".").pop()) {
                firebugTrace ( v, inf );
            }
        }
    }
    public static function firebugTrace (v : Dynamic, ?inf : haxe.PosInfos) :Void
    {
        var newLineIn = (lastMethod == inf.methodName) ? "" : "\n--------------------";
        var newLineOut = (lastMethod == inf.methodName) ? "" : "\n\n";
        
        haxe.Firebug.trace ( inf.methodName + " : " + newLineIn + Std.string(v) + newLineOut, inf );
        
        lastMethod = inf.methodName;
    }
}

When you have a lot of traces you might get lost searching what you need, and they may also became hard to read with the small spaces between the lines. This snipet will allow you to see the output only from the classes you are interested in at a given moment and will try to group the traces from each method together.
Usage:

RCLog.redirectTraces();
RCLog.allowTracesFrom (["MyClass1", "MyClass2"]);

version #12654, modified 2012-03-28 12:52:06 by cristibaluta