Introducing: The Peanut Butter Logger (Flash-friendly AS3 logging)

The Flex logging framework is pretty cool.  For an old skool Flash Hack like me it was a huge step up from the trace() that was pretty much our only tool back in the day.  Some of us rolled our own solution in the AS2 days and there were even a few projects around the idea.  But there was never a great way of getting our important debugging info to a helpful place.

And of course the Flex logging framework is for . . . Flex.  I have a bitter-sweet relationship with Flex and the fact that the logging framework isn’t something that’s uber-portable is a little frustrating.  But no matter; there was enough I didn’t like about the framework so it was an even better opportunity to roll my own.

I’ve been using this logging framework since the early AS3 days and finally thought that it might be helpful to provide it to anyone else who is interested in using it.  The usage is about the same as the Flex framework:

var logger:PBLogger = PBLogger.getLogger("company.project");
logger.debug("peanut butter is awesome");
logger.warn("We are almost out of honey!");

The logs are automatically trace()ed. Additionally though (and here is the fun part) you can very easily build ‘bridges’ to pipe the output somewhere else. I’m a big fan on Antropod. But I don’t want to write all of my logs specifically to the Antropod output. What if I want to also pipe my FATAL logs to a service or another socket or something? When I start a project I call PBLogArthropodBridge.initialize(); and all of my logs are now piped into the Antropod debugger. Handy no?

I’ve also tossed in there a Flex logging framework bridge. Using this you can just toss this into an existing project that is using the Flex logging framework and all of your logs will get piped into the Flex logging framework by similarly calling PBLogFlexBridge.initialize();.

I hope that this thing will be pretty easy for people to use. You are welcome to grab the project or just the .swf. If there is enough interest in this code then I might make a real project out of it. This is an important dependency to the command framework that I’ll be releasing next. Please let me know if you find it useful!

Filed under flex, project · Tagged with

Yea but . . .

Tell me what you're thinking.