Hello!
I wanted to present to you:
SQUID!
Squid is a standalone injectable system for saveable logging of user logs, errors and crashes for Defold. It is inspired by Log and Err by @Pkeod and Defold Log by @Insality and tries to be compatible with both. It’s MIT and even though it’s used by me in most of my projects, I refactored it recently, gave it an “inky” name and released it as open source in hope it might get stretched further.
Squid 1.1:
Check out README for quick usage reference and documentation.
Dependency
You can use it in your Defold project by adding a link to it in Dependencies. Current is 1.1:`
https://github.com/paweljarosz/squid/archive/refs/tags/1.1.zip
Colored logs
Squid utilises colored console output in Defold:
Each log entry is structured like this:
LOG_LEVEL: [tag]: [timestamp] code/address:line: message
Data: --if provided
It also pretty prints tables if provided as data parameter. Tables are also saved in log file up to a defined length and depth.
Auto-saving, auto error and crash handling
If configured to do so, it saves logs also to a log file in user save file directory automatically or explicitly. It also automatically saves Errors and Crashes. It also can automatically remove log files older than X days based on the timestamp in the file name.
Cross-platform
Squid is designed to be cross-platform, but tested mostly on Windows, Linux and HTML5. It should work on Mac, iOS and Android too, but wasn’t tested there yet. If there are any system specific issues, please report.
Configuration
Squid is configurable - you can use your own squid_config.lua file following the convention or configure it from game.project
- check out documentation for more details on it.
Quick Reference
Squid offers a very simple static API:
-- If squid is initialized with init() it will handle errors and crashes automatically too
squid.init()
-- Define new tag strings and enable/disable them:
squid.set_allowed("main", true)
-- Use static logging functions with or without optional non-string data and/or tag string:
squid.trace("My Trace Message") -- no data and no tag, uses default tag ("none")
squid.debug("My Debug Message ", { my_test_data = 1 }) -- with optional non-string data (default tag used)
squid.info( "My Info Message ", "main") -- with string data only (used as tag too)
squid.warn( "My Warning Message", "Hello World", "main") -- with string data and tag ("main" tag is used as tag here)
squid.error("My Error Message ", vmath.vector3(1), "main") -- with non-string data and tag
-- Or generic logging function with own logging level:
squid.log("My Other Message", squid.DEBUG)
-- Explicitly save any unsaved logs and check for crashes in final():
--(logs are saved automatically too, in batch every X logs as configured in game.project)
squid.final()
Instantiating
Squid can be conveniently used as internal logger module for various other Defold modules, e.g.:
- Pigeon by Paweł Jarosz
- Defold Saver by Insality
- Defold Event by Insality
-- Create new instance with optional tag assigned (`none` by default) initially allowed or not
self.player_logger = squid.new("player", true)
-- Use all API function with the created instance
self.player_logger:info("Logger with 'player' tag")