{"library":"splunk-logging","title":"Splunk Logging for JavaScript","type":"library","description":"The `splunk-logging` package provides a straightforward JavaScript interface for Node.js applications to send log data to Splunk Enterprise or Splunk Cloud via the HTTP Event Collector (HEC). The current stable version is 0.11.1, with releases occurring periodically to address dependencies and minor enhancements rather than a fixed cadence. This library simplifies the process of sending events by handling connection details, batching, and retries automatically. Key features include configurable batching settings (interval, maximum count, and maximum size), support for custom event formatting, and options for SSL certificate validation. While primarily community-supported, it is an official Splunk project designed for seamless integration with Splunk HEC endpoints, making it a robust choice for Node.js-based logging into the Splunk ecosystem.","language":"javascript","status":"active","last_verified":"Wed Apr 22","install":{"commands":["npm install splunk-logging"],"cli":null},"imports":["import { Logger } from 'splunk-logging';","const { Logger } = require('splunk-logging');","var SplunkLogger = require('splunk-logging').Logger;"],"auth":{"required":false,"env_vars":[]},"links":{"homepage":"https://www.splunk.com","github":"https://github.com/splunk/splunk-javascript-logging","docs":null,"changelog":null,"pypi":null,"npm":"https://www.npmjs.com/package/splunk-logging","openapi_spec":null,"status_page":null,"smithery":null},"quickstart":{"code":"import { Logger } from 'splunk-logging';\n\nconst config = {\n    token: process.env.SPLUNK_HEC_TOKEN ?? '',\n    url: process.env.SPLUNK_HEC_URL ?? 'https://splunk.local:8088'\n};\n\nconst splunkLogger = new Logger(config);\n\n// Optionally enable SSL certificate validation (highly recommended for production)\n// splunkLogger.requestOptions.strictSSL = true;\n\nconst payload = {\n    // Message can be anything; doesn't have to be an object\n    message: {\n        service: 'my-node-app',\n        level: 'info',\n        event_id: Math.floor(Math.random() * 1000000),\n        details: 'User activity logged successfully.',\n        timestamp: new Date().toISOString()\n    },\n    // Optional metadata\n    metadata: {\n        source: 'my-node-app',\n        sourcetype: 'node:json',\n        host: 'my-server'\n    }\n};\n\nconsole.log('Sending payload', JSON.stringify(payload, null, 2));\nsplunkLogger.send(payload, function(err, resp, body) {\n    if (err) {\n        console.error('Error sending data to Splunk:', err);\n        return;\n    }\n    // If successful, body will be { text: 'Success', code: 0 }\n    console.log('Response from Splunk:', body);\n});\n","lang":"typescript","description":"Demonstrates configuring a Splunk logger with environment variables for token and URL, then sending a structured JSON payload to the HTTP Event Collector, and logging the Splunk response.","tag":null,"tag_description":null,"last_tested":null,"results":[]},"compatibility":null}