COMMUNITY

How to add time for global trace?

current trace
xxx.hx:309

I want to add extra time info to global trace.like

xxx.hx:309 [2019-10-1-20:12]?

See haxe/Log.hx.
Declaration of haxe.Log.trace is prefixed with static dynamic function, that dynamic keyword in the context of a function means you can redefine this function implementation from anywhere.
Here is an example:

var oldTrace = haxe.Log.trace;
haxe.Log.trace = function(v:Dynamic, ?pos: haxe.PosInfos) {
    oldTrace("[" + Date.now().toString() + "] " + Std.string(v), pos);
};

// from anywhere
trace("something");

The var oldTrace holding the old implementation seems temporary here, but its value is permanently kept in the closure, so once executed it will work from anywhere, so you don’t have to care about the local oldTrace variable anymore.

thanks @emugel,it’s work