Sets up logging to a TaggedLogger for important http.Server events
npm install winston-tagged-http-logger
var server = require'http'createServer;// create our winston loggervar winston = require'winston';var winstonLogger = ;// create a transport so our logs have somewhere to govar TaggedConsoleTarget = require'tagged-console-target';winstonadd;// make a new tagged logger to generate tagged log messagesvar TaggedLogger = require'tagged-logger';var logger = winstonLogger 'my amazing server';// Use this module to pipe the events from an http server to the loggerrequire'winston-tagged-http-logger'server log;// All done! Events from `server` are now being piped to our `logger`!
- When the server starts running, showing the host and port that the server started on.
- When a request is responded to, the client, path, status code, method and response time are logged.
Why, take a look! Here's an example of a log:
19:35:53.255 2013-06-26 Wednesday19:35:53.589 [kvass, http] Listening on 0.0.0.0:950619:36:06.359 [kvass, http, 127.0.0.1:50230] GET /user/active 200 12ms
Broken down, these are the parts of a request log:
19:36:06.359the time on the server at which the request was received
[kvass, http,tags that have been assigned to this logger
127.0.0.1:50230]a tag representing the origin of the request
GETthe request method
/user/activethe requested path
200the response status code
12msthe time it took to respond to the request