Add logging configuration. Add --dump
option to just print the full configuration.
This commit is contained in:
@@ -130,6 +130,7 @@ threepid:
|
|||||||
# synapseSql:
|
# synapseSql:
|
||||||
# lookup:
|
# lookup:
|
||||||
# query: 'select user_id as mxid, medium, address from user_threepids' # query for retrive 3PIDs for hashes.
|
# query: 'select user_id as mxid, medium, address from user_threepids' # query for retrive 3PIDs for hashes.
|
||||||
|
# legacyRoomNames: false # use the old query to get room names.
|
||||||
|
|
||||||
### hash lookup for ldap provider (with example of the ldap configuration)
|
### hash lookup for ldap provider (with example of the ldap configuration)
|
||||||
# ldap:
|
# ldap:
|
||||||
@@ -167,3 +168,6 @@ threepid:
|
|||||||
# - '/_matrix/identity/v2/hash_details'
|
# - '/_matrix/identity/v2/hash_details'
|
||||||
# - '/_matrix/identity/v2/lookup'
|
# - '/_matrix/identity/v2/lookup'
|
||||||
#
|
#
|
||||||
|
|
||||||
|
# logging:
|
||||||
|
# root: trace # logging level
|
||||||
|
@@ -44,31 +44,42 @@ public class MxisdStandaloneExec {
|
|||||||
try {
|
try {
|
||||||
MxisdConfig cfg = null;
|
MxisdConfig cfg = null;
|
||||||
Iterator<String> argsIt = Arrays.asList(args).iterator();
|
Iterator<String> argsIt = Arrays.asList(args).iterator();
|
||||||
|
boolean dump = false;
|
||||||
while (argsIt.hasNext()) {
|
while (argsIt.hasNext()) {
|
||||||
String arg = argsIt.next();
|
String arg = argsIt.next();
|
||||||
if (StringUtils.equalsAny(arg, "-h", "--help", "-?", "--usage")) {
|
switch (arg) {
|
||||||
System.out.println("Available arguments:" + System.lineSeparator());
|
case "-h":
|
||||||
System.out.println(" -h, --help Show this help message");
|
case "--help":
|
||||||
System.out.println(" --version Print the version then exit");
|
case "-?":
|
||||||
System.out.println(" -c, --config Set the configuration file location");
|
case "--usage":
|
||||||
System.out.println(" -v Increase log level (log more info)");
|
System.out.println("Available arguments:" + System.lineSeparator());
|
||||||
System.out.println(" -vv Further increase log level");
|
System.out.println(" -h, --help Show this help message");
|
||||||
System.out.println(" ");
|
System.out.println(" --version Print the version then exit");
|
||||||
System.exit(0);
|
System.out.println(" -c, --config Set the configuration file location");
|
||||||
} else if (StringUtils.equals(arg, "-v")) {
|
System.out.println(" -v Increase log level (log more info)");
|
||||||
System.setProperty("org.slf4j.simpleLogger.log.io.kamax.mxisd", "debug");
|
System.out.println(" -vv Further increase log level");
|
||||||
} else if (StringUtils.equals(arg, "-vv")) {
|
System.out.println(" --dump Dump the full ma1sd configuration");
|
||||||
System.setProperty("org.slf4j.simpleLogger.log.io.kamax.mxisd", "trace");
|
System.out.println(" ");
|
||||||
} else if (StringUtils.equalsAny(arg, "-c", "--config")) {
|
System.exit(0);
|
||||||
String cfgFile = argsIt.next();
|
return;
|
||||||
cfg = YamlConfigLoader.loadFromFile(cfgFile);
|
case "-v":
|
||||||
} else if (StringUtils.equals("--version", arg)) {
|
System.setProperty("org.slf4j.simpleLogger.log.io.kamax.mxisd", "debug");
|
||||||
System.out.println(Mxisd.Version);
|
break;
|
||||||
System.exit(0);
|
case "-vv":
|
||||||
} else {
|
System.setProperty("org.slf4j.simpleLogger.log.io.kamax.mxisd", "trace");
|
||||||
System.err.println("Invalid argument: " + arg);
|
break;
|
||||||
System.err.println("Try '--help' for available arguments");
|
case "-c":
|
||||||
System.exit(1);
|
case "--config":
|
||||||
|
String cfgFile = argsIt.next();
|
||||||
|
cfg = YamlConfigLoader.loadFromFile(cfgFile);
|
||||||
|
break;
|
||||||
|
case "--dump":
|
||||||
|
dump = true;
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
System.err.println("Invalid argument: " + arg);
|
||||||
|
System.err.println("Try '--help' for available arguments");
|
||||||
|
System.exit(1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -76,6 +87,11 @@ public class MxisdStandaloneExec {
|
|||||||
cfg = YamlConfigLoader.tryLoadFromFile("ma1sd.yaml").orElseGet(MxisdConfig::new);
|
cfg = YamlConfigLoader.tryLoadFromFile("ma1sd.yaml").orElseGet(MxisdConfig::new);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (dump) {
|
||||||
|
YamlConfigLoader.dumpConfig(cfg);
|
||||||
|
System.exit(0);
|
||||||
|
}
|
||||||
|
|
||||||
log.info("ma1sd starting");
|
log.info("ma1sd starting");
|
||||||
log.info("Version: {}", Mxisd.Version);
|
log.info("Version: {}", Mxisd.Version);
|
||||||
|
|
||||||
|
33
src/main/java/io/kamax/mxisd/config/LoggingConfig.java
Normal file
33
src/main/java/io/kamax/mxisd/config/LoggingConfig.java
Normal 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");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@@ -117,6 +117,7 @@ public class MxisdConfig {
|
|||||||
private WordpressConfig wordpress = new WordpressConfig();
|
private WordpressConfig wordpress = new WordpressConfig();
|
||||||
private PolicyConfig policy = new PolicyConfig();
|
private PolicyConfig policy = new PolicyConfig();
|
||||||
private HashingConfig hashing = new HashingConfig();
|
private HashingConfig hashing = new HashingConfig();
|
||||||
|
private LoggingConfig logging = new LoggingConfig();
|
||||||
|
|
||||||
public AppServiceConfig getAppsvc() {
|
public AppServiceConfig getAppsvc() {
|
||||||
return appsvc;
|
return appsvc;
|
||||||
@@ -342,6 +343,14 @@ public class MxisdConfig {
|
|||||||
this.hashing = hashing;
|
this.hashing = hashing;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public LoggingConfig getLogging() {
|
||||||
|
return logging;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setLogging(LoggingConfig logging) {
|
||||||
|
this.logging = logging;
|
||||||
|
}
|
||||||
|
|
||||||
public MxisdConfig inMemory() {
|
public MxisdConfig inMemory() {
|
||||||
getKey().setPath(":memory:");
|
getKey().setPath(":memory:");
|
||||||
getStorage().getProvider().getSqlite().setDatabase(":memory:");
|
getStorage().getProvider().getSqlite().setDatabase(":memory:");
|
||||||
@@ -350,6 +359,8 @@ public class MxisdConfig {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public MxisdConfig build() {
|
public MxisdConfig build() {
|
||||||
|
getLogging().build();
|
||||||
|
|
||||||
if (StringUtils.isBlank(getServer().getName())) {
|
if (StringUtils.isBlank(getServer().getName())) {
|
||||||
getServer().setName(getMatrix().getDomain());
|
getServer().setName(getMatrix().getDomain());
|
||||||
log.debug("server.name is empty, using matrix.domain");
|
log.debug("server.name is empty, using matrix.domain");
|
||||||
|
@@ -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);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user