-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
269 additions
and
176 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,7 +9,7 @@ This is a composable logging addon for version 4 of the [Godot game engine](http | |
## Usage | ||
|
||
```gdscript | ||
var console_sink := Log.ConsoleSink.new() | ||
var console_sink := Log.ConsoleRichSink.new() | ||
Log.add_sink(console_sink) | ||
var dir_sink := Log.DirSink.new("mylog", "res://logs", 4042) | ||
|
@@ -54,24 +54,26 @@ timer.stop() | |
* `FilteringPipe`: Filters messages by level and forwards them to another sink. | ||
* `BroadcastPipe`: Broadcasts messages to multiple sinks. | ||
* `BufferedPipe`: Buffers messages and forwards them to another sink. | ||
* `FormattingPipe`: Formats messages and forwards them to another sink. | ||
* `Logger`: Can receive messages from other Loggers and Sinks. Users will call the log functions which format the message. | ||
|
||
## Sinks | ||
|
||
* `ConsoleSink`: Outputs messages to the console. | ||
* `ConsoleSink`: Outputs messages to stderr and stdout. Does not support colors. | ||
* `ConsoleRichSink`: Outputs messages to the godot Output console. Supports colors. | ||
* `DirSink`: Outputs messages to log files and rotates them. Uses a thread for file io. | ||
* `Logger`: Can receive messages from other Loggers and Sinks. Users will call the log functions which format the message. | ||
* `MemoryWindowSink`: Keeps `n` log messages in memory. Can be used to display the last `n` messages in a GUI. | ||
* `MemoryWindowSink`: Keeps `n` log messages in memory. Can be used to display the last `n` messages in a GUI. BBCode color support can be configured. | ||
|
||
## Custom Sinks/Pipes | ||
|
||
Classes ending in `Pipe` are sinks that forward messages to another sink. | ||
Classes ending in `Sink` write messages to a destination. | ||
|
||
To create a custom sink extend the `Log.LogSink` and implement the methods. | ||
To create a custom pipe or sink extend the `Log.LogPipe` or `Log.LogSink` respectively and implement the methods. | ||
|
||
```gdscript | ||
class MyCustomSink extends Log.LogSink: | ||
# LogPipe and LogSink functions below | ||
## Write many log records to the sink | ||
func write_bulks(p_log_records: Array[Dictionary], p_formatted_messages: PackedStringArray) -> void: | ||
pass | ||
|
@@ -81,13 +83,24 @@ class MyCustomSink extends Log.LogSink: | |
## Cleans up resources used by the sink. | ||
func close() -> void: | ||
pass | ||
# LogSink specific functions below | ||
## Sets the log record formatter. | ||
func set_log_record_formatter(p_log_record_formatter: LogRecordFormatter) -> void: | ||
pass | ||
## Gets the log record formatter. | ||
func get_log_record_formatter() -> LogRecordFormatter: | ||
pass | ||
``` | ||
|
||
## Custom Formatters | ||
|
||
```gdscript | ||
class MyLogRecordFormatter extends Log.LogRecordFormatter: | ||
func format(log_record: Dictionary) -> String: | ||
func format(log_record: Dictionary, p_sink_capabilties: Dictionary) -> String: | ||
# currently only the bbcode capability is used but user sinks can add their own capabilities | ||
var time_unix: float = log_record["time_unix"] | ||
var level: Log.LogLevel = log_record["level"] | ||
var unformatted_message: String = log_record["unformatted_message"] | ||
|
@@ -100,7 +113,7 @@ class MyLogRecordFormatter extends Log.LogRecordFormatter: | |
unformatted_message | ||
] | ||
return formatted_message | ||
# Logger use the global formatter by default but this can be overridden in the constructor. | ||
# Loggers use the global formatter by default but this can be overridden in the constructor. | ||
Log.set_log_record_formatter(MyLogRecordFormatter.new()) | ||
``` | ||
|
||
|
@@ -111,13 +124,20 @@ cd <godot_project_dir> | |
cd addons | ||
git submodule add [email protected]:raldone01/godot_addon_gdlogging.git gdlogging | ||
cd gdlogging | ||
git checkout v1.1.0 | ||
git checkout v2.0.0 | ||
``` | ||
|
||
`Project -> Project Settings -> Plugins -> gdlogging -> Activate` | ||
|
||
Autoloads are a bit janky so you may need to restart the editor for errors to go away. | ||
|
||
## Troubleshooting | ||
|
||
> [!CAUTION] | ||
> Deleting the `.godot` directory has the potential to cause data loss. Make sure to back up your project before doing so and carefully research the implications. | ||
If there are errors when loading the plugin that persist after restarting the editor, try deleting the `.godot` directory in the project directory. | ||
|
||
## Licensing | ||
|
||
Marked parts are licensed under the `LICENSE-godot-logger.md` (MIT) license. | ||
|
Oops, something went wrong.