raldone01 / godot_addon_gdlogging

Logging addon for godot 4
MIT License
11 stars 0 forks source link

Add syntactic sugar #4

Open smedelyan opened 2 months ago

smedelyan commented 2 months ago

Hi. It would be great to add helper functions to reduce the boilerplate when creating complex scenarios. I added the following functions locally, but maybe worth implementing similar approach in this repo:

class LogSink extends RefCounted:
# ...
    func buffered(buffer_size: int = 20) -> LogSink:
        return BufferedPipe.new(self, buffer_size)
    func filtered(p_level: LogLevel) -> LogSink:
        return FilteringPipe.new(self, p_level)

Usage:

# first - filters, then - buffers, then - pushes to console
var console: Log.LogSink = Log.ConsoleSink.new().buffered(20).filtered(Log.LogLevel.DEBUG)
raldone01 commented 2 months ago

Yeah some sort of builder api would be very nice. I thought about this approach but it is backwards to the way I would like it to be. I think it's counter intuitive to assemble the chain sink to source.