|
| 1 | +# Splunk Logging Library for JavaScript (beta) |
| 2 | + |
| 3 | +#### Version 0.8.0 |
| 4 | + |
| 5 | +This project provides a simple interface for logging to Splunk's Event Collector. |
| 6 | + |
| 7 | +## Requirements |
| 8 | + |
| 9 | +* Splunk 6.3+. |
| 10 | +* Node.js v0.10+. |
| 11 | +* An HTTP Event Collector token from your Splunk server. |
| 12 | + |
| 13 | +## Installation |
| 14 | + |
| 15 | +If you already have Node.js and npm installed, simply run: `npm install --save splunk-logging`. |
| 16 | + |
| 17 | +## Usage |
| 18 | + |
| 19 | +See the `examples` folder for more examples: |
| 20 | + |
| 21 | +* `basic.js`: shows how to configure a logger and send a log message to Splunk. |
| 22 | +* `batching.js`: shows how to queue log messages, and send them in batches. |
| 23 | +* `middleware.js`: shows how to add an express-like middleware function to be called before sending log messages to Splunk. |
| 24 | + |
| 25 | +### Basic example |
| 26 | + |
| 27 | +```javascript |
| 28 | +var SplunkLogger = require("splunk-logging").Logger; |
| 29 | + |
| 30 | +var config = { |
| 31 | + token: "your-token-here", |
| 32 | + url: "https://splunk.local:8088" |
| 33 | +}; |
| 34 | + |
| 35 | +var Logger = new SplunkLogger(config); |
| 36 | + |
| 37 | +var payload = { |
| 38 | + // Message can be anything, doesn't have to be an object |
| 39 | + message: { |
| 40 | + temperature: "70F", |
| 41 | + chickenCount: 500 |
| 42 | + }, |
| 43 | + // Severity is also optional |
| 44 | + severity: "info" |
| 45 | +}; |
| 46 | + |
| 47 | +console.log("Sending payload", payload); |
| 48 | +Logger.send(payload, function(err, resp, body) { |
| 49 | + // If successful, body will be { text: 'Success', code: 0 } |
| 50 | + console.log("Response from Splunk", body); |
| 51 | +}); |
| 52 | +``` |
| 53 | + |
| 54 | +## Community |
| 55 | + |
| 56 | +Stay connected with other developers building on Splunk. |
| 57 | + |
| 58 | +<table> |
| 59 | + |
| 60 | +<tr> |
| 61 | +<td><b>Email</b></td> |
| 62 | + |
| 63 | +</tr> |
| 64 | + |
| 65 | +<tr> |
| 66 | +<td><b>Issues</b> |
| 67 | +<td><span>https://github.com/splunk/splunk-logging-javascript/issues/</span></td> |
| 68 | +</tr> |
| 69 | + |
| 70 | +<tr> |
| 71 | +<td><b>Answers</b> |
| 72 | +<td><span>http://answers.splunk.com/</span></td> |
| 73 | +</tr> |
| 74 | + |
| 75 | +<tr> |
| 76 | +<td><b>Blog</b> |
| 77 | +<td><span>http://blogs.splunk.com/dev/</span></td> |
| 78 | +</tr> |
| 79 | + |
| 80 | +<tr> |
| 81 | +<td><b>Twitter</b> |
| 82 | +<td>@splunkdev</td> |
| 83 | +</tr> |
| 84 | + |
| 85 | +</table> |
| 86 | + |
| 87 | +### Contact us |
| 88 | + |
| 89 | +You can reach the Developer Platform team at _[email protected]_. |
| 90 | + |
| 91 | +## License |
| 92 | + |
| 93 | +The Splunk JavaScript Software Development Kit is licensed under the Apache |
| 94 | +License 2.0. Details can be found in the LICENSE file. |
0 commit comments