{"library":"splunk-bunyan-logger","title":"Splunk HTTP Event Collector Stream for Bunyan","type":"library","description":"The `splunk-bunyan-logger` package provides a Bunyan stream specifically designed to send structured log data to Splunk Enterprise or Splunk Cloud via the HTTP Event Collector (HEC). It acts as a bridge, allowing applications using the Bunyan JSON logging library to seamlessly integrate with Splunk's data ingestion capabilities. The current stable version is 0.11.0. While no explicit release cadence is provided, the recent update (0.11.0) indicates active maintenance, with the last update fixing deprecated internal dependencies. Key differentiators include its tight integration with Bunyan's streaming architecture, batching capabilities for efficient data transfer, and support for custom event formatting. It requires Node.js v4 or later (tested with v10 and v14) and Splunk Enterprise 6.3.0 or later, or Splunk Cloud.","language":"javascript","status":"active","last_verified":"Thu Apr 23","install":{"commands":["npm install splunk-bunyan-logger"],"cli":null},"imports":["const splunkBunyan = require('splunk-bunyan-logger');","const splunkBunyan = require('splunk-bunyan-logger');\nconst splunkStream = splunkBunyan.createStream(config);","const bunyan = require('bunyan');\nconst Logger = bunyan.createLogger({ name: 'my logger', streams: [splunkStream] });"],"auth":{"required":false,"env_vars":[]},"links":{"homepage":"https://www.npmjs.com/package/splunk-bunyan-logger","github":"https://github.com/splunk/splunk-bunyan-logger","docs":null,"changelog":null,"pypi":null,"npm":"https://www.npmjs.com/package/splunk-bunyan-logger","openapi_spec":null,"status_page":null,"smithery":null},"quickstart":{"code":"const bunyan = require(\"bunyan\");\nconst splunkBunyan = require(\"splunk-bunyan-logger\");\n\nconst config = {\n    token: process.env.SPLUNK_HEC_TOKEN ?? \"your-splunk-hec-token-here\",\n    url: process.env.SPLUNK_HEC_URL ?? \"https://splunk.local:8088\"\n};\n\n// Create a SplunkStream instance\nconst splunkStream = splunkBunyan.createStream(config);\n\n// Optional: Add an error handler for the stream\nsplunkStream.on(\"error\", (err, context) => {\n    // Log error, update metric, etc.\n    console.error(\"Splunk HEC Logger Error:\", err, context);\n});\n\n// Create a Bunyan Logger instance, adding the SplunkStream\nconst Logger = bunyan.createLogger({\n    name: \"my-application-logger\",\n    streams: [\n        { stream: process.stdout, level: \"info\" }, // Also log to console\n        splunkStream\n    ]\n});\n\nconst payload = {\n    // Message can be anything, doesn't have to be an object\n    message: {\n        temperature: \"72F\",\n        humidity: \"60%\",\n        sensorId: \"TH-001\"\n    },\n    // Custom metadata for Splunk (optional)\n    sourcetype: \"_json\",\n    source: \"my-node-app\"\n};\n\nconsole.log(\"Sending payload to Splunk HEC...\");\nLogger.info(payload, \"Environment sensor data collected.\");\nLogger.warn(\"Potential anomaly detected in sensor readings.\");\nconsole.log(\"Payload sent (asynchronously).\");\n","lang":"javascript","description":"This example demonstrates how to configure a Bunyan logger with the `splunk-bunyan-logger` stream to send structured logs to Splunk HTTP Event Collector. It includes basic error handling and uses environment variables for sensitive configuration.","tag":null,"tag_description":null,"last_tested":null,"results":[]},"compatibility":null}