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.
Features
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.
Setup
See the Defold-Log repository on Github for the Setup, Documentation, API and Use Cases
Usage
-- 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" })
end
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!
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:
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