Skip to content

Commit

Permalink
lower dependency to Java 11
Browse files Browse the repository at this point in the history
  • Loading branch information
osiegmar committed Nov 5, 2023
1 parent 6757bfb commit e716609
Show file tree
Hide file tree
Showing 5 changed files with 85 additions and 83 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,11 @@ jobs:

steps:
- uses: actions/checkout@v4
- name: Set up Java 17
- name: Set up Java 11
uses: actions/setup-java@v3
with:
distribution: 'temurin'
java-version: '17'
java-version: '11'
- uses: gradle/wrapper-validation-action@v1
- uses: gradle/gradle-build-action@v2
- name: Build with Gradle
Expand Down
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
## [2.0.0] - 2023-??-??
### Changed
- Complete rewrite
- Update to Java 17
- Update to Java 11
- Update Logback dependency to 1.4.11

## [1.1.1] - 2022-01-04
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ Unfortunately that JsonEncoder produces log output that is poorly suited for use

## Requirements

- Java 17
- Java 11
- Logback 1.4.11

## Prerequisites
Expand Down
4 changes: 2 additions & 2 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ version = "2.0.0-SNAPSHOT"

java {
toolchain {
languageVersion = JavaLanguageVersion.of(17)
languageVersion = JavaLanguageVersion.of(11)
}
withSourcesJar()
}
Expand All @@ -25,7 +25,7 @@ dependencies {
testImplementation("org.junit.jupiter:junit-jupiter:5.10.0")
testRuntimeOnly("org.junit.platform:junit-platform-launcher")
testImplementation("org.assertj:assertj-core:3.11.1")
testImplementation("net.javacrumbs.json-unit:json-unit-assertj:3.2.2")
testImplementation("net.javacrumbs.json-unit:json-unit-assertj:2.38.0")
testImplementation("com.fasterxml.jackson.core:jackson-databind:2.15.2")
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,28 +52,28 @@ class AwsJsonLogEncoderTest {
void defaultConfig() {
encoder.start();

assertThatJson(fullLog()).isEqualTo(json("""
{
"timestamp": "${json-unit.any-number}",
"level": "DEBUG",
"thread": "Test worker",
"logger": "de.siegmar.logbackawslogsjsonencoder.AwsJsonLogEncoderTest",
"message": "message 1",
"markers": {
"foo": 1,
"bar": 1
},
"mdc": {
"foo": "bar",
"baz": null
},
"keyValues": {
"foo": "bar",
"bar": null,
"null": "bar"
}
}
"""));
//language=JSON5
final String expectedJson =
"{"
+ "timestamp: '${json-unit.any-number}',"
+ "level: 'DEBUG',"
+ "thread: 'Test worker',"
+ "logger: 'de.siegmar.logbackawslogsjsonencoder.AwsJsonLogEncoderTest',"
+ "message: 'message 1',"
+ "markers: {"
+ " 'foo': 1,"
+ " 'bar': 1"
+ "},"
+ "mdc: {"
+ " foo: 'bar',"
+ " baz: null"
+ "},"
+ "keyValues: {"
+ " foo: 'bar',"
+ " bar: null,"
+ " 'null': 'bar'"
+ "}}";
assertThatJson(fullLog()).isEqualTo(json(expectedJson));
}

@Test
Expand Down Expand Up @@ -151,9 +151,9 @@ void stacktrace() {
}

assertThatJson(logMsg).and(
j -> j.node("stacktrace").isString().startsWith("""
java.lang.IllegalArgumentException: Example Exception
\tat de.siegmar.logbackawslogsjsonencoder.AwsJsonLogEncoderTest.stacktrace(AwsJsonLogEncoderTest""")
j -> j.node("stacktrace").isString().startsWith(
"java.lang.IllegalArgumentException: Example Exception\n"
+ "\tat de.siegmar.logbackawslogsjsonencoder.AwsJsonLogEncoderTest.stacktrace(AwsJsonLogEncoderTest")
);
}

Expand All @@ -169,14 +169,14 @@ void rootCause() {
logMsg = fullLog(e);
}

assertThatJson(logMsg).isEqualTo(json("""
{
"rootCause": {
"class": "java.lang.IllegalArgumentException",
"message": "Example Exception"
}
}
"""));
//language=JSON5
final String expectedJson =
"{rootCause: {"
+ "class: 'java.lang.IllegalArgumentException',"
+ "message: 'Example Exception'"
+ "}}";

assertThatJson(logMsg).isEqualTo(json(expectedJson));
}

@Test
Expand All @@ -203,17 +203,16 @@ void keyValues() {
@Test
void caller() {
setupAllDisabledEncoder(c -> c.setIncludeCaller(true));
//language=JSON5
final String expectedJson =
"{caller: {"
+ " file: 'NativeMethodAccessorImpl.java',"
+ " line: -2,"
+ " class: 'jdk.internal.reflect.NativeMethodAccessorImpl',"
+ " method: 'invoke0'"
+ "}}";
assertThatJson(fullLog())
.isEqualTo(json("""
{
"caller": {
"file": "NativeMethodAccessorImpl.java",
"line": -2,
"class": "jdk.internal.reflect.NativeMethodAccessorImpl",
"method": "invoke0"
}
}
"""));
.isEqualTo(json(expectedJson));
}

@Test
Expand All @@ -233,40 +232,43 @@ void customMapper() {
@Test
void complex() {
setupAllEnabledEncoder(c -> c.addStaticField("foo:bar"));
assertThatJson(fullLog()).isEqualTo(json("""
{
"sequenceNumber": 0,
"timestamp": "${json-unit.any-number}",
"nanoseconds": "${json-unit.any-number}",
"level": "DEBUG",
"thread": "Test worker",
"logger": "de.siegmar.logbackawslogsjsonencoder.AwsJsonLogEncoderTest",
"message": "message 1",
"rawMessage": "message {}",
"staticFields": {
"foo": "bar"
},
"markers": {
"foo": 1,
"bar": 1
},
"mdc": {
"foo": "bar",
"baz": null
},
"keyValues": {
"foo": "bar",
"bar": null,
"null": "bar"
},
"caller": {
"file": "NativeMethodAccessorImpl.java",
"line": -2,
"class": "jdk.internal.reflect.NativeMethodAccessorImpl",
"method": "invoke0"
}
}
"""));

//language=JSON5
final String expectedJson =
"{"
+ " sequenceNumber: 0,"
+ " timestamp: '${json-unit.any-number}',"
+ " nanoseconds: '${json-unit.any-number}',"
+ " level: 'DEBUG',"
+ " thread: 'Test worker',"
+ " logger: 'de.siegmar.logbackawslogsjsonencoder.AwsJsonLogEncoderTest',"
+ " message: 'message 1',"
+ " rawMessage: 'message {}',"
+ " staticFields: {"
+ " foo: 'bar'"
+ " },"
+ " markers: {"
+ " foo: 1,"
+ " bar: 1"
+ " },"
+ " mdc: {"
+ " foo: 'bar',"
+ " baz: null"
+ " },"
+ " keyValues: {"
+ " foo: 'bar',"
+ " bar: null,"
+ " 'null': 'bar'"
+ " },"
+ " caller: {"
+ " file: 'NativeMethodAccessorImpl.java',"
+ " line: -2,"
+ " class: 'jdk.internal.reflect.NativeMethodAccessorImpl',"
+ " method: 'invoke0'"
+ " }"
+ "}";

assertThatJson(fullLog()).isEqualTo(json(expectedJson));
}

private void setupAllDisabledEncoder(final Consumer<AwsJsonLogEncoder> customize) {
Expand Down

0 comments on commit e716609

Please sign in to comment.