X-Git-Url: https://git.argeo.org/?a=blobdiff_plain;f=org.argeo.init%2Fsrc%2Forg%2Fargeo%2Finit%2Flogging%2FThinLoggerFinder.java;h=4147534dd2695abcdc393f7c988ef49965ddc4df;hb=8be06a167888a8ba1f262bbe34c70385807d11c0;hp=9607c9478df78c3f5f259111a4ed7aab46ef4cee;hpb=938f9575c8091c723fa076f3c962e4b29556d2c5;p=lgpl%2Fargeo-commons.git diff --git a/org.argeo.init/src/org/argeo/init/logging/ThinLoggerFinder.java b/org.argeo.init/src/org/argeo/init/logging/ThinLoggerFinder.java index 9607c9478..4147534dd 100644 --- a/org.argeo.init/src/org/argeo/init/logging/ThinLoggerFinder.java +++ b/org.argeo.init/src/org/argeo/init/logging/ThinLoggerFinder.java @@ -2,15 +2,23 @@ package org.argeo.init.logging; import java.lang.System.Logger; import java.lang.System.LoggerFinder; +import java.util.HashMap; +import java.util.Map; +import java.util.Objects; -/** Factory for Java system logging. */ +/** + * Factory for Java system logging. As it has to be a public class in order to + * be exposed as a service provider, it is also the main entry point for the + * thin logging system, via static methos. + */ public class ThinLoggerFinder extends LoggerFinder { private static ThinLogging logging; + private static ThinJavaUtilLogging javaUtilLogging; public ThinLoggerFinder() { if (logging != null) throw new IllegalStateException("Only one logging can be initialised."); - logging = new ThinLogging(); + init(); } @Override @@ -18,17 +26,42 @@ public class ThinLoggerFinder extends LoggerFinder { return logging.getLogger(name, module); } + private static void init() { + logging = new ThinLogging(); + + Map configuration = new HashMap<>(); + for (Object key : System.getProperties().keySet()) { + Objects.requireNonNull(key); + String property = key.toString(); + if (property.startsWith(ThinLogging.LEVEL_PROPERTY_PREFIX) + || property.equals(ThinLogging.DEFAULT_LEVEL_PROPERTY)) + configuration.put(property, System.getProperty(property)); + } + logging.update(configuration); + } + /** * Falls back to java.util.logging if thin logging was not already initialised. */ public static void lazyInit() { if (logging != null) return; - logging = new ThinLogging(); - ThinJavaUtilLogging.init(); + if (javaUtilLogging != null) + return; + init(); + javaUtilLogging = ThinJavaUtilLogging.init(); + javaUtilLogging.readConfiguration(logging.getLevels()); + } + + public static void update(Map configuration) { + if (logging == null) + throw new IllegalStateException("Thin logging must be initialized first"); + logging.update(configuration); + if (javaUtilLogging != null) + javaUtilLogging.readConfiguration(logging.getLevels()); } - public static Logger getLogger(String name) { + static Logger getLogger(String name) { return logging.getLogger(name, null); } }