fix build

This commit is contained in:
Stephan Schnabel 2023-09-15 10:34:37 +02:00
parent 4c4a43ac0d
commit e4388e01b9
Signed by: stephan.schnabel
GPG key ID: E07AF5BA239FE543
3 changed files with 34 additions and 7 deletions

View file

@ -64,8 +64,7 @@
<maven.compiler.source>17</maven.compiler.source>
<maven.compiler.target>17</maven.compiler.target>
<invoker.parallelThreads>1C</invoker.parallelThreads>
<maven.compiler.implicit>class</maven.compiler.implicit>
<!-- ===================================================================== -->
<!-- ============================= Versions ============================== -->

View file

@ -1,5 +1,6 @@
package io.kokuwa.micronaut.logging.mdc;
import java.util.Collection;
import java.util.Set;
import org.slf4j.Logger;
@ -13,33 +14,58 @@ import io.micronaut.context.annotation.Requires;
import io.micronaut.context.env.Environment;
import io.micronaut.core.type.Argument;
import io.micronaut.core.util.StringUtils;
import io.micronaut.logging.LogLevel;
import io.micronaut.logging.LoggingSystem;
/**
* Configure MDC filter.
*
* @author Stephan Schnabel
*/
@BootstrapContextCompatible
@Requires(beans = LogbackUtil.class)
@Requires(property = MDCTurboFilterConfigurer.PREFIX)
@Requires(property = MDCTurboFilterConfigurer.PREFIX + ".enabled", notEquals = StringUtils.FALSE)
@BootstrapContextCompatible
@Context
public class MDCTurboFilterConfigurer {
public class MDCTurboFilterConfigurer implements LoggingSystem {
public static final String PREFIX = "logger.mdc";
private static final Logger log = LoggerFactory.getLogger(MDCTurboFilterConfigurer.class);
private final LogbackUtil logback;
private final Environment environment;
private Collection<String> mdcs = Set.of();
private boolean initialized;
public MDCTurboFilterConfigurer(LogbackUtil logback, Environment environment) {
this.logback = logback;
this.environment = environment;
configure();
this.refresh();
}
public void configure() {
for (var name : environment.getPropertyEntries(PREFIX)) {
@Override
public void refresh() {
mdcs = environment.getPropertyEntries(PREFIX);
initialized = false;
if (environment.getProperties("logger.levels").isEmpty()) {
log.warn("MDCs are configured, but no levels are set. MDC may not work.");
}
}
@Override
public void setLogLevel(String name, LogLevel level) {
if (!initialized) {
configure();
initialized = true;
}
}
private void configure() {
for (var name : mdcs) {
var prefix = PREFIX + "." + name + ".";
var key = environment.getProperty(prefix + "key", String.class, name);

View file

@ -1,4 +1,6 @@
logger:
levels:
io.micronaut.logging.PropertiesLoggingLevelsConfigurer: "OFF"
mdc:
key1:
key: key