scrolls
scrolls copied to clipboard
Log hooks/middlewares
I would like to use Scrolls as a single logging pipe, but what I need to do is also have a way to capture that data via another (additional) mechanism than the STDOUT
stream, for instance, a small class I wrote to store logs directly into Postgres. What would solve this nicely would be to register a hook with scrolls that is invoked when something is written to the logs:
Scrolls.hook(lambda { |data| MyClass.log(data) })
Better yet, we can use the Rack approach and have these hooks respond to #call
, allowing something like:
Scrolls.hook MyClass
Scrolls.hook MyClass.new
I'd recommend that, for convenience, this method can also take a block that is automatically treated as a lambda function:
Scroll.hook { |data| MyClass.log(data) }
What do you think?
@wuputah Yeah, this is where I am heading. Though I wasn't thinking additional outputs, but I like the idea. I was more focused on being able to replace the output method the same way you would a stream.
I like the idea of hooks.
Cool. I might be able to code something up for a pull request, though feel free to beat me to it.
I still really like this idea and will pursue it after my refactor work to clean up the code base in https://github.com/asenchi/scrolls/pull/71.