Skip to content

Instantly share code, notes, and snippets.

@erichelgeson
Created September 28, 2012 14:36
Show Gist options
  • Save erichelgeson/3800231 to your computer and use it in GitHub Desktop.
Save erichelgeson/3800231 to your computer and use it in GitHub Desktop.
Example use of winston-splunk
var winston = require('winston');
var options = {};
// Override logging options here
options.splunkHostname = 'node-server';
// No console, only Splunk!
winston.add(require('winston-splunk').splunk, options);
winston.remove(winston.transports.Console);
var http = require('http');
http.createServer(function (req, res) {
// Log Request Headers
winston.info("headers", req.headers);
res.writeHead(200, {'Content-Type': 'text/plain'});
// Serving up content
res.end('Hello Splunk!\n');
// Log other interesting elements from request json obj
var logReq = {};
logReq.bytesWritten = req.bytesWritten;
logReq.url = req.url;
logReq.method = req.method;
logReq.statusCode = req.statusCode;
winston.info("request", logReq);
// Log interesting elements from response
var logRes = {}
logRes.statusCode = res.statusCode;
logRes.headers = res._header;
winston.info("response", logRes);
}).listen(1337, '0.0.0.0');
winston.info('Server running at http://127.0.0.1:1337/');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment