made loglevels configurable
Signed-off-by: Stephan Richter <s.richter@srsoftware.de>
This commit is contained in:
@@ -16,4 +16,5 @@ dependencies {
|
||||
implementation("de.srsoftware:tools.util:1.3.0")
|
||||
implementation("de.srsoftware:tools.web:1.3.14")
|
||||
implementation("com.mysql:mysql-connector-j:9.1.0")
|
||||
implementation("org.json:json:20240303")
|
||||
}
|
||||
|
||||
@@ -14,6 +14,8 @@ import de.srsoftware.configuration.Configuration;
|
||||
import de.srsoftware.configuration.JsonConfig;
|
||||
import de.srsoftware.tools.ColorLogger;
|
||||
import de.srsoftware.tools.plugin.JarWatchdog;
|
||||
import org.json.JSONObject;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.net.InetSocketAddress;
|
||||
@@ -52,10 +54,10 @@ public class Application {
|
||||
*/
|
||||
public static void main(String[] args) throws IOException, SQLException {
|
||||
LOG.log(INFO, "Starting application…");
|
||||
ColorLogger.setRootLogLevel(DEBUG);
|
||||
ColorLogger.setLogLevel("jdk.event.security",INFO);
|
||||
ColorLogger.setLogLevel("sun.net.www.protocol.http.HttpURLConnection",INFO);
|
||||
JsonConfig jsonConfig = new JsonConfig("OpenCloudCal");
|
||||
|
||||
configureLogging(jsonConfig);
|
||||
|
||||
Optional<String> staticPath = jsonConfig.get("opencloudcal.static");
|
||||
var db = connect(jsonConfig);
|
||||
var port = jsonConfig.get("opencloudcal.http.port", 8080);
|
||||
@@ -75,8 +77,29 @@ public class Application {
|
||||
.addListener(autoImport)
|
||||
.afterScan(autoImport)
|
||||
.start();
|
||||
}
|
||||
|
||||
// TODO: add importers
|
||||
private static void configureLogging(JsonConfig jsonConfig) {
|
||||
var rootLevel = jsonConfig.get("opencloudcal.logging.rootlevel", "INFO");
|
||||
ColorLogger.setRootLogLevel(mapLogLevel(rootLevel));
|
||||
|
||||
var loggers = jsonConfig.get("opencloudcal.logging.loggers").orElse(null);
|
||||
if (loggers instanceof JSONObject json){
|
||||
json.keySet().forEach(key -> {
|
||||
var lvl = mapLogLevel(json.getString(key));
|
||||
ColorLogger.setLogLevel(key,lvl);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
private static System.Logger.Level mapLogLevel(String lbl) {
|
||||
return switch (lbl){
|
||||
case "ERROR" -> ERROR;
|
||||
case "WARN" -> WARNING;
|
||||
case "DEBUG" -> DEBUG;
|
||||
case "TRACE" -> TRACE;
|
||||
default ->INFO;
|
||||
};
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -287,11 +287,11 @@ public class AutoImporter implements Runnable, ClassListener {
|
||||
|
||||
@Override
|
||||
public void classAdded(Class<?> aClass) {
|
||||
if (Importer.class.isAssignableFrom(aClass))) try {
|
||||
if (Importer.class.isAssignableFrom(aClass)) try {
|
||||
var instance = aClass.getDeclaredConstructor().newInstance();
|
||||
importers.add((Importer) instance);
|
||||
lastImport = null;
|
||||
LOG.log(INFO,"Added {0} to the list of importers. Will be used soon…",instance);
|
||||
LOG.log(INFO,"Added {0} to the list of importers. Will be used soon…",aClass.getSimpleName());
|
||||
} catch (Exception e) {
|
||||
LOG.log(WARNING,"Failed to add importer: {0}",aClass.getSimpleName(),e);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user