A Winston transport for logging to Splunk with a HTTP Event Collector.
npm install --save winston winston-splunk-httplogger
var winston = require('winston'),
SplunkStreamEvent = require('winston-splunk-httplogger');
var splunkSettings = {
token: process.env.SPLUNK_TOKEN,
host: process.env.SPLUNK_HOST || 'localhost'
};
// Now use winston as normal
var logger = new winston.Logger({
transports: [
new winston.transports.Console(),
new SplunkStreamEvent({ splunk: splunkSettings })
]
});
logger.info('This is sent to Splunk');
- Log into your Splunk instance as an Administrator
- Go to Settings > Data Inputs
- Click on HTTP Event Collector under Local inputs
- Click on New Token
- Walk through the wizard to configure your new HTTP Event Collector
Splunk will provide you with a token at the end of the wizard. You need to insert that token into the splunk object you use to create the SplunkStreamEvent() object. In the example above, this is done by placing the token in the SPLUNK_TOKEN environment variable.