Hello Flex Logging and Goodbye trace()
Being a long time Flash Developer, using the trace() method was the first solution to trying to debug a problem. “Just trace out the value and see what it is and go from there”. I kind of laughed when someone at the office called it “poor mans debugger”. Scary enough, the more I thought about it, the more I realized he was right. Since the Flex Builder debugger, I rarely trace() anything out to the console anymore. I still trace things out in my application, a service or an action so I know that things happened properly.
I also remember discussing in #flex (on irc efnet) that there isn’t a compiler option to strip out all trace() statements in a swf. I believe people even created tickets on the Flex bug base for this. For me I’ve always accepted that since the old Flash 4 days, but there are some plugins now that allow you to see all trace statements in a SWF. This is all the more reason to use the Flex Logging classes!
First off, the Flex Logger basically wraps to trace() but the benefits of the flex logger are more flexible than trace. Let’s start with the different levels of logging: Debug, Info, Warn, Error and Fatal. This allows you to display the level of trace out to the console. For example, mylogger.info( “startup” ) or myLogger.debug( “event name” ). The great thing about these different levels is the TraceTarget class has a “level” property that you set that will only display that level of logging and higher. For example if you set the target.level to LogEventLevel.Debug, it will show everything from debug up. But if you set it to LogEventLevel.Warn, it’ll only show warnings and errors. To me, this solves the need of having a compiler option to omit trace actions.
Another great benefit of the flex logging classes are there are already a few packages that implement them: mx.rpc.*, mx.messaging.*, mx.data.*. It was really neat to see this in action for the first time, I made a RemoteObject call to the server and it traced out all of the info related to the call, and even the value object from the server. Again, the traces can be omitted via the “level” property.
I will agree with the saying, “Old habits die hard”, but when I started using the Flex logging classes, it wasn’t a difficult transition at all. If you’re an old Flash Developer turned Flex, I strongly urge you to check out the Flex Logging classes!
Cheers,
-lp
Filed under: Flex, Actionscript on August 7th, 2008 | No Comments »













