Skip to content

Commit e52af1f

Browse files
authored
Merge pull request #7 from newrelic/configurable-custom-fields
fix: requeue logentries failed due to case sensitive applicationName comparsion
2 parents 479ec8a + c3d704e commit e52af1f

File tree

9 files changed

+63
-21
lines changed

9 files changed

+63
-21
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.3</version>
31+
<version>1.0.4</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.3</version>
41+
<version>1.0.4</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.3'
23+
'Implementation-Version': '1.0.4'
2424
)
2525
}
2626
}
@@ -53,7 +53,7 @@ publishing {
5353

5454
groupId = 'com.newrelic.labs'
5555
artifactId = 'custom-log4j2-appender'
56-
version = '1.0.3'
56+
version = '1.0.4'
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.3'
30+
'Implementation-Version': '1.0.4'
3131
)
3232
}
3333
}
@@ -55,7 +55,7 @@ publishing {
5555

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

6060
pom {
6161
name = 'Custom Log4j2 Appender'

custom-log4j2-appender/build.gradle

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

@@ -16,22 +15,18 @@ dependencies {
1615
}
1716

1817
jar {
19-
enabled = false // Disable the standard JAR task
20-
}
21-
22-
shadowJar {
23-
archiveClassifier.set('') // Remove the 'all' classifier
24-
mergeServiceFiles()
2518
manifest {
2619
attributes(
2720
'Implementation-Title': 'Custom Log4j2 Appender',
2821
'Implementation-Vendor': 'New Relic Labs',
2922
'Implementation-Vendor-Id': 'com.newrelic.labs',
30-
'Implementation-Version': '1.0.3'
23+
'Implementation-Version': '1.0.4'
3124
)
3225
}
3326
}
3427

28+
29+
3530
tasks.withType(JavaCompile) {
3631
options.encoding = 'UTF-8'
3732
}
@@ -46,16 +41,19 @@ task sourcesJar(type: Jar) {
4641
from sourceSets.main.allSource
4742
}
4843

44+
45+
4946
publishing {
5047
publications {
5148
mavenJava(MavenPublication) {
52-
artifact shadowJar // Only include Shadow JAR
49+
from components.java // Include standard JAR
50+
5351
artifact javadocJar
5452
artifact sourcesJar
5553

5654
groupId = 'com.newrelic.labs'
5755
artifactId = 'custom-log4j2-appender'
58-
version = '1.0.3'
56+
version = '1.0.4'
5957

6058
pom {
6159
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.3"
10+
VERSION="1.0.4"
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.3"
10+
VERSION="1.0.4"
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.3"
9+
VERSION="1.0.4"
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/LogEntry.java

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,18 @@
22

33
import java.util.Map;
44

5+
import com.fasterxml.jackson.annotation.JsonCreator;
6+
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
7+
import com.fasterxml.jackson.annotation.JsonProperty;
8+
9+
@JsonIgnoreProperties(ignoreUnknown = true)
510
public class LogEntry {
611
private final String message;
712
private final String applicationName;
813
private final String name;
914
private final String logtype;
1015
private final long timestamp;
1116

12-
1317
public LogEntry(String message, String applicationName, String name, String logtype, long timestamp,
1418
Map<String, Object> custom, boolean mergeCustomFields) {
1519
this.message = message;
@@ -20,6 +24,26 @@ public LogEntry(String message, String applicationName, String name, String logt
2024

2125
}
2226

27+
// Default constructor for Jackson
28+
public LogEntry() {
29+
this.message = null;
30+
this.applicationName = null;
31+
this.name = null;
32+
this.logtype = null;
33+
this.timestamp = 0L;
34+
}
35+
36+
@JsonCreator
37+
public LogEntry(@JsonProperty("message") String message, @JsonProperty("applicationname") String applicationName,
38+
@JsonProperty("name") String name, @JsonProperty("logtype") String logtype,
39+
@JsonProperty("timestamp") long timestamp) {
40+
this.message = message;
41+
this.applicationName = applicationName;
42+
this.name = name;
43+
this.logtype = logtype;
44+
this.timestamp = timestamp;
45+
}
46+
2347
public String getMessage() {
2448
return message;
2549
}

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

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -198,15 +198,35 @@ private void sendLogs(List<Map<String, Object>> logEvents) throws IOException {
198198
}
199199

200200
private void requeueLogs(List<Map<String, Object>> logEvents) {
201+
201202
for (Map<String, Object> logEvent : logEvents) {
202203
try {
204+
// Log the contents of logEvent
205+
// System.out.println("logEvent: " + logEvent);
206+
207+
// Convert logEvent to LogEntry
203208
LogEntry logEntry = objectMapper.convertValue(logEvent, LogEntry.class);
204-
logQueue.put(logEntry); // Requeue the log entry
209+
210+
// Log the contents of the converted LogEntry
211+
// System.out.println("Converted LogEntry: ");
212+
// System.out.println(" message: " + logEntry.getMessage());
213+
// System.out.println(" applicationName: " + logEntry.getApplicationName());
214+
// System.out.println(" name: " + logEntry.getName());
215+
// System.out.println(" logtype: " + logEntry.getLogType());
216+
// System.out.println(" timestamp: " + logEntry.getTimestamp());
217+
218+
// Requeue the log entry
219+
logQueue.put(logEntry);
205220
} catch (InterruptedException e) {
206221
Thread.currentThread().interrupt();
207222
System.err.println("Failed to requeue log entry: " + logEvent);
223+
} catch (IllegalArgumentException e) {
224+
System.err.println("Failed to convert log event to LogEntry: " + logEvent);
208225
}
209226
}
227+
228+
System.err.println("Network issue - NewRelicBatchingAppenderhas re-queued " + logEvents.size() + " entries"
229+
+ " : queue size " + logQueue.size());
210230
}
211231

212232
private byte[] gzipCompress(String input) throws IOException {

0 commit comments

Comments
 (0)