Skip to content

Commit 6bdf3fc

Browse files
Merge pull request #2 from splunk/release/0.9.0
Merge Release/0.9.0 into Develop
2 parents 8315fe8 + 0d3ea9f commit 6bdf3fc

File tree

13 files changed

+2624
-934
lines changed

13 files changed

+2624
-934
lines changed

CHANGELOG.md

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,29 @@
1-
# Splunk Logging Library for JavaScript (beta)
1+
# Splunk logging for JavaScript
2+
3+
## v0.9.0
4+
5+
### New features & APIs
6+
7+
* Added the ability to configure automated batching with 3 settings: `batchInterval`, `maxBatchCount`, & `maxBatchSize`.
8+
* Added the ability to retry sending to Splunk Enterprise or Splunk Cloud in the case of network errors with the `maxRetries` configuration setting.
9+
* Added the ability to configure a custom Splunk Enterprise or Splunk Cloud event format by overriding `eventFormatter(message, severity)`.
10+
11+
### Breaking Changes
12+
13+
* Removed the `autoFlush` configuration setting. To achieve the same effect, set `config.maxBatchCount` to `0`.
14+
* Removed support for middleware functions.
15+
* The `context` object has been simplified, `config` and `requestOptions` can no longer be specified there; please use those settings directly on the logger.
16+
17+
### Examples
18+
19+
* Removed the `middleware.js` example.
20+
* Renamed the `batching.js` example to `manual_batching`.
21+
* Added the `all_batching.js`, `custom_format.js`, `retry.js` examples.
22+
23+
### Minor changes
24+
25+
* Significant refactor of internal functions.
226

327
## v0.8.0 - beta
428

5-
* Beta release.
29+
* Beta release.

README.md

Lines changed: 23 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,34 @@
1-
# Splunk Logging Library for JavaScript (beta)
1+
# Splunk logging for JavaScript
22

3-
#### Version 0.8.0
3+
#### Version 0.9.0
44

5-
This project provides a simple interface for logging to Splunk's Event Collector.
5+
This project provides a simple JavaScript interface for logging to HTTP Event Collector in Splunk Enterprise and Splunk Cloud.
66

77
## Requirements
88

9-
* Splunk 6.3+.
10-
* An HTTP Event Collector token from your Splunk server.
11-
* Node.js v0.10+.
9+
* Node.js v0.10 or later.
10+
* Splunk Enterprise 6.3.0 or later, or Splunk Cloud.
11+
* An HTTP Event Collector token from your Splunk Enterprise server.
1212

1313
## Installation
1414

15-
If you already have Node.js and npm installed, simply run: `npm install --save splunk-logging`.
15+
First, update npm to the latest version by running:
16+
17+
sudo npm install npm -g
18+
19+
Then run:
20+
21+
npm install --save splunk-logging
1622

1723
## Usage
1824

19-
See the `examples` folder for more examples:
25+
See the `examples` folder for usage examples:
2026

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.
27+
* `all_batching.js`: Shows how to configure a logger with the 3 batching settings: `batchInterval`, `maxBatchCount`, & `maxBatchSize`.
28+
* `basic.js`: Shows how to configure a logger and send a log message to Splunk.
29+
* `custom_format.js`: Shows how to configure a logger to log messages to Splunk using a custom format.
30+
* `manual_batching.js`: Shows how to queue log messages, and send them in batches by manually calling `flush()`.
31+
* `retry.js`: Shows how to configure retries on errors.
2432

2533
### Basic example
2634

@@ -35,7 +43,7 @@ var config = {
3543
var Logger = new SplunkLogger(config);
3644

3745
var payload = {
38-
// Message can be anything, doesn't have to be an object
46+
// Message can be anything; doesn't have to be an object
3947
message: {
4048
temperature: "70F",
4149
chickenCount: 500
@@ -51,7 +59,7 @@ Logger.send(payload, function(err, resp, body) {
5159

5260
## Community
5361

54-
Stay connected with other developers building on Splunk.
62+
Stay connected with other developers building on Splunk software.
5563

5664
<table>
5765

@@ -62,7 +70,7 @@ Stay connected with other developers building on Splunk.
6270

6371
<tr>
6472
<td><b>Issues</b>
65-
<td><span>https://github.com/splunk/splunk-logging-javascript/issues/</span></td>
73+
<td><span>https://github.com/splunk/splunk-javascript-logging/issues/</span></td>
6674
</tr>
6775

6876
<tr>
@@ -84,7 +92,7 @@ Stay connected with other developers building on Splunk.
8492

8593
### Contact us
8694

87-
You can reach the Developer Platform team at _[email protected]_.
95+
You can reach the developer platform team at _[email protected]_.
8896

8997
## License
9098

examples/all_batching.js

Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
1+
/*
2+
* Copyright 2015 Splunk, Inc.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License"): you may
5+
* not use this file except in compliance with the License. You may obtain
6+
* a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12+
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13+
* License for the specific language governing permissions and limitations
14+
* under the License.
15+
*/
16+
17+
/**
18+
* This example shows how to batch events with the
19+
* SplunkLogger with all available settings:
20+
* batchInterval, maxBatchCount, & maxBatchSize.
21+
*/
22+
23+
// Change to require("splunk-logging").Logger;
24+
var SplunkLogger = require("../index").Logger;
25+
26+
/**
27+
* Only the token property is required.
28+
*
29+
* Here, batchInterval is set to flush every 1 second, when
30+
* 10 events are queued, or when the size of queued events totals
31+
* more than 1kb.
32+
*/
33+
var config = {
34+
token: "your-token-here",
35+
url: "https://localhost:8088",
36+
batchInterval: 1000,
37+
maxBatchCount: 10,
38+
maxBatchSize: 1024 // 1kb
39+
};
40+
41+
// Create a new logger
42+
var Logger = new SplunkLogger(config);
43+
44+
Logger.error = function(err, context) {
45+
// Handle errors here
46+
console.log("error", err, "context", context);
47+
};
48+
49+
// Define the payload to send to Splunk's Event Collector
50+
var payload = {
51+
// Message can be anything, doesn't have to be an object
52+
message: {
53+
temperature: "70F",
54+
chickenCount: 500
55+
},
56+
// Metadata is optional
57+
metadata: {
58+
source: "chicken coop",
59+
sourcetype: "httpevent",
60+
index: "main",
61+
host: "farm.local",
62+
},
63+
// Severity is also optional
64+
severity: "info"
65+
};
66+
67+
console.log("Queuing payload", payload);
68+
// Don't need a callback here
69+
Logger.send(payload);
70+
71+
var payload2 = {
72+
message: {
73+
temperature: "75F",
74+
chickenCount: 600,
75+
note: "New chickens have arrived"
76+
},
77+
metadata: payload.metadata
78+
};
79+
80+
console.log("Queuing second payload", payload2);
81+
// Don't need a callback here
82+
Logger.send(payload2);
83+
84+
/**
85+
* Since we've configured batching, we don't need
86+
* to do anything at this point. Events will
87+
* will be sent to Splunk automatically based
88+
* on the batching settings above.
89+
*/
90+
91+
// Kill the process
92+
setTimeout(function() {
93+
console.log("Events should be in Splunk! Exiting...");
94+
process.exit();
95+
}, 2000);

examples/basic.js

Lines changed: 31 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -23,20 +23,10 @@ var SplunkLogger = require("../index").Logger;
2323

2424
/**
2525
* Only the token property is required.
26-
* Defaults are listed explicitly.
27-
*
28-
* Alternatively, specify config.url like so:
29-
*
30-
* "https://localhost:8088/services/collector/event/1.0"
3126
*/
3227
var config = {
3328
token: "your-token-here",
34-
host: "localhost",
35-
path: "/services/collector/event/1.0",
36-
protocol: "https",
37-
port: 8088,
38-
level: "info",
39-
autoFlush: true
29+
url: "https://localhost:8088"
4030
};
4131

4232
// Create a new logger
@@ -47,9 +37,9 @@ Logger.error = function(err, context) {
4737
console.log("error", err, "context", context);
4838
};
4939

50-
// Define the payload to send to Splunk's Event Collector
40+
// Define the payload to send to HTTP Event Collector
5141
var payload = {
52-
// Message can be anything, doesn't have to be an object
42+
// Message can be anything, it doesn't have to be an object
5343
message: {
5444
temperature: "70F",
5545
chickenCount: 500
@@ -59,14 +49,40 @@ var payload = {
5949
source: "chicken coop",
6050
sourcetype: "httpevent",
6151
index: "main",
62-
host: "farm.local",
52+
host: "farm.local"
6353
},
6454
// Severity is also optional
6555
severity: "info"
6656
};
6757

6858
console.log("Sending payload", payload);
59+
60+
/**
61+
* Since maxBatchCount is set to 1 by default,
62+
* calling send will immediately send the payload.
63+
*
64+
* The underlying HTTP POST request is made to
65+
*
66+
* https://localhost:8088/services/collector/event/1.0
67+
*
68+
* with the following body
69+
*
70+
* {
71+
* "source": "chicken coop",
72+
* "sourcetype": "httpevent",
73+
* "index": "main",
74+
* "host": "farm.local",
75+
* "event": {
76+
* "message": {
77+
* "temperature": "70F",
78+
* "chickenCount": 500
79+
* },
80+
* "severity": "info"
81+
* }
82+
* }
83+
*
84+
*/
6985
Logger.send(payload, function(err, resp, body) {
7086
// If successful, body will be { text: 'Success', code: 0 }
7187
console.log("Response from Splunk", body);
72-
});
88+
});

0 commit comments

Comments
 (0)