1 Reply Latest reply on Apr 12, 2007 1:15 PM by cluebcke

    Using a Trace or Debug window with an application

    csawall
      I will have a config parameter in an XML file to enable/disable debug. I want a window to be displayed when debug is enabled and show all debug output from the app.

      I am having a difficult time figuring out how to properly use Trace(). I understand that when I use Trace, it writes to a text file and I can see that. I'm looking to have a popup window in use with the app instead so that you can see live debug messages. Is there a best way to do this? Whatever solution I end up with, I need to have it packaged with the app itself.

      Any advice is greatly appreciated.

      Thanks,
      Chris
        • 1. Re: Using a Trace or Debug window with an application
          cluebcke
          I've implemented a logging framework for my company that allows log messages to be written to the trace file, back to the server, or both. I'm sorry that I can't share the code as it's not my intellectual property. But I can tell you my approach, which would be very easy to adapt to displaying log messages in a UI component.

          First, read all the docs you can on the logging framework. I realize they don't tell you how to roll your own, but be familiar with them as a starting point.

          Second, trace() is a low-level Flash Player function that is used by, but is really separate from, the logging framework. Specifically, trace() is used by mx.logging.targets.TraceTarget, which can be instantiated to receive various log messages that will then be output to the trace file. This is obviously close to what we want, but not quite there.

          What I found I needed to do was move one step up to TraceTarget's parent, LineFormattedTarget, extend that class and override LineFormattedTarget.internalLog(), which is where (along with a couple other helper methods) I implemented the functionality I described above. If you go this route there are two things to be aware of:

          1. internalLog() is in the mx_internal namespace; in order to override it you have to import and use mx_internal. Inspired by something else I read on that subject, I posted a blog about doing so here.

          2. LineFormattedTarget.internalLog() is an empty method (it would probably be abstract were this Java); check out TraceTarget's implementation of it if you want to get a feel for a 'proper' implementation

          There are other approaches--you could chuck the whole logging framework and just roll your own if you wanted. However, it has a good built-in support for Log4J-like features, including runtime management of log targets and log levels, that I find very valuable. There may be better approaches to implementing your own target as well, but I haven't found one yet. Once I understood how the log targets fit in to the overall framework, and got over my nervousness about using mx_internal (nothing exploded, I swear), it was actually really easy to implement, and I now use logging religiously.

          Hope that helps,
          Chris