task: update README.md
This commit is contained in:
106
README.md
106
README.md
@@ -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
|
## Features
|
||||||
|
|
||||||
- Multiple log levels (TRACE, DEBUG, INFO, WARN, ERROR)
|
- 5 log levels: TRACE, DEBUG, INFO, WARN, ERROR
|
||||||
- Optional timestamps for each log message
|
- Full and abbreviated function names
|
||||||
- File logging with automatic directory creation
|
- Optional timestamps
|
||||||
- Both full and abbreviated function names
|
- File logging with auto-directory creation
|
||||||
- Configurable log filtering by level
|
- Configurable argument separator
|
||||||
|
|
||||||
## Configuration
|
## Properties
|
||||||
|
|
||||||
### Inspector Properties
|
|
||||||
|
|
||||||
| Property | Type | Default | Description |
|
| Property | Type | Default | Description |
|
||||||
| --- | --- | --- | --- |
|
| --- | --- | --- | --- |
|
||||||
| `current_log_level` | LogLevel | DEBUG | Minimum log level to display |
|
| `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 |
|
| `save_log` | bool | false | Save logs to file |
|
||||||
|
| `separator` | String | " " | Separator between arguments |
|
||||||
| `folder` | String | "" | Directory for log files |
|
| `folder` | String | "" | Directory for log files |
|
||||||
| `log_filename` | String | "addons/Logs/data.log" | Log file path |
|
| `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
|
## Usage
|
||||||
|
|
||||||
### Full Function Names
|
|
||||||
```gdscript
|
```gdscript
|
||||||
Logger.trace("Detailed trace message", variable1, variable2)
|
# Full names
|
||||||
Logger.debug("Debug information", value)
|
Log.trace("message", var1, var2)
|
||||||
Logger.info("Application started")
|
Log.debug("message", data)
|
||||||
Logger.warning("This is a warning")
|
Log.info("message")
|
||||||
Logger.error("An error occurred", error_code)
|
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
|
## Output Format
|
||||||
```gdscript
|
|
||||||
Logger.t("Trace", data)
|
|
||||||
Logger.d("Debug", data)
|
|
||||||
Logger.i("Info", data)
|
|
||||||
Logger.w("Warning", data)
|
|
||||||
Logger.e("Error", data)
|
|
||||||
```
|
```
|
||||||
|
[HH:MM:SS]|[LEVEL ]: Message # With timestamp
|
||||||
## Log Output Format
|
[LEVEL ]: Message # Without timestamp
|
||||||
|
|
||||||
**With 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
|
## MIT License
|
||||||
|
|||||||
@@ -44,9 +44,9 @@ func _print(level: LogLevel, ...args: Array) -> void:
|
|||||||
var level_str:String = LogLevel.keys()[level]
|
var level_str:String = LogLevel.keys()[level]
|
||||||
var timestamp := Time.get_time_string_from_system()
|
var timestamp := Time.get_time_string_from_system()
|
||||||
var text: String = ""
|
var text: String = ""
|
||||||
for i:int in args.size():
|
for c:int in args.size():
|
||||||
text += str(args[i])
|
text += str(args[c])
|
||||||
if i < args.size() - 1:
|
if c < args.size() - 1:
|
||||||
text += self.separator
|
text += self.separator
|
||||||
|
|
||||||
var message:String = LOG_FORMAT_TIMESTAMP % [
|
var message:String = LOG_FORMAT_TIMESTAMP % [
|
||||||
|
|||||||
Reference in New Issue
Block a user