Targeting SOSmax in HaXe

As boring as the title sounds (and it does sound boring), it's a worthwhile investment to get a good logging solution going on whatever platform you're developing on. I've been playing around with haXe lately and I discovered its trace() function to be severely lacking--that is, until I actually read the documentation (I'm a man, we don't read documentation). HaXe allows you to write your own implementation and plug it into the trace function by setting haxe.Log.trace to your own custom class.

When developing in Flash or Unity, I like to use SOSmax, an XML socket server. So, I wrote a quick interface that redirects trace() to SOSmax.

All you have to do is add

new SOSTrace();

to your code. Optionally, you can add a server and port. Subsequent calls to trace() will be directed to SOSmax. Additionally, you can specify a log level as the second parameter (defaults to SOSTrace.DEBUG):

trace("Log THIS!", SOSTrace.WARN);

Finally, you can use replacement--though this is less useful than in AS3, because in HaXe you can actually compile out all the trace() statements with the --no-traces compiler option.

trace("Point at ({0}, {1}).", SOSTrace.DEBUG, point.x, point.y);

Grab it on github.

UPDATE: Check out http://thegoldenmule.com/blog/?p=261. I've since added a JavaScript target as well!

4 Comments

  1. Alan Klement

    I'm definitely interested in this. I'm working with haXe now every day and I start becoming curious how the SOS Max could be integrated.

    I see you're using for the Flash target, have you looked into externs for other targets. Specifically I was curious about using it with JS & PHP.

  2. thegoldenmule

    That's a great idea! I will definitely look into getting this running with at least the JS target. Thanks for the suggestion.

Leave a Reply