Handy Tip - myTrace() function

This is something I’ve found handy over the years, so I thought I’d share it.

Essentially, I often create a function like myTrace(), as shown below. Then, instead of writing trace() calls, I write myTrace() calls.

Why? It gives me more control. I can, for example, choose to do nothing with all traces (ideal when compiling to release, to be sure people with debug players don’t see anything).
Or only trace out essential traces.
I can also redirect all traces to something like MonsterDebugger.
Or redirect all traces to a textbox (handy when debugging on a non-coding machine).
Or I can simply redirect all traces to trace() as if nothing had ever happened.

Example Code:

private function myTrace(traceString:String):void
{
	if (false) // Pass all traces through. // false = temporarily disabled.
		trace(traceString);
	if (traceString.indexOf("essential") != 0) // only trace messages containing "essential".
		trace(traceString);

	//MonsterDebugger.trace(this, traceString);
	
	/*if (true) { // redirect all traces to a textbox (created earlier)
		traceString += "
";
		serialOutput.text += traceString;
		serialOutput.verticalScrollPosition = serialOutput.maxVerticalScrollPosition;
	}*/

}