Disable logging in Flex

Categories: flex
Written By: sebi

Decisions about logging can be difficult sometimes. During development it’s desirable to have logs about everything, but we don’t want to add this overhead to an application, which is in production.

In Flex there’s no easy way to turn off the logging framework completely, once you added all your log lines.

Also you can always find yourself in the need of quickly re-enable the logging, if a bug arises in a live system, so completely remove the logging is probably not a good idea – for example with a compile time constant:

	if( Log.isDebug() )
		LOG.debug( "onPostConstruct() :: " );

It still requires to recompile you application to enable it. To be able to modify it at runtime is better.

I found that the easiest way to do this is to modify the level property of the s:TraceTarget.
Normally we have something like this:


If we properly added guard conditions around all log lines – and we did, didn’t we? – then simply increasing the level above LogEventLevel.FATAL – which is practically 1000, will disable our logs across the application, the Log won’t enter to our statement. So just define it as below:


Leave a Reply