scrolls icon indicating copy to clipboard operation
scrolls copied to clipboard

Log hooks/middlewares

Open wuputah opened this issue 12 years ago • 3 comments

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 avatar Jun 20 '12 05:06 wuputah

@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.

asenchi avatar Jun 20 '12 13:06 asenchi

Cool. I might be able to code something up for a pull request, though feel free to beat me to it.

wuputah avatar Jun 21 '12 01:06 wuputah

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.

asenchi avatar Aug 31 '17 23:08 asenchi