# Squid 🦑 saveable logging and errors and crashes handling

**URL:** <https://forum.defold.com/t/squid-saveable-logging-and-errors-and-crashes-handling/79296>\
**Category:** The Defoldmine\
**Created:** [December 29, 2024, 6:59pm UTC](https://forum.defold.com/t/squid-saveable-logging-and-errors-and-crashes-handling/79296 "2024-12-29T18:59:37Z")\
**Posts on this page:** 18\
**Page:** 1

<div class="post-metadata">

**Author:** ![Pawel](https://forum-defold.b-cdn.net/user_avatar/forum.defold.com/pawel/32/24623_2.png) [@Pawel](https://forum.defold.com/u/Pawel)\
**Post date:** [December 29, 2024, 6:59pm UTC](https://forum.defold.com/t/squid-saveable-logging-and-errors-and-crashes-handling/79296/1 "2024-12-29T18:59:37Z")

</div>

Hello!

I wanted to present to you:

# 🦑 SQUID!

 ![Squid-hero](https://forum-defold-uploads.b-cdn.net/original/3X/1/3/130679bf8954ebf879b528e5a72deee3e396a742.jpeg)

**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:

[https://github.com/paweljarosz/squid](https://github.com/paweljarosz/squid)

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.2:`

` https://github.com/paweljarosz/squid/archive/refs/tags/1.2.zip`

## 🌈 Colored logs

Squid utilises colored console output in Defold:

 ![console](https://forum-defold-uploads.b-cdn.net/original/3X/7/e/7eafdc51536367625e0518ba7b505bd3b586c4f3.png)

Each log entry is structured like this:

```lua
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:

```lua
-- 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](https://github.com/paweljarosz/pigeon) by Paweł Jarosz
- [Defold Saver](https://github.com/Insality/defold-saver) by Insality
- [Defold Event](https://github.com/Insality/defold-event) by Insality

```lua
-- 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")

```

---

<div class="post-metadata">

**Author:** ![Insality](https://forum-defold.b-cdn.net/user_avatar/forum.defold.com/insality/32/39737_2.png) [@Insality](https://forum.defold.com/u/Insality)\
**Post date:** [December 30, 2024, 2:08pm UTC](https://forum.defold.com/t/squid-saveable-logging-and-errors-and-crashes-handling/79296/2 "2024-12-30T14:08:05Z")

</div>

Nice! Thanks for the sharing, looks amazing!

First time name Squid make me thinking this is something UI relative 😃

---

<div class="post-metadata">

**Author:** ![Pawel](https://forum-defold.b-cdn.net/user_avatar/forum.defold.com/pawel/32/24623_2.png) [@Pawel](https://forum.defold.com/u/Pawel)\
**Post date:** [December 30, 2024, 2:16pm UTC](https://forum.defold.com/t/squid-saveable-logging-and-errors-and-crashes-handling/79296/3 "2024-12-30T14:16:21Z")

</div>

I like naming modules by animals, because those are very fast to memorize imho 😃 And squid is the one with ink, so can “write” 😅 Nevermind, octopus is reserved for the next module I’m working on xD

And this has saving inside - I thought that it might be useful for Defold Log as well, but thought that perhaps you want to somehow bind it with own Saver, because I was thinking about it as well 😃

Example log file:

[squid\_log\_file\_2024-12-29\_19\_43.txt](https://forum.defold.com/uploads/short-url/XFDQAUEmI7WZ18EUtyO4lHdKQw.txt) (1.0 KB)

At the beginning it stores info about engine, user system and device and then appends logs. It also stores crashes information if there occur any.

---

<div class="post-metadata">

**Author:** ![Insality](https://forum-defold.b-cdn.net/user_avatar/forum.defold.com/insality/32/39737_2.png) [@Insality](https://forum.defold.com/u/Insality)\
**Post date:** [December 30, 2024, 2:53pm UTC](https://forum.defold.com/t/squid-saveable-logging-and-errors-and-crashes-handling/79296/4 "2024-12-30T14:53:02Z")

</div>

Yea, this logs looks handy and also a good example of “how to implement that”

I had plans about external log storage, but still didn’t meet the any use cases for my projects before. Even it will be implemented - it will be the same inner way as you did, to escape additional dependencies

About dependencies:

From first look the additional dependency of Immutable seems unnecessary. It’s used only for inner settings, which only you as developer have the access. It can bring more friction to start using or try this module.

---

<div class="post-metadata">

**Author:** ![Pawel](https://forum-defold.b-cdn.net/user_avatar/forum.defold.com/pawel/32/24623_2.png) [@Pawel](https://forum.defold.com/u/Pawel)\
**Post date:** [December 30, 2024, 3:04pm UTC](https://forum.defold.com/t/squid-saveable-logging-and-errors-and-crashes-handling/79296/5 "2024-12-30T15:04:31Z")

</div>

> [@Insality](#):
>
> It can bring more friction to start using or try this module.

You’re right about it, it’s mainly for my convenience as of now, as I use it in my projects like this. I also don’t want users to copy/paste the config module, you know, like you would need if you want to modify the custom configuration, instead of just adding dependency, but I want to allow to modify the configuration. It was my first time, when I tried to bound configuration with game.project. Maybe I’ll figure out some better ways for such config too 😃

> [@Insality](#):
>
> it will be the same inner way as you did, to escape additional dependencies

But on the other hand - a module like logger is injected into other modules for loggin purposes and it’s pretty natural (like `.set_logger()`) . So I was thinking of making the same with saving purposes - any module that wants to save something to files could use an easy injected saver module 😃

For Immutable itself - I can’t figure out a way of checking if such a module is present in project - because if so, it could be used silently without user’s interaction. Require will always raise error if there is no file under given path and it doesn’t matter if it’s inside `pcall`.

> [@Insality](#):
>
> still didn’t meet the any use cases for my projects before.

My use case was client’s work and users weird issues, that I couldn’t reproduce, hence collecting full logs from them helped a bit 😃 I imagine a great saver module that can save to local file, but also have an option to store it somewhere online too, it would be a blast!

---

<div class="post-metadata">

**Author:** ![NaakkaDev](https://forum-defold.b-cdn.net/user_avatar/forum.defold.com/naakkadev/32/34927_2.png) [@NaakkaDev](https://forum.defold.com/u/NaakkaDev)\
**Post date:** [December 30, 2024, 4:00pm UTC](https://forum.defold.com/t/squid-saveable-logging-and-errors-and-crashes-handling/79296/6 "2024-12-30T16:00:10Z")

</div>

This is awesome, but I kinda managed to break it. 😅

I have `squid.init()` and `squid.final()` set in my main.script, which is the first thing that loads when I start the game.

```lua
WARNING:CRASH: Crashdump version or format does not match: Crash version: 1330007625.538976314 Tool Version: 2.51144
INFO: [crash]: [17:36:41] squid/squid.lua:121: CRASH: No crash dump found
DEBUG: [none]: [17:36:41] main/main.script:71: final()

```

I see this in the defold editor console when I close the game (ESC) too quickly. When this happens squid writes its things into the newest existing log file, instead of creating a new one.  
This could be a non-issue, but if the engine crashes too early then the log files might get messy.

I also noticed that when the log directory is empty, the first log, instead of the system info text wall, it has a warning: `No files found in directory.`

Lastly, when I close the game via ESC (when it has properly loaded etc.), squid seems to think there was a crash. The “Escape Quits Game” editor preference is enabled, but I _presume_ it quits the game gracefully instead of nuking it. 😛

```lua
INFO: [crash]: [17:44:38] squid/squid.lua:121: CRASH: No crash dump found

```

---

<div class="post-metadata">

**Author:** ![Pawel](https://forum-defold.b-cdn.net/user_avatar/forum.defold.com/pawel/32/24623_2.png) [@Pawel](https://forum.defold.com/u/Pawel)\
**Post date:** [December 30, 2024, 4:36pm UTC](https://forum.defold.com/t/squid-saveable-logging-and-errors-and-crashes-handling/79296/7 "2024-12-30T16:36:01Z")

</div>

Thank you for the first reports! 😃 I’ll look into those 😉

If this is only what you see in log:

```lua
INFO: [crash]: [17:44:38] squid/squid.lua:121: CRASH: No crash dump found

```

this is normal, it’s an INFO trace, it means there were no crashes, perhaps I should change the message, but somehow I find it a useful information, so I don’t want to remove it 😃

> [@NaakkaDev](#):
>
> `WARNING:CRASH: Crashdump version or format does not match: Crash version: 1330007625.538976314 Tool Version: 2.51144`

I also bumped into this, in different circumstances:

> [@Crash dump after error occurence is nil?](https://forum.defold.com/t/crash-dump-after-error-occurence-is-nil/79294):
>
> I’m trying to collect a crash, but when it occurs after error: assert(false) crash.write\_dump() The error is printed, but I get a warning in console after: WARNING:CRASH: Crashdump version or format does not match: Crash version: 1128354388.538982981 Tool Version: 2.51144 and then: local dump = crash.load\_previous() dump is nil confused When there is no error (assert commented out) the dump is correct (not nil). Why is this happening?

But I don’t know what it is and why there is such a warning.

> [@NaakkaDev](#):
>
> When this happens squid writes its things into the newest existing log file, instead of creating a new one.  
> This could be a non-issue, but if the engine crashes too early then the log files might get messy.

Yeah, this is an issue 😕

EDIT:  
@NaakkaDev maybe you are opening and closing game in the very same minute twice or more?

If so it will be written in the same log file, because squid appends logs to a file with a name with a time stamp in format YYYY-MM-DD\_hh\_mm, so if you call `squid.init()` in the very same minute, e.g. 18:51, all logs will be written into one file. I think narrowing it down to a minute is enough for usual use cases, so I won’t be adding seconds to the time stamp 😅

If you configure `is_adding_timestamp` in game.project to `0` it will be resulting in all logs being written to a single file always, but also bear in mind in such case, squid will **not** automatically remove old logs (because it is based on those time stamps in file names)

---

<div class="post-metadata">

**Author:** ![NaakkaDev](https://forum-defold.b-cdn.net/user_avatar/forum.defold.com/naakkadev/32/34927_2.png) [@NaakkaDev](https://forum.defold.com/u/NaakkaDev)\
**Post date:** [December 30, 2024, 6:20pm UTC](https://forum.defold.com/t/squid-saveable-logging-and-errors-and-crashes-handling/79296/8 "2024-12-30T18:20:04Z")

</div>

> [@Pawel](#):
>
> this is normal, it’s an INFO trace, it means there were no crashes, perhaps I should change the message, but somehow I find it a useful information, so I don’t want to remove it 😃

Yeah, I had a feeling that was the case, but the `CRASH:` part is tripping me up and making me think it is trying to report a crash but didn’t find the dump file. 😃

Could perhaps append the message with `(OK)` or such.

> [@Pawel](#):
>
> @NaakkaDev maybe you are opening and closing game in the very same minute twice or more?

Yes that seems to be the case. I didn’t notice the filename had no seconds.

---

<div class="post-metadata">

**Author:** ![Pawel](https://forum-defold.b-cdn.net/user_avatar/forum.defold.com/pawel/32/24623_2.png) [@Pawel](https://forum.defold.com/u/Pawel)\
**Post date:** [December 31, 2024, 1:14pm UTC](https://forum.defold.com/t/squid-saveable-logging-and-errors-and-crashes-handling/79296/9 "2024-12-31T13:14:03Z")

</div>

> [@NaakkaDev](#):
>
> Could perhaps append the message with `(OK)` or such.

@NaakkaDev such a message could be ok? [crash] is a tag here (for easier searching):

![image](https://defold-forum-bucket.nbg1.your-objectstorage.com/original/3X/a/6/a67e5b62ef09a0d4d047a064d62a5c578954e598.png)

---

<div class="post-metadata">

**Author:** ![NaakkaDev](https://forum-defold.b-cdn.net/user_avatar/forum.defold.com/naakkadev/32/34927_2.png) [@NaakkaDev](https://forum.defold.com/u/NaakkaDev)\
**Post date:** [December 31, 2024, 1:20pm UTC](https://forum.defold.com/t/squid-saveable-logging-and-errors-and-crashes-handling/79296/10 "2024-12-31T13:20:56Z")

</div>

Yes. That one is much clearer. I do wonder if the “OK:” part is needed now, since “No crashes,” already says it all.

---

<div class="post-metadata">

**Author:** ![Pawel](https://forum-defold.b-cdn.net/user_avatar/forum.defold.com/pawel/32/24623_2.png) [@Pawel](https://forum.defold.com/u/Pawel)\
**Post date:** [December 31, 2024, 1:52pm UTC](https://forum.defold.com/t/squid-saveable-logging-and-errors-and-crashes-handling/79296/11 "2024-12-31T13:52:14Z")

</div>

Updated to 1.1 😃

- Removed Immutable dependency.
- Changed final message about no crashes to more friendly:  
(`INFO: [squid]: [14:47:48] squid/squid.lua:122: No crashes, no dump found.`)
- Added functions to get and set new squid configuration.
- Improved documentation.

---

<div class="post-metadata">

**Author:** ![NaakkaDev](https://forum-defold.b-cdn.net/user_avatar/forum.defold.com/naakkadev/32/34927_2.png) [@NaakkaDev](https://forum.defold.com/u/NaakkaDev)\
**Post date:** [December 31, 2024, 4:42pm UTC](https://forum.defold.com/t/squid-saveable-logging-and-errors-and-crashes-handling/79296/12 "2024-12-31T16:42:12Z")

</div>

Guess what happens when I set the `app_catalog ` to `PROJECTNAME/logs` and the `PROJECTNAME` directory does not exist. 😆

> **Spoiler**
>
> ```lua
> ERROR:SCRIPT: squid/squid_impl.lua:48: Unable to locate application support path for "PROJECTNAME/logs": (-2)
> 
> ```
> 
> Since Squid can create the log root directory, in my opinion it should also be able to create any missing directory regardless of the depth.
> 
> Btw. I did try to find the code that creates the log directory but seems I’m blind. 🕶

---

<div class="post-metadata">

**Author:** ![Pawel](https://forum-defold.b-cdn.net/user_avatar/forum.defold.com/pawel/32/24623_2.png) [@Pawel](https://forum.defold.com/u/Pawel)\
**Post date:** [December 31, 2024, 4:59pm UTC](https://forum.defold.com/t/squid-saveable-logging-and-errors-and-crashes-handling/79296/13 "2024-12-31T16:59:33Z")

</div>

Should be in save\_logs in squid\_impl 😁 I never considered nested dirs 😅

---

<div class="post-metadata">

**Author:** ![Pawel](https://forum-defold.b-cdn.net/user_avatar/forum.defold.com/pawel/32/24623_2.png) [@Pawel](https://forum.defold.com/u/Pawel)\
**Post date:** [January 20, 2025, 10:35pm UTC](https://forum.defold.com/t/squid-saveable-logging-and-errors-and-crashes-handling/79296/14 "2025-01-20T22:35:42Z")

</div>

Added a new version 1.2! 🥳

It has critical fixes for usage with instantiated logger (created using `squid.new()`) and few other rather small changes and improvements and full API documentation:

- Added message when saving logs and crashes with location of the saved file:  
(e.g. `INFO: [squid]: [14:47:48] squid/squid.lua:122: Succesfully saved at: Data: /home/pawel/snap/steam/common/.config/squid_app_catalog/squid_log_file_2025-01-20_22_32.txt`)
- Added default level to plain `squid.log()` function set as `squid.INFO` when no level is provided by user.
- Fixed printing condition not working issue.
- Fixed code address nesting level when using instantiated squid logger.
- Fixed Lua annotations when using instantiated squid logger.
- Improved documentation and example script, added API documentation.

---

<div class="post-metadata">

**Author:** ![Caue-Aron](https://forum-defold.b-cdn.net/user_avatar/forum.defold.com/caue-aron/32/41954_2.png) [@Caue-Aron](https://forum.defold.com/u/Caue-Aron)\
**Post date:** [January 30, 2025, 12:13pm UTC](https://forum.defold.com/t/squid-saveable-logging-and-errors-and-crashes-handling/79296/16 "2025-01-30T12:13:16Z")

</div>

Hey, im trying to use squid with editor scripts, but im getting this error on every editor scripts reload:  
`ERROR:EXT: Loading /unfold/unfold.editor_script failed: @squid/squid_config.lua:23 attempt to index ? (a nil value)`  
with this code:

```lua
local squid = require 'squid.squid'
local M = {}

function M.get_commands()
    squid.init()
    return {
        {
            label = "Turn Into Collection",
            locations = { "Assets", "Edit" },
            query = { selection = { type = "resource", cardinality = "one" } },
            active = function(opts)
                return editor.get(opts.selection, "path"):EndsWith(".gltf")
            end,
            run = function(opts)
                squid.set_allowed("Unfold", true)
                squid.trace("TEST")
            end
        }
    }
end

return M

```

---

<div class="post-metadata">

**Author:** ![britzl](https://forum-defold.b-cdn.net/user_avatar/forum.defold.com/britzl/32/23_2.png) [@britzl](https://forum.defold.com/u/britzl)\
**Post date:** [January 30, 2025, 1:08pm UTC](https://forum.defold.com/t/squid-saveable-logging-and-errors-and-crashes-handling/79296/17 "2025-01-30T13:08:59Z")

</div>

Squid is intended for runtime use in the engine. I suppose it would be possible to patch the parts of Squid which rely on Defold engine APIs, such as your error where a call to sys.get\_config\_string() fails.

---

<div class="post-metadata">

**Author:** ![Caue-Aron](https://forum-defold.b-cdn.net/user_avatar/forum.defold.com/caue-aron/32/41954_2.png) [@Caue-Aron](https://forum.defold.com/u/Caue-Aron)\
**Post date:** [January 30, 2025, 1:25pm UTC](https://forum.defold.com/t/squid-saveable-logging-and-errors-and-crashes-handling/79296/18 "2025-01-30T13:25:05Z")

</div>

hm, is there anything i can do myself instead of using squid then? I suppose defold allows for colorful printing, couldnt find any resources on that myself tho.

---

<div class="post-metadata">

**Author:** ![Pawel](https://forum-defold.b-cdn.net/user_avatar/forum.defold.com/pawel/32/24623_2.png) [@Pawel](https://forum.defold.com/u/Pawel)\
**Post date:** [December 4, 2026, 2:32pm UTC](https://forum.defold.com/t/squid-saveable-logging-and-errors-and-crashes-handling/79296/19 "2026-12-04T14:32:13Z")

</div>

I’ve updated Squid to 1.3 fixing some issues and improving its usability with instanced loggers 😉

Release notes:

> **[Release 1.3 · paweljarosz/squid](https://github.com/paweljarosz/squid/releases/tag/1.3)**
>
> Squid 1.3 adds logger adapters for external libraries, configurable source locations, and fixes for log data and error handling.
> What’s new
> 
> Added squid.get\_logger(tag, is\_allowed, stack\_level), an...
