Shared haxe libraries: how to log beyond trace statements?

I create, and attempt to maintain, several haxelib libraries.

I’d like to add logging statements beyond “trace”, ideally, with different levels of logging: debug, info, etc.

But how to do this in way that can be easily used when someone else is consuming the library, and may have their own logging solution? How to do this in a way that’s easy for the library consumer to understand, and allow them to use my libraries log statements with their own solution, with a minimal amount of configuration?

I’m ok if the solution is not cross-platform, if the solution is simpler.

I’d really like to hear both quick-and-dirty, and more complex solutions, or ideas, if anyone has any.


Here is HaxePunk’s minimal logging utility. With Import.hx (awesome underappreciated feature) you can import these helpers into your namespace so they’re as easy to use as trace.

For extensibility I would just give consumers a method to register a log callback (LogLevel -> String -> Void) and use the callback if one is defined.

A nice thing about Haxe is, with conditional compilation, you can have log statements while debugging, but in production the method calls will disappear without a trace :wink:

1 Like

I’ve been using MConsole.

1 Like

I’m resurrecting this because I’m curious about the topic.

I found this, by the makers of hexMachina:

It’s inspired by log4j. Opinions?

I’d suggest having something dead simple, like the haxe.Log.trace function that one can redefine and route to a preferred logging infra. Maybe your lib would use an internal function which could be filtered by setting a log level value, static as well, and you may possibly also want to namespace the logs to differentiate your different libs.


I’d say that this very much depends on what you’re expecting from your logging.
If you’re used to log4j or log4net and you want the same possibilities of configuration or you’re expecting sending logs to multiple endpoints based on their verbosity, hierarchy etc. with the tradeoff of minor performance hit then go with hexLog.
If you need something to just print out statement into browser console then hexLog is likely an overkill.

It’s a pretty complex project I feel, specifically on the logic side of things (it’s a story & game logic engine). So I think I’m going to need quite a lot of logging when I’m hunting for bugs. But @elsassph’s suggestion can work too if implemented correctly. I’m not favoring any log4 variant, I’m simply not confident enough in my Haxing skills yet :smiley: . And since I’m investing as much as I can in the prototype itself, I have little to spare when it comes to making an efficient yet future-proof logging system.

Not sure if you seen this, but there is a section on debugging in Haxe Manual: Debugging - Haxe - The Cross-platform Toolkit

1 Like

Sadly, hexLog doesn’t seem to be actively maintained anymore.