TomFrost / Bristol

Insanely configurable logging for Node.js
MIT License
113 stars 19 forks source link

Use with Express #9

Closed unphased closed 9 years ago

unphased commented 9 years ago

Hi, I'm curious about whether it is "proper" to just write a middleware function(req, res, next) that logs whatever I want about the request with Bristol, and then replace express morgan with this function.

TomFrost commented 9 years ago

Absolutely! Bristol isn't opinionated about where it gets used, so that's a perfectly sound use case. In fact, in most of my REST APIs, I do exactly that to log the request, and then again at the end to log the response. If you're looking at Koa now that 0.12.0 (or io.js) is out, that becomes even easier there.

Let me know if Bristol gave you any issues in this use case; otherwise we can close the ticket. Thanks!

unphased commented 9 years ago

Cool, I think we can close this because I don't know how much time it will take me to actually get around to trying out this library, and I'll open up new issues if I run into problems.

I would love to play with Koa but I think Express will do for now because it is familiar and my apps run on it. It was painful enough to port from Express 3 to Express 4.

I have been working in a project where my coworkers have been using promises with Q quite a bit, and I'll be honest, promises are hard to think about, and I think as a result this can slow down productivity a bit. Generators fit into my mind better, and as I understand it, they should be at least as powerful for supporting flow control as Promises are. I guess I'll want to learn to use nvm etc. and slowly migrate things over to node v0.12 before tinkering with Koa.

TomFrost commented 9 years ago

Sure thing, thanks!

Though for what it's worth, as you're on your journey to upgrading to the newest Node practices, generators are awesome but they're not a full replacement for promises. Promises, especially when used in conjunction with a full featured Promise library like Bluebird and Q (you should check out Bluebird -- mostly the same API as Q, worlds faster) will allow you to have much more control over concurrency and are indispensable when it comes to error handling. Generators, at their core, are really meant for on-the-fly generation of additional elements of a series. The libraries out there for using them in place of promises or callbacks largely hack their functionality to apply it to unrelated uses.

Not that that's necessarily a bad thing, mind you, but definitely something to consider when choosing the best tool for the job at hand. Best of luck!

unphased commented 9 years ago

Okay, thanks for the tips!