Defold Log - Context logger with performance metrics



Log - is a single file Lua library for Defold game engine, enabling efficient logging for game development. It simplifies debugging and monitoring by allowing developers to generate detailed logs that can be adjusted for different stages of development.


  • Log Levels: Includes TRACE, DEBUG, INFO, WARN, and ERROR for varied detail in logging.
  • Build-specific Logging: Allows changing log verbosity between debug and release builds.
  • Detailed Context: Supports logging with additional information for context, such as variable values or state information.
  • Format Customization: Allows customizing the log message format.
  • Performance Tracking: Provides features to log execution time and memory use.


See the Defold-Log repository on Github for the Setup, Documentation, API and Use Cases


-- Import log module first
local log = require("log.log")

-- Create a logger instance to use in this file
local logger = log.get_logger("my_logger_name")

function init(self)
    -- All available functions in logger instance:
    logger:trace("Trace is typically used to log the start and end of functions or specific events")
    logger:debug("Debug is suitable for detailed system information that could be helpful during development", { level = self.level, message = "any_param" })
    logger:info("Info is used for general system information under normal operation")
    logger:warn("Warn is intended for potentially harmful situations that could require attention")
    logger:error("Error indicates serious issues that have occurred and should be addressed immediately", { error = "error message" })

Let’s play a game

In this repository, there are several very simple issues awaiting implementation. If you’re interested in trying yourself at making an open-source contribution, this is an good way to do this!



I like the performance tracking — quite convenient!

I’ve been using GitHub - d954mas/defold-chronos: High resolution monotonic timers for Defold in my own performance tests, to get the most reliable measurements. I might add it as “use if available”, like what you’ve done with utf8. If so, I will create a pull request.


That can be useful for someone who want this and no any affects for other users. Like the idea!

Will wait for the PR :heart:

Quick follow-up: defold-chronos appears to be untested on Apple platforms (and I don’t have any myself to test on). Based on that along with the overhead of the logging function itself, which makes microsecond precision less useful, I decided against doing a PR. Precise profiling is arguably better done with a purpose-built module.

I did a couple of changes for my own purposes (commit); the time and memory values are printed with delimiters for readability, and if the memory difference is less than 0 (GC ran) I print a question mark:

   933,008,399ns  1,266,848B D[app]...
        26,599ns         88B D[app]...
 4,302,851,800ns          ?B D[app]...

Yea, it’s true that in the current implementation of time tracking the string format functions are included.

For such precision with nanoseconds, we can update the time counter after all format changes, as I do with memory counter

Update: I update the current release tag with these fixes about precision of tracking. Also all tracking will be disabled in release mode to save performance if you forget.

Chronos support still can be useful if your wish to make a PR. I can check the apple devices if required



Thanks @GooseSwanson for the PR!

Update the repo to v2 release with defold-chronos support.