Skip to content

Commit 229679a

Browse files
troosanSlyngDK
andauthored
Added socket log formatter (#343)
* Added socket log formatter --------- Co-authored-by: Simon Bengtsson <[email protected]>
1 parent eeaaa28 commit 229679a

File tree

8 files changed

+481
-40
lines changed

8 files changed

+481
-40
lines changed

README.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,9 @@ It supports the following formats: default, [Elastic Common Schema (ECS)](https:
1414
| 2.x.x | 1.x.x, 2.x.x |
1515

1616
# Configuration
17-
The extension is enabled by default for console, when added to the project.
18-
Console logging can be disabled using configuration: `quarkus.log.json.console.enabled=false`
17+
The extension is enabled by default for console and socket, when added to the project.
18+
Console json logging can be disabled using configuration: `quarkus.log.json.console.enabled=false`
19+
Socket json logging can be disabled using configuration: `quarkus.log.json.socket.enabled=false`
1920

2021
To see additional configuration options take a look at [Config](https://quarkiverse.github.io/quarkiverse-docs/quarkus-logging-json/dev/index.html)
2122

deployment/src/main/java/io/quarkiverse/loggingjson/deployment/LoggingJsonProcessor.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
import io.quarkus.deployment.builditem.FeatureBuildItem;
2121
import io.quarkus.deployment.builditem.LogConsoleFormatBuildItem;
2222
import io.quarkus.deployment.builditem.LogFileFormatBuildItem;
23+
import io.quarkus.deployment.builditem.LogSocketFormatBuildItem;
2324

2425
class LoggingJsonProcessor {
2526

@@ -44,6 +45,13 @@ LogFileFormatBuildItem setUpFileFormatter(Capabilities capabilities, LoggingJson
4445
return new LogFileFormatBuildItem(recorder.initializeFileJsonLogging(config, jsonFactory(capabilities)));
4546
}
4647

48+
@BuildStep
49+
@Record(ExecutionTime.RUNTIME_INIT)
50+
LogSocketFormatBuildItem setUpSocketFormatter(Capabilities capabilities, LoggingJsonRecorder recorder,
51+
Config config) {
52+
return new LogSocketFormatBuildItem(recorder.initializeSocketJsonLogging(config, jsonFactory(capabilities)));
53+
}
54+
4755
private JsonFactory jsonFactory(Capabilities capabilities) {
4856
if (capabilities.isPresent(Capability.JACKSON)) {
4957
return new JacksonJsonFactory();

deployment/src/test/java/io/quarkiverse/loggingjson/deployment/providers/custom/CustomJsonProviderJsonbTest.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,11 +55,11 @@ void testCustomJsonProvider() throws Exception {
5555
Assertions.assertTrue(firstCustomJsonProvider.getWriteToNumberOfCalls() > 0);
5656

5757
Assertions.assertTrue(fields.contains("second"));
58-
Assertions.assertEquals(2, secondCustomJsonProvider.getIsEnabledNumberOfCalls()); // expecting both console and file formatter to call
58+
Assertions.assertEquals(3, secondCustomJsonProvider.getIsEnabledNumberOfCalls()); // expecting console, file and socket formatters to call
5959
Assertions.assertTrue(secondCustomJsonProvider.getWriteToNumberOfCalls() > 0);
6060

6161
Assertions.assertFalse(fields.contains("third"));
62-
Assertions.assertEquals(2, thirdCustomJsonProvider.getIsEnabledNumberOfCalls()); // expecting both console and file formatter to call
62+
Assertions.assertEquals(3, thirdCustomJsonProvider.getIsEnabledNumberOfCalls()); // expecting console, file and socket formatters to call
6363
Assertions.assertEquals(0, thirdCustomJsonProvider.getWriteToNumberOfCalls());
6464
}
6565
}

0 commit comments

Comments
 (0)