Skip to content

Commit 64b523f

Browse files
authored
Merge pull request #5 from newrelic/btach-flush-enhancements
feat: Batch flush enhancements
2 parents 223fc88 + 871b213 commit 64b523f

File tree

8 files changed

+32
-17
lines changed

8 files changed

+32
-17
lines changed

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ Add the library to your project using Maven Central:
2828
<dependency>
2929
<groupId>com.newrelic.labs</groupId>
3030
<artifactId>custom-log4j2-appender</artifactId>
31-
<version>1.0.1</version>
31+
<version>1.0.2</version>
3232
</dependency>
3333
```
3434

@@ -38,7 +38,7 @@ Or, if using a locally built JAR file:
3838
<dependency>
3939
<groupId>com.newrelic.labs</groupId>
4040
<artifactId>custom-log4j2-appender</artifactId>
41-
<version>1.0.1</version>
41+
<version>1.0.2</version>
4242
<scope>system</scope>
4343
<systemPath>${project.basedir}/src/main/resources/custom-log4j2-appender.jar</systemPath>
4444
</dependency>

custom-log4j2-appender/build-jar.gradle

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ jar {
2020
'Implementation-Title': 'Custom Log4j2 Appender',
2121
'Implementation-Vendor': 'New Relic Labs',
2222
'Implementation-Vendor-Id': 'com.newrelic.labs',
23-
'Implementation-Version': '1.0.1'
23+
'Implementation-Version': '1.0.2'
2424
)
2525
}
2626
}
@@ -53,7 +53,7 @@ publishing {
5353

5454
groupId = 'com.newrelic.labs'
5555
artifactId = 'custom-log4j2-appender'
56-
version = '1.0.1'
56+
version = '1.0.2'
5757

5858
pom {
5959
name = 'Custom Log4j2 Appender'

custom-log4j2-appender/build-shadowJar.gradle

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ shadowJar {
2727
'Implementation-Title': 'Custom Log4j2 Appender',
2828
'Implementation-Vendor': 'New Relic Labs',
2929
'Implementation-Vendor-Id': 'com.newrelic.labs',
30-
'Implementation-Version': '1.0.1'
30+
'Implementation-Version': '1.0.2'
3131
)
3232
}
3333
}
@@ -55,7 +55,7 @@ publishing {
5555

5656
groupId = 'com.newrelic.labs'
5757
artifactId = 'custom-log4j2-appender'
58-
version = '1.0.1'
58+
version = '1.0.2'
5959

6060
pom {
6161
name = 'Custom Log4j2 Appender'

custom-log4j2-appender/build.gradle

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
plugins {
22
id 'java'
3+
id 'com.github.johnrengelman.shadow' version '6.1.0'
34
id 'maven-publish'
45
}
56

@@ -15,18 +16,22 @@ dependencies {
1516
}
1617

1718
jar {
19+
enabled = false // Disable the standard JAR task
20+
}
21+
22+
shadowJar {
23+
archiveClassifier.set('') // Remove the 'all' classifier
24+
mergeServiceFiles()
1825
manifest {
1926
attributes(
2027
'Implementation-Title': 'Custom Log4j2 Appender',
2128
'Implementation-Vendor': 'New Relic Labs',
2229
'Implementation-Vendor-Id': 'com.newrelic.labs',
23-
'Implementation-Version': '1.0.1'
30+
'Implementation-Version': '1.0.2'
2431
)
2532
}
2633
}
2734

28-
29-
3035
tasks.withType(JavaCompile) {
3136
options.encoding = 'UTF-8'
3237
}
@@ -41,19 +46,16 @@ task sourcesJar(type: Jar) {
4146
from sourceSets.main.allSource
4247
}
4348

44-
45-
4649
publishing {
4750
publications {
4851
mavenJava(MavenPublication) {
49-
from components.java // Include standard JAR
50-
52+
artifact shadowJar // Only include Shadow JAR
5153
artifact javadocJar
5254
artifact sourcesJar
5355

5456
groupId = 'com.newrelic.labs'
5557
artifactId = 'custom-log4j2-appender'
56-
version = '1.0.1'
58+
version = '1.0.2'
5759

5860
pom {
5961
name = 'Custom Log4j2 Appender'

custom-log4j2-appender/publish-jar-legacy.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ cp build-jar.gradle build.gradle
77
# Set variables
88
GROUP_ID="com.newrelic.labs"
99
ARTIFACT_ID="custom-log4j2-appender"
10-
VERSION="1.0.1"
10+
VERSION="1.0.2"
1111
KEY_ID="0ED9FD74E81E6D83FAE25F235640EA0B1C631C6F" # Replace with your actual key ID
1212

1313
# Get the current directory (assuming the script is run from the custom-log4j2-appender directory)

custom-log4j2-appender/publish-jar.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ cp build-jar.gradle build.gradle
77
# Set variables
88
GROUP_ID="io.github.newrelic-experimental"
99
ARTIFACT_ID="custom-log4j2-appender"
10-
VERSION="1.0.1"
10+
VERSION="1.0.2"
1111
KEY_ID="0ED9FD74E81E6D83FAE25F235640EA0B1C631C6F" # Replace with your actual key ID
1212

1313
# Get the current directory (assuming the script is run from the custom-log4j2-appender directory)

custom-log4j2-appender/publish-shadowJar.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ cp build-shadowJar.gradle build.gradle
66
# Set variables
77
GROUP_ID="io.github.newrelic-experimental"
88
ARTIFACT_ID="custom-log4j2-appender"
9-
VERSION="1.0.1"
9+
VERSION="1.0.2"
1010
KEY_ID="0ED9FD74E81E6D83FAE25F235640EA0B1C631C6F" # Replace with your actual key ID
1111

1212
# Get the current directory (assuming the script is run from the custom-log4j2-appender directory)

custom-log4j2-appender/src/main/java/com/newrelic/labs/NewRelicBatchingAppender.java

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,10 +132,23 @@ public void append(LogEvent event) {
132132
}
133133
// Directly add to the queue
134134
queue.add(new LogEntry(message, applicationName, muleAppName, logType, timestamp, custom));
135+
// Check if the batch size is reached and flush immediately
136+
if (queue.size() >= batchSize) {
137+
flushQueue();
138+
}
135139
} catch (Exception e) {
136140
logger.error("Unable to insert log entry into log queue. ", e);
137141
}
138142
}
143+
private void flushQueue() {
144+
List<LogEntry> batch = new ArrayList<>();
145+
queue.drainTo(batch, batchSize);
146+
if (!batch.isEmpty()) {
147+
logger.debug("Flushing {} log entries to New Relic", batch.size());
148+
logForwarder.flush(batch);
149+
}
150+
}
151+
139152

140153
private Map<String, Object> extractcustom(LogEvent event) {
141154
Map<String, Object> custom = new HashMap<>();

0 commit comments

Comments
 (0)