feat: add caller script & filters & timers

- add caller script in print
- add filters to blacklist or whitelist script logs to be shown
- add timer to check performance easily
This commit is contained in:
2026-01-31 17:18:15 +01:00
parent e065809279
commit a748d77e32
2 changed files with 148 additions and 60 deletions

114
README.md
View File

@@ -1,59 +1,77 @@
# SimpleLogger
Multi-level logging system for Godot with timestamps and file persistence.
Lightweight logging system for Godot 4.5+
## Features
- 5 log levels: TRACE, DEBUG, INFO, WARN, ERROR
- Full and abbreviated function names
- Optional timestamps
- File logging with auto-directory creation
- Configurable argument separator
- 5 log levels (TRACE, DEBUG, INFO, WARN, ERROR)
- Caller script tracking
- Script filtering (blacklist/whitelist)
- Performance profiling
- Optional file persistence
- Configurable timestamps and separators
## Quick Start
```gdscript
Log.i("Player spawned")
Log.d("Health:", player.health, "Position:", player.position)
Log.e("Failed to load resource", path)
```
Output:
```
[12:34:56][player ][INFO ]: Player spawned
[12:34:56][player ][DEBUG ]: Health: 100 Position: (0, 0)
[12:34:56][resource_load][ERROR ]: Failed to load resource res://missing.png
```
## API
### Log Levels
| Full | Short | Use case |
|------|-------|----------|
| `trace()` | `t()` | Granular debugging |
| `debug()` | `d()` | Development info |
| `info()` | `i()` | General events |
| `warning()` | `w()` | Potential issues |
| `error()` | `e()` | Failures |
### Filtering
```gdscript
Log.mute("chunk_generator.gd")
Log.unmute("chunk_generator.gd")
Log.set_blacklist(["map.gd", "noise.gd"])
Log.set_whitelist(["player.gd", "enemy.gd"])
Log.clear_filters()
```
### Performance
```gdscript
Log.time_start("pathfinding")
# ... code ...
Log.time_end("pathfinding")
# Output: [DEBUG ]: PERF pathfinding 12.34ms
```
### Separator
```gdscript
Log.set_separator(" | ")
Log.set_separator(" -> ", true) # one-time only
```
## Properties
| Property | Type | Default | Description |
| --- | --- | --- | --- |
| `current_log_level` | LogLevel | DEBUG | Minimum log level to display |
| `enable_timestamp` | bool | true | Add timestamp to messages |
| `save_log` | bool | false | Save logs to file |
| `separator` | String | " " | Separator between arguments |
| `folder` | String | "" | Directory for log files |
| `log_filename` | String | "addons/Logs/data.log" | Log file path |
## Usage
```gdscript
# Full names
Log.trace("message", var1, var2)
Log.debug("message", data)
Log.info("message")
Log.warning("message")
Log.error("message", error_code)
# Abbreviated
Log.t("message", var1)
Log.d("message", data)
Log.i("message")
Log.w("message")
Log.e("message")
# Custom separator
Log.set_separator(", ")
Log.info("a", "b", "c") # [INFO ]: a, b, c
# One-time separator
Log.set_separator(" | ", true)
Log.info("x", "y") # [INFO ]: x | y
Log.info("a", "b") # [INFO ]: a b
```
## Output Format
```
[HH:MM:SS]|[LEVEL ]: Message # With timestamp
[LEVEL ]: Message # Without timestamp
```
| Property | Default | Description |
|----------|---------|-------------|
| `current_log_level` | DEBUG | Minimum level to display |
| `enable_timestamp` | true | Show timestamps |
| `enable_caller` | true | Show calling script |
| `save_log` | false | Write to file |
| `filter_mode` | BLACKLIST | Filter behavior |
| `folder` | "" | Log directory |
| `log_filename` | "addons/Logs/data.log" | Log file path |
## MIT License