Connect-style request logger

46 views
Skip to first unread message

Daniel Radetsky

unread,
Jan 21, 2014, 6:07:42 PM1/21/14
to res...@googlegroups.com
Sup homies:

I wrote a connect/expressjs-style request logger for restify. I started messing with restify and I wanted one (it's hard to learn something without logs for feedback), and when I searched for one, I found somebody else asking for one, so I wrote one. It's at https://github.com/dradetsky/restify-dev-logger, or npm install restify-dev-logger. Feel free to tell me how shit my code is.

Love and kisses,
--D

Daniel Radetsky

unread,
Jan 21, 2014, 10:17:11 PM1/21/14
to res...@googlegroups.com
Disregard this; it doesn't work. 

Daniel Radetsky

unread,
Jan 22, 2014, 1:47:01 AM1/22/14
to res...@googlegroups.com
I don't entirely understand why at the moment, but it looks like:

1. The logger package I wrote logs 200s, 300s, and 500s, but not 400's (i.e. 404s; important).

2. The simple logger described in https://groups.google.com/forum/#!topic/restify/iLRiYz3Fko0 logs 200s, 300s, and 400s, but not 500s (also important).

I could write some hacky, special-purpose code in my particular project, but IMO it should be possible for one logging system to log all requests, a la express. People trying to figure out how to use restify need feedback from the system to understand what's going on, at least if they think like me.

From what I can tell, my guess is that (1) happens because of the special-purpose handling given to 404s by emitRouteError, except that this doesn't make sense because 404s get a json response which presumably comes from res.send, which means httpResponse.end is called, which means that 'finish' is emitted, which ought to trigger the logger. But it doesn't. 

And my guess was that (2) happens because of the special handling of general errors (server.js's createServer, line 81, "server.on('uncaughtException',...)"), in which the 'after' event is not emitted as normal.

Or not. Like I say, I don't really understand it yet.

Just for fun, I tried sticking server.emit('after') at the end of the callback on line 81, activating the type-(2) logger, and browsing a route with an error (reading a property of null). The result was it printed the stack trace and crashed rather than logging anything or continuing.


--
You received this message because you are subscribed to a topic in the Google Groups "restify" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/restify/_dMtBXS55Yo/unsubscribe.
To unsubscribe from this group and all its topics, send an email to restify+u...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.

Reply all
Reply to author
Forward
0 new messages