From 84d867969000ef34a368e266ea2d94f8755b0228 Mon Sep 17 00:00:00 2001 From: SuramVishal Date: Fri, 15 Mar 2019 22:17:56 +0530 Subject: [PATCH 1/3] Closing httpclient properly on logback shutdown Code at present only closes httpclient, if `eventsBatch.size() > 0`. But there might be scenarios where logback calls shutdown and there are no events to flush. Therefore `sender.stopHttpClient()` never being called preventing a main method exit due to non-deamon thread usage of httpClient. --- .../java/com/splunk/logging/HttpEventCollectorSender.java | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/main/java/com/splunk/logging/HttpEventCollectorSender.java b/src/main/java/com/splunk/logging/HttpEventCollectorSender.java index 8d9d8785..3433c041 100644 --- a/src/main/java/com/splunk/logging/HttpEventCollectorSender.java +++ b/src/main/java/com/splunk/logging/HttpEventCollectorSender.java @@ -204,7 +204,9 @@ public synchronized void flush() { public synchronized void flush(boolean close) { if (eventsBatch.size() > 0) { postEventsAsync(eventsBatch, close); - } + } else if (close) { + this.stopHttpClient(); + } // Clear the batch. A new list should be created because events are // sending asynchronously and "previous" instance of eventsBatch object // is still in use. From e2edbad40334538ed4b1d989f908254d3864add0 Mon Sep 17 00:00:00 2001 From: SuramVishal Date: Sat, 16 Mar 2019 12:33:17 +0530 Subject: [PATCH 2/3] Code refactoring --- .../java/com/splunk/logging/HttpEventCollectorSender.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main/java/com/splunk/logging/HttpEventCollectorSender.java b/src/main/java/com/splunk/logging/HttpEventCollectorSender.java index 3433c041..39ff893a 100644 --- a/src/main/java/com/splunk/logging/HttpEventCollectorSender.java +++ b/src/main/java/com/splunk/logging/HttpEventCollectorSender.java @@ -205,8 +205,8 @@ public synchronized void flush(boolean close) { if (eventsBatch.size() > 0) { postEventsAsync(eventsBatch, close); } else if (close) { - this.stopHttpClient(); - } + this.stopHttpClient(); + } // Clear the batch. A new list should be created because events are // sending asynchronously and "previous" instance of eventsBatch object // is still in use. From 8cb48a1138f8c786c775c8a7a6361412b153af8c Mon Sep 17 00:00:00 2001 From: Tim Pavlik Date: Fri, 29 Mar 2019 15:27:52 -0700 Subject: [PATCH 3/3] Updated version to 1.7.2 --- CHANGELOG.md | 8 ++++++-- README.md | 18 +++++++++--------- pom.xml | 2 +- 3 files changed, 16 insertions(+), 12 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index d729a265..2071f3cb 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,9 @@ # Splunk Logging for Java Changelog +## Version 1.7.2 + +* Closing httpclient properly on logback shutdown [#112](https://github.com/splunk/splunk-library-javalogging/pull/112). + ## Version 1.7.1 * Change HttpEventCollectorLogbackAppender stop method to call this.sender.close() [#93](https://github.com/splunk/splunk-library-javalogging/pull/93). @@ -11,8 +15,8 @@ ## Version 1.6.2 -* Add support to allow users to define their own event body serializer for HTTP event adapter: Simply create a class implementing `com.splunk.logging.EventBodySerializer`, -and add the full class name as a property (`eventBodySerializer`) to the adapter. +* Add support to allow users to define their own event body serializer for HTTP event adapter: Simply create a class implementing `com.splunk.logging.EventBodySerializer`, +and add the full class name as a property (`eventBodySerializer`) to the adapter. Default will be a JSON event body containing message, severity, and other properties. [#86](https://github.com/splunk/splunk-library-javalogging/pull/86). ## Version 1.6.1 diff --git a/README.md b/README.md index 44ddd837..d06cbf02 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ # Splunk Logging for Java -#### Version 1.7.1 +#### Version 1.7.2 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). @@ -18,16 +18,16 @@ Splunk logging for Java provides: ## Documentation and resources -* For more information about installing and using Splunk logging for Java, see +* For more information about installing and using Splunk logging for Java, see [Overview of Splunk logging for Java](http://dev.splunk.com/goto/sdk-slj). -* For reference documentation, see the +* For reference documentation, see the [Splunk logging for Java API reference](https://docs.splunk.com/DocumentationStatic/JavaLogging/1.6.2/index.html). -* For all things developer with Splunk, see the +* For all things developer with Splunk, see the [Splunk Developer Portal](http://dev.splunk.com). -* For more about about Splunk in general, see +* For more about about Splunk in general, see [Splunk>Docs](http://docs.splunk.com/Documentation/Splunk). ## License @@ -38,12 +38,12 @@ See the [LICENSE file](/license.md) for details. ## Contributions -[Get the Splunk Java Logging Framework from GitHub](https://github.com/splunk/splunk-library-javalogging) -and clone the resources to your computer. For example, use the following -command: +[Get the Splunk Java Logging Framework from GitHub](https://github.com/splunk/splunk-library-javalogging) +and clone the resources to your computer. For example, use the following +command: git clone https://github.com/splunk/splunk-library-javalogging.git - + ## Support The Splunk logging for Java is community-supported. diff --git a/pom.xml b/pom.xml index 283bfacf..80b67e57 100644 --- a/pom.xml +++ b/pom.xml @@ -6,7 +6,7 @@ com.splunk.logging splunk-library-javalogging - 1.7.1 + 1.7.2 jar Splunk Logging for Java