Skip to content

Commit 37dbe6f

Browse files
committed
Provide a FallbackConfigSourceInterceptor and add a test
Also fix the relocations as they were incorrect before.
1 parent 74b4581 commit 37dbe6f

File tree

6 files changed

+104
-33
lines changed

6 files changed

+104
-33
lines changed

README.md

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -63,15 +63,16 @@ public class MyJsonProvider implements JsonProvider {
6363
}
6464
```
6565

66-
## Property Relocation
66+
## Configuration Properties Relocation
6767

68-
This project includes a configuration property relocation mechanism using SmallRye Config's `RelocateConfigSourceInterceptor`.
69-
It supports backward compatibility by allowing both old and new property names:
68+
In 3.2.0, two configuration properties were renamed to be more consistent with Quarkus configuration.
7069

71-
- Old: `quarkus.log.console.json.enable` → New: `quarkus.log.console.json.enabled`
72-
- Old: `quarkus.log.file.json.enable` → New: `quarkus.log.file.json.enabled`
70+
- Old: `quarkus.log.json.console.enable` → New: `quarkus.log.json.console.enabled`
71+
- Old: `quarkus.log.json.file.enable` → New: `quarkus.log.json.file.enabled`
7372

74-
When using the old property names, a log message will be generated advising to update to the new property names.
73+
A relocation/fallback mechanism has been added so the old properties are still supported
74+
but we recomment that you switch to the new ones
75+
(`quarkus update` will do it for you).
7576

7677
## Contributors ✨
7778

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
package io.quarkiverse.loggingjson.deployment;
2+
3+
import java.util.Arrays;
4+
import java.util.Collections;
5+
import java.util.logging.Handler;
6+
import java.util.logging.Level;
7+
import java.util.logging.LogManager;
8+
import java.util.logging.Logger;
9+
10+
import org.jboss.logmanager.handlers.ConsoleHandler;
11+
import org.jboss.logmanager.handlers.FileHandler;
12+
import org.jboss.shrinkwrap.api.ShrinkWrap;
13+
import org.jboss.shrinkwrap.api.spec.JavaArchive;
14+
import org.junit.jupiter.api.Assertions;
15+
import org.junit.jupiter.api.Test;
16+
import org.junit.jupiter.api.extension.RegisterExtension;
17+
18+
import io.quarkiverse.loggingjson.JsonFormatter;
19+
import io.quarkus.bootstrap.logging.InitialConfigurator;
20+
import io.quarkus.bootstrap.logging.QuarkusDelayedHandler;
21+
import io.quarkus.bootstrap.model.AppArtifact;
22+
import io.quarkus.test.QuarkusUnitTest;
23+
24+
/**
25+
* In this test, we check that the feature is disabled as it is the only way to check the relocation/fallback works.
26+
*/
27+
class JsonDeprecatedConfigTest {
28+
29+
@RegisterExtension
30+
static final QuarkusUnitTest config = new QuarkusUnitTest()
31+
.setArchiveProducer(() -> ShrinkWrap.create(JavaArchive.class))
32+
.setForcedDependencies(Collections.singletonList(
33+
new AppArtifact("io.quarkus", "quarkus-jackson", System.getProperty("test.quarkus.version"))))
34+
.withConfigurationResource("application-json-deprecated-config.properties");
35+
36+
static {
37+
System.setProperty("java.util.logging.manager", org.jboss.logmanager.LogManager.class.getName());
38+
}
39+
40+
@Test
41+
void testJsonLoggingDisabled() throws Exception {
42+
LogManager logManager = LogManager.getLogManager();
43+
Assertions.assertTrue(logManager instanceof org.jboss.logmanager.LogManager);
44+
45+
QuarkusDelayedHandler delayedHandler = InitialConfigurator.DELAYED_HANDLER;
46+
Assertions.assertTrue(Arrays.asList(Logger.getLogger("").getHandlers()).contains(delayedHandler));
47+
Assertions.assertEquals(Level.ALL, delayedHandler.getLevel());
48+
49+
Handler consoleHandler = Arrays.stream(delayedHandler.getHandlers())
50+
.filter(h -> (h instanceof ConsoleHandler))
51+
.findFirst().orElse(null);
52+
Assertions.assertNotNull(consoleHandler);
53+
54+
Assertions.assertFalse(consoleHandler.getFormatter() instanceof JsonFormatter);
55+
56+
Handler fileHandler = Arrays.stream(delayedHandler.getHandlers())
57+
.filter(h -> (h instanceof FileHandler))
58+
.findFirst().orElse(null);
59+
Assertions.assertNotNull(fileHandler);
60+
61+
Assertions.assertFalse(fileHandler.getFormatter() instanceof JsonFormatter);
62+
}
63+
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
quarkus.log.level=INFO
2+
quarkus.log.console.enable=true
3+
quarkus.log.console.level=WARNING
4+
quarkus.log.json.console.enable=false
5+
quarkus.log.json.fields.arguments.include-non-structured-arguments=true
6+
quarkus.log.json.additional-field.serviceName.value=deployment-test
7+
quarkus.log.file.enable=true
8+
quarkus.log.json.file.enable=false
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
package io.quarkiverse.loggingjson.config;
2+
3+
import java.util.Map;
4+
import java.util.Map.Entry;
5+
import java.util.stream.Collectors;
6+
7+
import io.smallrye.config.FallbackConfigSourceInterceptor;
8+
9+
/**
10+
* @deprecated maps the old config to the new config, should be removed at some point
11+
*/
12+
@Deprecated(forRemoval = true, since = "3.2.0")
13+
public class LoggingConfigFallbackConfigSourceInterceptor extends FallbackConfigSourceInterceptor {
14+
15+
private static final Map<String, String> FALLBACKS = LoggingConfigRelocateConfigSourceInterceptor.RELOCATIONS.entrySet()
16+
.stream().collect(Collectors.toUnmodifiableMap(Entry::getValue, Entry::getKey));
17+
18+
public LoggingConfigFallbackConfigSourceInterceptor() {
19+
super(FALLBACKS);
20+
}
21+
}
Lines changed: 4 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,40 +1,17 @@
11
package io.quarkiverse.loggingjson.config;
22

3-
import java.util.HashSet;
4-
import java.util.Iterator;
53
import java.util.Map;
6-
import java.util.Set;
74

8-
import io.smallrye.config.ConfigSourceInterceptorContext;
95
import io.smallrye.config.RelocateConfigSourceInterceptor;
106

7+
@Deprecated(forRemoval = true, since = "3.2.0")
118
public class LoggingConfigRelocateConfigSourceInterceptor extends RelocateConfigSourceInterceptor {
129

13-
private static final Map<String, String> RELOCATIONS = relocations();
10+
static final Map<String, String> RELOCATIONS = Map.of(
11+
"quarkus.log.json.console.enable", "quarkus.log.json.console.enabled",
12+
"quarkus.log.json.file.enable", "quarkus.log.json.file.enabled");
1413

1514
public LoggingConfigRelocateConfigSourceInterceptor() {
1615
super(RELOCATIONS);
1716
}
18-
19-
@Override
20-
public Iterator<String> iterateNames(final ConfigSourceInterceptorContext context) {
21-
final Set<String> names = new HashSet<>();
22-
final Iterator<String> namesIterator = context.iterateNames();
23-
while (namesIterator.hasNext()) {
24-
final String name = namesIterator.next();
25-
names.add(name);
26-
final String mappedName = RELOCATIONS.get(name);
27-
if (mappedName != null) {
28-
names.add(mappedName);
29-
}
30-
}
31-
return names.iterator();
32-
}
33-
34-
private static Map<String, String> relocations() {
35-
return Map.of(
36-
"quarkus.log.console.json.enable", "quarkus.log.console.json.enabled",
37-
"quarkus.log.file.json.enable", "quarkus.log.file.json.enabled");
38-
}
39-
4017
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
11
io.quarkiverse.loggingjson.config.LoggingConfigRelocateConfigSourceInterceptor
2+
io.quarkiverse.loggingjson.config.LoggingConfigFallbackConfigSourceInterceptor

0 commit comments

Comments
 (0)