Skip to content

Commit f7bf377

Browse files
Merge branch 'main' into StartDispatcher
2 parents 7319aa9 + 82c4a56 commit f7bf377

26 files changed

+785
-213
lines changed
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
---
2+
name: Pull Request Template
3+
about: Create a Pull Request to contribute to the SDK
4+
title: ''
5+
labels: ''
6+
assignees: ''
7+
8+
---
9+
10+
## Description of PR
11+
12+
Provide the **context and motivation** for this PR.
13+
Briefly explain the **type of changes** (bug fix, feature request, doc update, etc.) made in this PR. Provide reference to issue # fixed, if applicable.
14+
15+
Describe the approach to the solution, the changes made, and any resulting change in behavior or impact to the user.
16+
17+
## Testing the changes
18+
19+
Please ensure tests are added for your changes.
20+
Include details of **types of tests** written for the changes in the PR and any **test setup and configuration** required to run the tests.
21+
Mention the **versions of the SDK, language runtime, OS and details of Splunk deployment** used in testing.
22+
23+
## Documentation
24+
25+
Please ensure **comments** are added for your changes and any **relevant docs** (readme, reference docs, etc.) are updated.
26+
Include any references to documentation related to the changes.
27+
28+
## Dependencies and other resources
29+
30+
Provide references to PRs or things **dependent on this change** and any relevant PRs or resources like style guides and tools used in this PR.
31+
32+

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
.idea
44
target
55
.vscode
6+
.factorypath
67
*.iml
78
pom.xml.old
89
pom.xml.orig

CHANGELOG.md

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,65 @@
11
# Splunk Logging for Java Changelog
22

3+
## Version 1.11.5
4+
5+
### Critical Security Update
6+
* Bump Log4J version to latest 2.17.2 @see [CVE-2021-44832 Log4j<2.17.1](https://nvd.nist.gov/vuln/detail/CVE-2021-44832)
7+
* Bump Logback version to latest 1.2.11 @see [CVE-2021-42550 Logback<1.2.8](https://nvd.nist.gov/vuln/detail/CVE-2021-42550)
8+
9+
### Enhancements
10+
* Added StandardErrorCallback class. Register ErrorCallback implementations via logback or log4j xml config. (PR [#215](https://github.com/splunk/splunk-library-javalogging/pull/215))
11+
* ErrorCallback class used to handle error other than Server errors.
12+
13+
### Minor Changes
14+
* Bump org.slf4j:slf4j-api version to latest [1.7.36](https://github.com/qos-ch/slf4j/releases/tag/v_1.7.36)
15+
* Bump com.squareup.okhttp3:okhttp to latest [4.9.3](https://square.github.io/okhttp/changelogs/changelog_4x/#version-493)
16+
* Bump com.google.code.gson:gson to latest [2.9.0](https://github.com/google/gson/releases/tag/gson-parent-2.9.0)
17+
* Flush HttpClient after flushing appenders. (PR [#207](https://github.com/splunk/splunk-library-javalogging/pull/207))
18+
* Timeout settings modified for OKHttpClient. (PR [#199](https://github.com/splunk/splunk-library-javalogging/pull/199))
19+
* Default behavior of Splunk event header & body are reverted back to v1.7.3. (PR [#198](https://github.com/splunk/splunk-library-javalogging/pull/198))
20+
21+
## Version 1.11.4
22+
23+
### Critical Security Update
24+
* Update Logback to version 1.2.9 per CVE-2021-42550.
25+
26+
## Version 1.11.3
27+
28+
### Critical Security Update
29+
* Upgrade Log4J again v2.17.0 related to CVE-2021-45046 & CVE-2021-44228
30+
31+
## Version 1.11.2
32+
33+
### Critical Security Update
34+
* Upgrading log4J to 2.16 per CVE-2021-45046.
35+
36+
## Version 1.11.1
37+
38+
### Critical Security Update
39+
* Upgrading log4J to 2.15 per CVE-2021-44228. [PR](https://github.com/splunk/splunk-library-javalogging/pull/222)
40+
41+
## Version 1.11.0
42+
43+
### Minor Changes
44+
* Added a parameter to set await termination timeout. [PR](https://github.com/splunk/splunk-library-javalogging/pull/179)
45+
46+
## Version 1.10.0
47+
48+
### Bug Fixes
49+
50+
* Fixed issue causing delayed time when using AsyncAppender (GitHub issue [#186](https://github.com/splunk/splunk-javascript-logging/issues/186))
51+
* Now the timestamp is being recorded at the time when log event "occurs" instead of the time when log event is being "sent"
52+
53+
### Minor Changes
54+
55+
* Updated the project to use make conventions to spin up local dockerized instances.
56+
* Upgrade version of okhttp to 4.9.1.
57+
* Upgrade version of slf4j to 1.7.30.
58+
* Upgrade version of gson to 2.8.7.
59+
* Upgrade version of junit to 4.13.2.
60+
* Upgrade version of commons to 3.12.
61+
62+
363
## Version 1.9.0
464

565
* Resolve an issue with TcpAppender losing events when busy (@avdv)

README.md

Lines changed: 44 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# Splunk Logging for Java
22

3-
#### Version 1.9.0
3+
#### Version 1.11.5
44

55
Splunk logging for Java enables you to log events to HTTP Event Collector or to a TCP input on a Splunk Enterprise instance within your Java applications. You can use three major Java logging frameworks: [Logback](http://logback.qos.ch), [Log4j 2](http://logging.apache.org/log4j/2.x/), and [java.util.logging](https://docs.oracle.com/javase/7/docs/api/java/util/logging/package-summary.html). Splunk logging for Java is also enabled for [Simple Logging Facade for Java (SLF4J)](http://www.slf4j.org).
66

@@ -24,18 +24,18 @@ Here's what you need to get going with Splunk logging for Java.
2424

2525
If you haven't already installed Splunk, download it
2626
[here](http://www.splunk.com/download). For more about installing and running
27-
Splunk and system requirements, see [Installing & Running Splunk](http://dev.splunk.com/view/SP-CAAADRV). Splunk logging for Java is tested with Splunk Enterprise 7.0 and 7.2.
27+
Splunk and system requirements, see [Installing & Running Splunk](http://dev.splunk.com/view/SP-CAAADRV). Splunk logging for Java is tested with Splunk Enterprise 8.0 and 8.2.0.
2828

29-
#### Java
29+
#### Java
3030

3131
You'll need Java version 8 or higher, from [OpenJDK](https://openjdk.java.net) or [Oracle](https://www.oracle.com/technetwork/java).
3232

3333
#### Logging frameworks
3434

3535
If you're using the Log4j 2, Simple Logging Facade for Java (SLF4J), or Logback logging frameworks in conjunction with Splunk logging for Java there are additional compatibility requirements. For more about logging framework requirements, see [Enable logging to HEC](https://dev.splunk.com/enterprise/docs/devtools/java/logging-java/howtouseloggingjava/enableloghttpjava/) and [Enable logging to TCP inputs](https://dev.splunk.com/enterprise/docs/devtools/java/logging-java/howtouseloggingjava/enablelogtcpjava). These frameworks require:
36-
* Log4j version 2.12.1
37-
* SLF4J version 1.7.29
38-
* Logback version 1.2.3
36+
* Log4j version 2.17.2
37+
* SLF4J version 1.7.36
38+
* Logback version 1.2.11
3939

4040
## Documentation and resources
4141

@@ -51,6 +51,43 @@ If you're using the Log4j 2, Simple Logging Facade for Java (SLF4J), or Logback
5151
* For more about about Splunk in general, see
5252
[Splunk>Docs](http://docs.splunk.com/Documentation/Splunk).
5353

54+
## Dependency Management
55+
56+
The `splunk-library-javalogging` artifact can be accessed via Splunk's managed Maven repoitory.
57+
58+
### Apache Maven
59+
60+
First define the repository as follows
61+
62+
```xml
63+
...
64+
<repositories>
65+
<repository>
66+
<id>splunk-artifactory</id>
67+
<name>Splunk Releases</name>
68+
<url>https://splunk.jfrog.io/splunk/ext-releases-local</url>
69+
</repository>
70+
</repositories>
71+
...
72+
```
73+
74+
... then reference the dependency as follows
75+
76+
```xml
77+
...
78+
<dependencies>
79+
<dependency>
80+
<groupId>com.splunk.logging</groupId>
81+
<artifactId>splunk-library-javalogging</artifactId>
82+
<version>${latest.version}</version>
83+
</dependency>
84+
...
85+
</dependencies>
86+
...
87+
```
88+
89+
The above can be adapted to suit Other dependency management implementations as necessary.
90+
5491
## License
5592

5693
Splunk logging for Java is licensed under the Apache License 2.0.
@@ -78,4 +115,4 @@ You can [contact support][contact] if you have Splunk related questions.
78115

79116
You can reach the Dev Platform team at [devinfo@splunk.com](mailto:devinfo@splunk.com).
80117

81-
[contact]: https://www.splunk.com/en_us/support-and-services.html
118+
[contact]: https://www.splunk.com/en_us/support-and-services.html

pom.xml

Lines changed: 31 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,34 @@
11
<?xml version="1.0" encoding="UTF-8"?>
22
<project xmlns="http://maven.apache.org/POM/4.0.0"
3-
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
4-
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
3+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
54
<modelVersion>4.0.0</modelVersion>
65

76
<groupId>com.splunk.logging</groupId>
87
<artifactId>splunk-library-javalogging</artifactId>
9-
<version>1.9.0</version>
8+
9+
<version>1.11.5</version>
10+
1011
<packaging>jar</packaging>
1112

1213
<name>Splunk Logging for Java</name>
13-
<url>http://dev.splunk.com/goto/sdk-slj</url>
14+
<url>https://dev.splunk.com/goto/sdk-slj</url>
1415

15-
<description>Library for structured, semantic logging of Common Information Model compliant events, meant for use
16-
with SLF4J.
16+
<description>
17+
Library for structured, semantic logging of Common Information Model compliant events, meant for use with SLF4J.
1718
</description>
1819

1920
<properties>
2021
<maven.resources.overwrite>true</maven.resources.overwrite>
2122
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
23+
24+
<!-- CVE-2021-44228: https://nvd.nist.gov/vuln/detail/CVE-2021-44228 -->
25+
<!-- CVE-2021-45046: https://nvd.nist.gov/vuln/detail/CVE-2021-45046 -->
26+
<!-- CVE-2021-45105 (Log4j<2.17.0): https://nvd.nist.gov/vuln/detail/CVE-2021-45105 -->
27+
<!-- CVE-2021-44832 (Log4j<2.17.1): https://nvd.nist.gov/vuln/detail/CVE-2021-44832 -->
28+
<log4j2.version>2.17.2</log4j2.version>
29+
30+
<!-- CVE-2021-42550: https://nvd.nist.gov/vuln/detail/CVE-2021-42550 -->
31+
<logback.version>1.2.11</logback.version>
2232
</properties>
2333
<profiles>
2434
<profile>
@@ -93,7 +103,9 @@
93103
<execution>
94104
<id>attach-javadocs</id>
95105
<configuration>
96-
<additionalOptions>-Xdoclint:syntax</additionalOptions>
106+
<additionalOptions>
107+
<additionalOption>-Xdoclint:syntax</additionalOption>
108+
</additionalOptions>
97109
</configuration>
98110
<goals>
99111
<goal>jar</goal>
@@ -183,46 +195,46 @@
183195
<dependency>
184196
<groupId>org.slf4j</groupId>
185197
<artifactId>slf4j-api</artifactId>
186-
<version>1.7.30</version>
198+
<version>1.7.36</version>
187199
<scope>test</scope>
188200
</dependency>
189201
<dependency>
190202
<groupId>ch.qos.logback</groupId>
191203
<artifactId>logback-classic</artifactId>
192-
<version>1.2.3</version>
204+
<version>${logback.version}</version>
193205
<scope>provided</scope>
194206
</dependency>
195207
<dependency>
196208
<groupId>ch.qos.logback</groupId>
197209
<artifactId>logback-core</artifactId>
198-
<version>1.2.3</version>
210+
<version>${logback.version}</version>
199211
<scope>provided</scope>
200212
</dependency>
201213
<dependency>
202214
<groupId>ch.qos.logback</groupId>
203215
<artifactId>logback-access</artifactId>
204-
<version>1.2.3</version>
216+
<version>${logback.version}</version>
205217
<scope>provided</scope>
206218
</dependency>
207219

208220
<dependency>
209221
<groupId>com.squareup.okhttp3</groupId>
210222
<artifactId>okhttp</artifactId>
211-
<version>4.9.1</version>
223+
<version>4.9.3</version>
212224
</dependency>
213225

214226
<dependency>
215227
<groupId>org.apache.logging.log4j</groupId>
216228
<artifactId>log4j-api</artifactId>
217229
<scope>provided</scope>
218-
<version>2.14.1</version>
230+
<version>${log4j2.version}</version>
219231
</dependency>
220232

221233
<dependency>
222234
<groupId>org.apache.logging.log4j</groupId>
223235
<artifactId>log4j-core</artifactId>
224236
<scope>provided</scope>
225-
<version>2.14.1</version>
237+
<version>${log4j2.version}</version>
226238
</dependency>
227239

228240
<dependency>
@@ -235,7 +247,7 @@
235247
<dependency>
236248
<groupId>com.google.code.gson</groupId>
237249
<artifactId>gson</artifactId>
238-
<version>2.8.7</version>
250+
<version>2.9.0</version>
239251
</dependency>
240252

241253
<dependency>
@@ -283,7 +295,9 @@
283295
</goals>
284296
<configuration>
285297
<source>8</source>
286-
<additionalOptions>-Xdoclint:syntax</additionalOptions>
298+
<additionalOptions>
299+
<additionalOption>-Xdoclint:syntax</additionalOption>
300+
</additionalOptions>
287301
</configuration>
288302
</execution>
289303
</executions>
@@ -331,4 +345,4 @@
331345
</scm>
332346

333347

334-
</project>
348+
</project>

src/main/java/com/splunk/logging/HttpEventCollectorErrorHandler.java

Lines changed: 45 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,26 @@
3636
*/
3737
public class HttpEventCollectorErrorHandler {
3838

39+
/**
40+
* Register error handler via full class name.
41+
*
42+
* When the class name is null or empty, null is registered to the <code>HttpEventCollectorErrorHandler</code>.
43+
*
44+
* @param errorCallbackClass the name of the class, for instance: <code>com.splunk.logging.util.StandardErrorCallback</code>
45+
*/
46+
public static void registerClassName(String errorCallbackClass) {
47+
if (errorCallbackClass == null || errorCallbackClass.trim().isEmpty()) {
48+
HttpEventCollectorErrorHandler.onError(null);
49+
return;
50+
}
51+
try {
52+
ErrorCallback callback = (ErrorCallback) Class.forName(errorCallbackClass).newInstance();
53+
HttpEventCollectorErrorHandler.onError(callback);
54+
} catch (final Exception e) {
55+
System.err.println("Warning: cannot create ErrorCallback instance: " + e);
56+
}
57+
}
58+
3959
/**
4060
* This exception is passed to error callback when Splunk server replies an error
4161
*/
@@ -100,10 +120,26 @@ public interface ErrorCallback {
100120
private static ErrorCallback errorCallback;
101121

102122
/**
103-
* Register error callbacks
104-
* @param callback ErrorCallback
123+
* Register error callbacks.
124+
*
125+
* @param callback ErrorCallback Only one ErrorCallback can be registered. A new one will replace the old one.
105126
*/
106127
public static void onError(ErrorCallback callback) {
128+
if (callback == null) {
129+
logInfo("Reset ErrorCallback to null (no error handling).");
130+
}
131+
else {
132+
logInfo("Register ErrorCallback implementation: " + callback);
133+
// onError() is called multiple times in unit tests and is also replaced intentionally.
134+
// Issue a warning when it is replaced by a different kind of handler.
135+
if (errorCallback != null && !errorCallback.equals(callback)) {
136+
logWarn("ErrorCallback instance of '"
137+
+ errorCallback.getClass().getName()
138+
+ "' will be replaced by handler instance of '"
139+
+ callback.getClass().getName()
140+
+ "'");
141+
}
142+
}
107143
errorCallback = callback;
108144
}
109145

@@ -117,4 +153,11 @@ public static void error(final List<HttpEventCollectorEventInfo> data, final Exc
117153
errorCallback.error(data, ex);
118154
}
119155
}
156+
157+
private static void logInfo(String message) {
158+
System.out.println("Info: " + message);
159+
}
160+
private static void logWarn(String message) {
161+
System.out.println("Warning: " + message);
162+
}
120163
}

0 commit comments

Comments
 (0)