Hi,

just had an issue where an application would run on any machine with the
debug player installed, but would completely fail to load on any machine
with the non-debug player.

The issue us that there is a Logger singleton class which would find out the
name of the calling class by throwing a stack-trace, so you can do something
like this:
*Logger.error("some message"); * - then the Logger class would throw an
error, get the stack trace, work out the name of the calling class and use
it like so:

*Log.getLogger( classNameExtractedFromStackTrace ).error("some message"); *

In non-debug players the stackTrace always appears to be null (guess this
makes sense), but that was supposedly okay because if a name couldn't be
found it was returning an empty string instead:

However, the problem appears to be that getLogger is really picky about what
it receives as the category argument. For example :

Log.getLogger("").info("message");       //This causes the Flex app to keel
over completely
Log.getLogger("-").info("message");      //This doesn't, and the Flex app
works fine.


The Flex docs suggest manually putting the name of each class in as the
category String, but a really don't like that idea, and I was wondering how
any of you work with Log.getLogger?

With the aim of doing as little refactoring as possible at this point in
time I'm thinking of changing the logging here so that it works like this:

*Logger.info("message", this);* //pass in a ref to the calling class - (bah)

...which calls the Logger method info like so....

*public static function info(message:String, callee:Object=null):void //*null
so that we can swap things over at our own pace
*{
    Log.getLogger(getNameFromCallee(callee)).info(message);
}*

Then use describeType to get the name (and replacing any characters which
would cause issues):

*private static function getNameFromCallee(callee:Object):String
{
    var name:String = (callee == null) ? "-" :
describeType(callee)....@base.tostring();
     if(name != null)
     {
         name = name.split("::").join(".");  //I'm sure I may need to
replace other chars as well - eg  name = name.split("/").join(".");
     }
     else
     {
          name = "-";
     }
     return name;
}*

Suggestions welcomed.

Reply via email to