Fall back to java.util.logging in a pure OSGi environment
[lgpl/argeo-commons.git] / org.argeo.init / src / org / argeo / init / logging / ThinLoggerFinder.java
index 7849309460933695f5b60a96d44f5e8cf2592c4c..9607c9478df78c3f5f259111a4ed7aab46ef4cee 100644 (file)
@@ -5,9 +5,11 @@ import java.lang.System.LoggerFinder;
 
 /** Factory for Java system logging. */
 public class ThinLoggerFinder extends LoggerFinder {
-       private ThinLogging logging;
+       private static ThinLogging logging;
 
        public ThinLoggerFinder() {
+               if (logging != null)
+                       throw new IllegalStateException("Only one logging can be initialised.");
                logging = new ThinLogging();
        }
 
@@ -16,4 +18,17 @@ public class ThinLoggerFinder extends LoggerFinder {
                return logging.getLogger(name, module);
        }
 
+       /**
+        * 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();
+       }
+
+       public static Logger getLogger(String name) {
+               return logging.getLogger(name, null);
+       }
 }