task: update README.md

This commit is contained in:
2026-01-03 09:07:50 +01:00
parent 9eed99ba47
commit e065809279
2 changed files with 39 additions and 73 deletions

106
README.md
View File

@@ -1,93 +1,59 @@
# LoggerAddon Documentation
# SimpleLogger
A comprehensive logging system for Godot that provides multiple log levels, timestamps, and file persistence.
Multi-level logging system for Godot with timestamps and file persistence.
## Features
- Multiple log levels (TRACE, DEBUG, INFO, WARN, ERROR)
- Optional timestamps for each log message
- File logging with automatic directory creation
- Both full and abbreviated function names
- Configurable log filtering by level
- 5 log levels: TRACE, DEBUG, INFO, WARN, ERROR
- Full and abbreviated function names
- Optional timestamps
- File logging with auto-directory creation
- Configurable argument separator
## Configuration
### Inspector Properties
## Properties
| Property | Type | Default | Description |
| --- | --- | --- | --- |
| `current_log_level` | LogLevel | DEBUG | Minimum log level to display |
| `enable_timestamp` | bool | true | Add timestamp to log messages |
| `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 |
## Log Levels
From lowest to highest priority:
- **TRACE**: Detailed debugging information
- **DEBUG**: General debugging information
- **INFO**: Informational messages
- **WARN**: Warning messages (displayed in yellow)
- **ERROR**: Error messages (displayed in red)
## Usage
### Full Function Names
```gdscript
Logger.trace("Detailed trace message", variable1, variable2)
Logger.debug("Debug information", value)
Logger.info("Application started")
Logger.warning("This is a warning")
Logger.error("An error occurred", error_code)
# 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
```
### Abbreviated Function Names
```gdscript
Logger.t("Trace", data)
Logger.d("Debug", data)
Logger.i("Info", data)
Logger.w("Warning", data)
Logger.e("Error", data)
## Output Format
```
## Log Output Format
**With timestamp:**
[HH:MM:SS]|[LEVEL ]: Message # With timestamp
[LEVEL ]: Message # Without timestamp
```
[HH:MM:SS]|[LEVEL ]: Message content
```
**Without timestamp:**
```
[LEVEL ]: Message content
```
## File Logging
When `save_log` is enabled:
1. Logs are saved to the specified file path
2. Directories are created automatically if they don't exist
3. Messages are appended to the file (not overwritten)
4. File operations are handled safely with error checking
### Example Configuration
```gdscript
Logger.current_log_level = LogLevel.DEBUG
Logger.enable_timestamp = true
Logger.save_log = true
Logger.folder = "user://logs/"
Logger.log_filename = "game.log"
```
## Tips
- Set `current_log_level` to `LogLevel.ERROR` in production to reduce console spam
- Use TRACE and DEBUG for development, remove them before shipping
- Combine multiple arguments in a single call for cleaner logs
- File logging automatically creates missing directories
## MIT License

View File

@@ -44,9 +44,9 @@ func _print(level: LogLevel, ...args: Array) -> void:
var level_str:String = LogLevel.keys()[level]
var timestamp := Time.get_time_string_from_system()
var text: String = ""
for i:int in args.size():
text += str(args[i])
if i < args.size() - 1:
for c:int in args.size():
text += str(args[c])
if c < args.size() - 1:
text += self.separator
var message:String = LOG_FORMAT_TIMESTAMP % [