gliderlabs / logspout

Log routing for Docker container logs
MIT License
4.66k stars 680 forks source link

Middleware style adapters #196

Open treeder opened 8 years ago

treeder commented 8 years ago

While working on creating an adapter, I have it sending all logs to papertrail and my adapter sends certain lines to another service if they contain a specific value. If my adapter processes a line, I don't want it to also go to papertrail. So first of all, is there a way to stop other adapters from processing the message? If this is already there, then ignore the rest of this issue. ❓

I couldn't find a way, which made me think that middleware style adapters would be nice. So you could tell logspout to stop giving the message to other adapters. Something like gin middleware: https://github.com/gin-gonic/gin#custom-middleware

For instance, an adapter could have a Handler function, say:

type HandlerFunc func(*Context, *router.Message)

Then you could chain these. Context could have an Abort() function that would stop the chain.

josegonzalez commented 8 years ago

@michaelshobbs thoughts?

michaelshobbs commented 8 years ago

That's interesting. I know logspout has a way to ignore certain containers but this is at the adapter level. @mattaitchison is this something that can be achieved with routes?

treeder commented 8 years ago

I played with this a bit, trying to use routes at first, but it turns out the cp.logstreams array isn't in any predictable order.

I got a proof of concept going here: https://github.com/iron-io/logspout/pull/2

It's a little bit hacked together to make it work with the current logspout implementation, but it works and includes an example Handler. Adapters continue to work the same way too. User can user adapters and/or handlers. User can also add handlers with ONBUILD, the same way too, as you can see here: https://github.com/iron-io/logspout/pull/2/files#diff-c00d979dbff09c1ff576b1aa1d5a0480R18