Created
September 28, 2012 14:36
-
-
Save erichelgeson/3800231 to your computer and use it in GitHub Desktop.
Example use of winston-splunk
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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