From 64f39f93bf0ef36cde9b9940cbb09826e1ba82f7 Mon Sep 17 00:00:00 2001 From: Matthew Scott Date: Tue, 9 Mar 2021 19:33:31 -0700 Subject: [PATCH] Added new config option with readme documentation --- README.md | 21 ++++++++++++++++++++- package.json | 2 +- splunklogger.js | 4 ++++ 3 files changed, 25 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 9c93d7b..c8d8d2f 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ # Splunk logging for JavaScript -#### Version 0.10.1 +#### Version 0.10.2 This project provides a simple JavaScript interface for logging to HTTP Event Collector in Splunk Enterprise and Splunk Cloud. @@ -49,6 +49,25 @@ var Logger = new SplunkLogger(config); Logger.requestOptions.strictSSL = true; ``` +### Configure Http Keep-Alive Agent + +Note: No default agent configuration is configured by default. +To enable it, set `config.agent` to a valid http Agent (i.e. https://nodejs.org/api/http.html#http_new_agent_options) + +```javascript +var SplunkLogger = require("splunk-logging").Logger; +var Agent = require('http').Agent +var agent = new Agent({ keepAlive: true }) + +var config = { + token: "your-token-here", + url: "https://splunk.local:8088", + agent: agent, +}; + +var Logger = new SplunkLogger(config); +``` + ### Basic example ```javascript diff --git a/package.json b/package.json index 4ad97db..8cde3a9 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "splunk-logging", - "version": "0.10.1", + "version": "0.10.2", "description": "Splunk HTTP Event Collector logging interface", "homepage": "http://dev.splunk.com", "main": "index.js", diff --git a/splunklogger.js b/splunklogger.js index 7524f7f..5116fe2 100644 --- a/splunklogger.js +++ b/splunklogger.js @@ -434,6 +434,10 @@ SplunkLogger.prototype._sendEvents = function(context, callback) { // since json is set to true. requestOptions.headers["Content-Type"] = "application/x-www-form-urlencoded"; requestOptions.url = this.config.protocol + "://" + this.config.host + ":" + this.config.port + this.config.path; + + if (this.config.agent) { + requestOptions.agent = this.config.agent; + } // Initialize the context again, right before using it context = this._initializeContext(context);