How to customise the default logs of micro gateway and store them in splunk server.
The microgateway config file has
edgemicro: port: 8000 max_connections: 1000 config_change_poll_interval: 600 logging: level: error dir: /var/tmp stats_log_interval: 60 rotate_interval: 24
You can increase the log level to info. Logs are written to the dir (default /var/tmo) in the config file. I'm no expert in Splunk, but it should be able to read the logs files from the file system.
Write Custom Plugin using the "Bunyan"
var bunyan = require("bunyan");
var splunkBunyan = require("splunk-bunyan-logger");
var config = { token: "your-token-here", url: "https://splunk.local:8088" };
var splunkStream = splunkBunyan.createStream(config);
// Enable SSL certificate validation
stream.logger.requestOptions.strictSSL = true;
// Note: splunkStream must be set to an element in the streams array
module.exports.init = function() {
//use either bunyan OR splunkBunyan to createLogger()
var log = bunyan.createLogger(
{ name: "my logger", streams: [
{ level: 'error', stream: splunkStream },
{ level: 'debug', stream: process.stderr, },
{ level: 'info', type: 'rotating-file', path: '/var/log/foo.log', period: '1d' <!-- daily rotation--> , count: 3 <!-- keep 3 back copies--> }
]
});
return { onrequest: function(req, res, next)
{
log.info('ONREQUEST'); next();
}, onend_request: function(req, res, data, next) { log.info("ONEND_REQUEST"); next(null, data);
}
};
}
//referrer
// https://npm.taobao.org/package/splunk-bunyan-logger
// https://www.npmjs.com/package/bunyan#streams
//Installation
//npm install --save splunk-bunyan-logger
User | Count |
---|---|
5 | |
2 | |
1 | |
1 | |
1 |