Improve logging

This commit is contained in:
Max Dor
2019-02-07 01:35:43 +01:00
parent 3a6b75996c
commit 471e06536b
12 changed files with 48 additions and 35 deletions

View File

@@ -111,7 +111,6 @@ public class HttpMxisd {
public void stop() { public void stop() {
httpSrv.stop(); httpSrv.stop();
m.stop(); m.stop();
} }

View File

@@ -56,31 +56,31 @@ import java.util.ServiceLoader;
public class Mxisd { public class Mxisd {
protected MxisdConfig cfg; private MxisdConfig cfg;
protected CloseableHttpClient httpClient; private CloseableHttpClient httpClient;
protected IRemoteIdentityServerFetcher srvFetcher; private IRemoteIdentityServerFetcher srvFetcher;
protected IStorage store; private IStorage store;
protected KeyManager keyMgr; private KeyManager keyMgr;
protected SignatureManager signMgr; private SignatureManager signMgr;
// Features // Features
protected AuthManager authMgr; private AuthManager authMgr;
protected DirectoryManager dirMgr; private DirectoryManager dirMgr;
protected LookupStrategy idStrategy; private LookupStrategy idStrategy;
protected InvitationManager invMgr; private InvitationManager invMgr;
protected ProfileManager pMgr; private ProfileManager pMgr;
protected AppSvcManager asHander; private AppSvcManager asHander;
protected SessionManager sessMgr; private SessionManager sessMgr;
protected NotificationManager notifMgr; private NotificationManager notifMgr;
public Mxisd(MxisdConfig cfg) { public Mxisd(MxisdConfig cfg) {
this.cfg = cfg.build(); this.cfg = cfg.build();
} }
protected void build() { private void build() {
httpClient = HttpClients.custom() httpClient = HttpClients.custom()
.setUserAgent("mxisd") .setUserAgent("mxisd")
.setMaxConnPerRoute(Integer.MAX_VALUE) .setMaxConnPerRoute(Integer.MAX_VALUE)

View File

@@ -23,6 +23,8 @@ package io.kamax.mxisd;
import io.kamax.mxisd.config.MxisdConfig; import io.kamax.mxisd.config.MxisdConfig;
import io.kamax.mxisd.config.YamlConfigLoader; import io.kamax.mxisd.config.YamlConfigLoader;
import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.io.IOException; import java.io.IOException;
import java.util.Arrays; import java.util.Arrays;
@@ -31,7 +33,10 @@ import java.util.Objects;
public class MxisdStandaloneExec { public class MxisdStandaloneExec {
private static final Logger log = LoggerFactory.getLogger("");
public static void main(String[] args) throws IOException { public static void main(String[] args) throws IOException {
log.info("------------- mxisd starting -------------");
MxisdConfig cfg = null; MxisdConfig cfg = null;
Iterator<String> argsIt = Arrays.asList(args).iterator(); Iterator<String> argsIt = Arrays.asList(args).iterator();
@@ -40,9 +45,8 @@ public class MxisdStandaloneExec {
if (StringUtils.equals("-c", arg)) { if (StringUtils.equals("-c", arg)) {
String cfgFile = argsIt.next(); String cfgFile = argsIt.next();
cfg = YamlConfigLoader.loadFromFile(cfgFile); cfg = YamlConfigLoader.loadFromFile(cfgFile);
System.out.println("Loaded configuration from " + cfgFile);
} else { } else {
System.out.println("Invalid argument: " + arg); log.info("Invalid argument: {}", arg);
System.exit(1); System.exit(1);
} }
} }
@@ -55,11 +59,11 @@ public class MxisdStandaloneExec {
HttpMxisd mxisd = new HttpMxisd(cfg); HttpMxisd mxisd = new HttpMxisd(cfg);
Runtime.getRuntime().addShutdownHook(new Thread(() -> { Runtime.getRuntime().addShutdownHook(new Thread(() -> {
mxisd.stop(); mxisd.stop();
System.out.println("------------- mxisd stopped -------------"); log.info("------------- mxisd stopped -------------");
})); }));
mxisd.start(); mxisd.start();
System.out.println("------------- mxisd started -------------"); log.info("------------- mxisd started -------------");
} catch (Throwable t) { } catch (Throwable t) {
t.printStackTrace(); t.printStackTrace();
System.exit(1); System.exit(1);

View File

@@ -64,8 +64,8 @@ public class DirectoryConfig {
public void build() { public void build() {
log.info("--- Directory config ---"); log.info("--- Directory config ---");
log.info("Exclude:"); log.info("Exclude:");
log.info("\tHomeserver: {}", getExclude().getHomeserver()); log.info(" Homeserver: {}", getExclude().getHomeserver());
log.info("\t3PID: {}", getExclude().getThreepid()); log.info(" 3PID: {}", getExclude().getThreepid());
} }
} }

View File

@@ -21,6 +21,8 @@
package io.kamax.mxisd.config; package io.kamax.mxisd.config;
import io.kamax.matrix.json.GsonUtil; import io.kamax.matrix.json.GsonUtil;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.yaml.snakeyaml.Yaml; import org.yaml.snakeyaml.Yaml;
import org.yaml.snakeyaml.constructor.Constructor; import org.yaml.snakeyaml.constructor.Constructor;
import org.yaml.snakeyaml.representer.Representer; import org.yaml.snakeyaml.representer.Representer;
@@ -32,21 +34,29 @@ import java.util.Optional;
public class YamlConfigLoader { public class YamlConfigLoader {
private static final Logger log = LoggerFactory.getLogger(YamlConfigLoader.class);
public static MxisdConfig loadFromFile(String path) throws IOException { public static MxisdConfig loadFromFile(String path) throws IOException {
log.debug("Reading config from {}", path);
Representer rep = new Representer(); Representer rep = new Representer();
rep.getPropertyUtils().setAllowReadOnlyProperties(true); rep.getPropertyUtils().setAllowReadOnlyProperties(true);
rep.getPropertyUtils().setSkipMissingProperties(true); rep.getPropertyUtils().setSkipMissingProperties(true);
Yaml yaml = new Yaml(new Constructor(MxisdConfig.class), rep); Yaml yaml = new Yaml(new Constructor(MxisdConfig.class), rep);
try (FileInputStream is = new FileInputStream(path)) { try (FileInputStream is = new FileInputStream(path)) {
Object o = yaml.load(is); Object o = yaml.load(is);
return GsonUtil.get().fromJson(GsonUtil.get().toJson(o), MxisdConfig.class); log.debug("Read config in memory from {}", path);
MxisdConfig cfg = GsonUtil.get().fromJson(GsonUtil.get().toJson(o), MxisdConfig.class);
log.info("Loaded config from {}", path);
return cfg;
} }
} }
public static Optional<MxisdConfig> tryLoadFromFile(String path) { public static Optional<MxisdConfig> tryLoadFromFile(String path) {
log.debug("Attempting to read config from {}", path);
try { try {
return Optional.of(loadFromFile(path)); return Optional.of(loadFromFile(path));
} catch (FileNotFoundException e) { } catch (FileNotFoundException e) {
log.info("No config file at {}", path);
return Optional.empty(); return Optional.empty();
} catch (IOException e) { } catch (IOException e) {
throw new RuntimeException(e); throw new RuntimeException(e);

View File

@@ -421,9 +421,9 @@ public abstract class LdapConfig {
log.info("Port: {}", connection.getPort()); log.info("Port: {}", connection.getPort());
log.info("TLS: {}", connection.isTls()); log.info("TLS: {}", connection.isTls());
log.info("Bind DN: {}", connection.getBindDn()); log.info("Bind DN: {}", connection.getBindDn());
log.info("Base DNs: {}"); log.info("Base DNs:");
for (String baseDN : connection.getBaseDNs()) { for (String baseDN : connection.getBaseDNs()) {
log.info("\t- {}", baseDN); log.info(" - {}", baseDN);
} }
log.info("Attribute: {}", GsonUtil.get().toJson(attribute)); log.info("Attribute: {}", GsonUtil.get().toJson(attribute));

View File

@@ -38,9 +38,9 @@ public class EmailTemplateConfig extends GenericTemplateConfig {
log.info("--- E-mail Generator templates config ---"); log.info("--- E-mail Generator templates config ---");
log.info("Invite: {}", getName(getInvite())); log.info("Invite: {}", getName(getInvite()));
log.info("Session:"); log.info("Session:");
log.info("\tValidation: {}", getSession().getValidation()); log.info(" Validation: {}", getSession().getValidation());
log.info("\tUnbind:"); log.info(" Unbind:");
log.info("\t\tFraudulent: {}", getSession().getUnbind().getFraudulent()); log.info(" Fraudulent: {}", getSession().getUnbind().getFraudulent());
return this; return this;
} }

View File

@@ -37,9 +37,9 @@ public class PhoneSmsTemplateConfig extends GenericTemplateConfig {
log.info("--- SMS Generator templates config ---"); log.info("--- SMS Generator templates config ---");
log.info("Invite: {}", getName(getInvite())); log.info("Invite: {}", getName(getInvite()));
log.info("Session:"); log.info("Session:");
log.info("\tValidation: {}", getSession().getValidation()); log.info(" Validation: {}", getSession().getValidation());
log.info("\tUnbind:"); log.info(" Unbind:");
log.info("\t\tFraudulent: {}", getSession().getUnbind().getFraudulent()); log.info(" Fraudulent: {}", getSession().getUnbind().getFraudulent());
return this; return this;
} }

View File

@@ -61,7 +61,7 @@ public class NotificationConfig {
public void build() { public void build() {
log.info("--- Notification config ---"); log.info("--- Notification config ---");
log.info("Handlers:"); log.info("Handlers:");
handler.forEach((k, v) -> log.info("\t{}: {}", k, v)); handler.forEach((k, v) -> log.info(" {}: {}", k, v));
} }
} }

View File

@@ -62,7 +62,7 @@ public class DirectoryManager {
this.providers = new ArrayList<>(providers); this.providers = new ArrayList<>(providers);
log.info("Directory providers:"); log.info("Directory providers:");
this.providers.forEach(p -> log.info("\t- {}", p.getClass().getName())); this.providers.forEach(p -> log.info(" - {}", p.getClass().getName()));
} }
public UserDirectorySearchResult search(URI target, String accessToken, String query) { public UserDirectorySearchResult search(URI target, String accessToken, String query) {

View File

@@ -57,7 +57,7 @@ public class RecursivePriorityLookupStrategy implements LookupStrategy {
try { try {
log.info("Found {} providers", providers.size()); log.info("Found {} providers", providers.size());
providers.forEach(p -> log.info("\t- {}", p.getClass().getName())); providers.forEach(p -> log.info(" - {}", p.getClass().getName()));
providers.sort((o1, o2) -> Integer.compare(o2.getPriority(), o1.getPriority())); providers.sort((o1, o2) -> Integer.compare(o2.getPriority(), o1.getPriority()));
log.info("Recursive lookup enabled: {}", cfg.getRecursive().isEnabled()); log.info("Recursive lookup enabled: {}", cfg.getRecursive().isEnabled());

View File

@@ -58,7 +58,7 @@ public class ProfileManager {
this.providers = new ArrayList<>(providers); this.providers = new ArrayList<>(providers);
log.info("Profile Providers:"); log.info("Profile Providers:");
providers.forEach(p -> log.info("\t- {}", p.getClass().getSimpleName())); providers.forEach(p -> log.info(" - {}", p.getClass().getSimpleName()));
} }
public <T> List<T> getList(Function<ProfileProvider, List<T>> function) { public <T> List<T> getList(Function<ProfileProvider, List<T>> function) {