You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
@@ -12,36 +12,49 @@ Copyright 2024-2025 Paweł Jarosz
12
12
13
13
## Defold dependency:
14
14
15
-
You can add Squid as a dependency to Defold. Open your `game.project` file and add the following link as an entry in the `Dependencies` under the `Project` section. Current version is 1.1:
15
+
You can add Squid as a dependency to Defold. Open your `game.project` file and add the following link as an entry in the `Dependencies` under the `Project` section. Current version is 1.2:
If squid is initialized with init() it will handle errors and crashes automatically too:
23
23
```lua
24
-
-- If squid is initialized with init() it will handle errors and crashes automatically too
25
24
squid.init()
25
+
```
26
26
27
-
-- Define new tag strings and enable/disable them:
27
+
Define new tag strings and enable/disable them:
28
+
```lua
28
29
squid.set_allowed("main", true)
30
+
```
29
31
30
-
-- Use static logging functions with or without optional non-string data and/or tag string:
32
+
Use static logging functions with or without optional non-string data and/or tag string:
33
+
```lua
31
34
squid.trace("My Trace Message") -- no data and no tag, uses default tag ("none")
32
35
squid.debug("My Debug Message ", { my_test_data=1 }) -- with optional non-string data (default tag used)
33
36
squid.info( "My Info Message ", "main") -- with string data only (used as tag too)
34
37
squid.warn( "My Warning Message", "Hello World", "main") -- with string data and tag ("main" tag is used as tag here)
35
38
squid.error("My Error Message ", vmath.vector3(1), "main") -- with non-string data and tag
39
+
squid.log("My Other VIP Message", 6) -- Or generic logging function with own logging level
40
+
```
36
41
37
-
-- Or generic logging function with own logging level:
38
-
squid.log("My Other Message", squid.DEBUG)
42
+
It is ok to print directly numbers or other data too if they can be concatenated to string:
43
+
```lua
44
+
squid.warn(1.0)
45
+
squid.warn(vmath.vector3(1))
46
+
squid.warn(msg.url())
47
+
squid.warn(type(1))
48
+
squid.warn(hash"test")
49
+
```
39
50
40
-
--You can explicitly save any unsaved buffered logs to a file at any time:
41
-
--(logs are saved automatically anyway, in batch, every X logs if configured in game.project)
51
+
You can explicitly save any unsaved buffered logs to a file at any time (logs are saved automatically anyway, in batch, every X logs if configured in game.project):
52
+
```lua
42
53
squid.save_logs()
54
+
```
43
55
44
-
-- If squid.final() is called (in final() preferably) it checks for crash dumps and saves all unsaved buffered logs
56
+
If squid.final() is called (in final() preferably) it checks for crash dumps and saves all unsaved buffered logs:
57
+
```lua
45
58
squid.final()
46
59
```
47
60
@@ -60,15 +73,15 @@ For example (tables are always pretty printed):
-- Use all API function with the created instance:
120
+
Use all API function with the created instance:
121
+
```lua
107
122
self.player_logger:info("Logger with 'player' tag")
108
123
```
109
124
110
-
## Configuration
125
+
If you want to use Squid with Pigeon use:
126
+
```lua
127
+
pigeon.set_dependency_module_log( squid )
128
+
```
129
+
130
+
If you want to use Squid with Saver or Event use (they works with instantiated loggers):
131
+
```lua
132
+
saver.set_logger( squid.new("saver", true) )
133
+
event.set_logger( squid.new("event", true) )
134
+
```
135
+
136
+
---
137
+
138
+
# Configuration
111
139
112
140
Squid configuration can be set with user's custom one with `squid.set_config(your_config)`.
113
141
It has to be compatible with SquidConfig (you can use Lua Language Server to check it too).
114
142
You can get current configuration using `squid.get_config()`.
115
143
144
+
Get current configuration:
116
145
```lua
117
-
-- Get current configuration:
118
146
localmy_config=squid.get_config()
119
-
my_config.is_printing=false
147
+
```
120
148
121
-
-- Set new configuration:
149
+
Set new configuration:
150
+
```lua
151
+
my_config.is_printing=false
122
152
squid.set_config(my_config)
123
153
```
124
154
@@ -145,6 +175,8 @@ max_data_depth = 5
145
175
146
176
It can be then defined in `game.project` editor in Defold.
147
177
178
+
### Configuration
179
+
148
180
| Entry | Default | Type | Description |
149
181
|-|-|-|-|
150
182
|**app_catalog**|`squid_app_catalog`|*[string]*| Name of the catalog where file with logs is saved. Parent directory is the save file directory given by Defold sys API. It is operating system specific and is typically located under the user's home directory .e.g. `%appdata%` for Windows. For Linux it is aditionally prefixed with `config/`, so usually `~/config/`. For HTML5 it is only used as a prefix. |
@@ -162,30 +194,167 @@ It can be then defined in `game.project` editor in Defold.
162
194
|**max_data_length**| 1000 |*[integer]*| Maximum length of a data string |
163
195
|**max_data_depth**| 5 |*[integer]*| Maximum depth of a data table |
164
196
197
+
Note:
198
+
165
199
*[0/1]* might be replaced with boolean checkboxes when [it will be possible in Defold with this issue solved](https://github.com/defold/defold/issues/9981).
Finalize Squid logging - check for crashes and saved all unsaved buffered logs
302
+
303
+
---
304
+
### Squid.get_config()
305
+
Get Squid configuration
306
+
|| name | type | description |
307
+
|-|-|-|-|
308
+
| return | | SquidConfig | User configuration table compatible with SquidConfig
309
+
310
+
---
311
+
### Squid.set_config(config)
312
+
Set and use user configuration
313
+
|| name | type | description |
314
+
|-|-|-|-|
315
+
| param | config | SquidConfig | User configuration table compatible with SquidConfig
316
+
317
+
---
318
+
### Squid.new(tag, is_allowed)
319
+
Create a new instance of the Squid logger
320
+
|| name | type | description |
321
+
|-|-|-|-|
322
+
| param | tag? | string | Optional tag used for all logs when invoked within this instance
323
+
| param | is_allowed? | boolean | Optional flag to set if instance's tag is allowed to be logged initially
324
+
325
+
---
326
+
327
+
# Thanks
168
328
169
329
Squid is heavily inspired by [Log](https://github.com/subsoap/log) and [Err](https://github.com/subsoap/err) by Subsoap and [Defold Log](https://github.com/Insality/defold-log) by Insality and uses and iterates over some of their solutions. Squid tries to be compatible with both APIs for easier replacements.
170
330
171
331
If you like this module, you can show appreciation by supporting them. Insality is running [Github Sponsors](https://github.com/sponsors/insality), Ko-Fi, etc and [Subsoap create awesome games](https://www.subsoap.com/).
172
332
173
333
You can also support me here via [Github Sponsors](https://github.com/sponsors/paweljarosz), [Ko-Fi](https://ko-fi.com/witchcrafter) or [Patreon](https://www.patreon.com/witchcrafter_rpg) ^^
174
334
175
-
##Changelog
335
+
# Changelog
176
336
177
-
####1.0
337
+
### 1.0
178
338
* First public version release.
179
339
180
-
####1.1
340
+
### 1.1
181
341
* Removed Immutable dependency.
182
342
* Changed final message about no crashes to more friendly:
183
-
(```INFO: [squid]: [14:47:48] squid/squid.lua:122: No crashes, no dump found.```)
343
+
(e.g. ```INFO: [squid]: [14:47:48] squid/squid.lua:122: No crashes, no dump found.```)
184
344
* Added functions to get and set new squid configuration.
185
345
* Improved documentation.
186
346
347
+
### 1.2
348
+
* Fixed code address nesting level when using instantiated squid logger.
349
+
* Improved documentation and example script, added API documentation.
350
+
* Added message when saving logs and crashes with location of the saved file:
* Added default level to plain squid.log() function set as squid.INFO when no level is provided by user.
354
+
* Fixed Lua annotations when using instantiated squid logger.
355
+
* Fixed printing condition not working issue.
187
356
188
-
##License
357
+
# License
189
358
190
359
MIT
191
360
@@ -195,4 +364,4 @@ Permission is hereby granted, free of charge, to any person obtaining a copy of
195
364
196
365
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
197
366
198
-
THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
367
+
THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
0 commit comments