Add logging configuration. Add --dump option to just print the full configuration.

This commit is contained in:
Anatoly Sablin
2020-01-25 14:57:22 +03:00
parent 73526be2ac
commit 9219bd4723
5 changed files with 97 additions and 23 deletions

View File

@@ -0,0 +1,33 @@
package io.kamax.mxisd.config;
import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
public class LoggingConfig {
private static final Logger LOGGER = LoggerFactory.getLogger(LoggingConfig.class);
private String root;
public String getRoot() {
return root;
}
public void setRoot(String root) {
this.root = root;
}
public void build() {
String systemLevel = System.getProperty("org.slf4j.simpleLogger.log.io.kamax.mxisd");
LOGGER.info("Logging config:");
if (StringUtils.isNotBlank(systemLevel)) {
LOGGER.info(" Logging level set by environment: {}", systemLevel);
} else if (StringUtils.isNotBlank(getRoot())) {
LOGGER.info(" Logging level set by the configuration: {}", getRoot());
System.setProperty("org.slf4j.simpleLogger.log.io.kamax.mxisd", getRoot());
} else {
LOGGER.info(" Logging level hasn't set, use default");
}
}
}

View File

@@ -117,6 +117,7 @@ public class MxisdConfig {
private WordpressConfig wordpress = new WordpressConfig();
private PolicyConfig policy = new PolicyConfig();
private HashingConfig hashing = new HashingConfig();
private LoggingConfig logging = new LoggingConfig();
public AppServiceConfig getAppsvc() {
return appsvc;
@@ -342,6 +343,14 @@ public class MxisdConfig {
this.hashing = hashing;
}
public LoggingConfig getLogging() {
return logging;
}
public void setLogging(LoggingConfig logging) {
this.logging = logging;
}
public MxisdConfig inMemory() {
getKey().setPath(":memory:");
getStorage().getProvider().getSqlite().setDatabase(":memory:");
@@ -350,6 +359,8 @@ public class MxisdConfig {
}
public MxisdConfig build() {
getLogging().build();
if (StringUtils.isBlank(getServer().getName())) {
getServer().setName(getMatrix().getDomain());
log.debug("server.name is empty, using matrix.domain");

View File

@@ -76,4 +76,14 @@ public class YamlConfigLoader {
}
}
public static void dumpConfig(MxisdConfig cfg) {
Representer rep = new Representer();
rep.getPropertyUtils().setBeanAccess(BeanAccess.FIELD);
rep.getPropertyUtils().setAllowReadOnlyProperties(true);
rep.getPropertyUtils().setSkipMissingProperties(true);
Yaml yaml = new Yaml(new Constructor(MxisdConfig.class), rep);
String dump = yaml.dump(cfg);
log.info("Full configuration:\n{}", dump);
}
}