X-Git-Url: https://git.argeo.org/?a=blobdiff_plain;f=org.argeo.init%2Fsrc%2Forg%2Fargeo%2Finit%2Fosgi%2FOsgiBootUtils.java;h=e0b2f155105c83aa7402fa8cadfbd32ccc2dfb2b;hb=8321a31f879e6998ed4fe9c70f3cd3faa21e4a0f;hp=d8efe83435bb8b745a51ab977dde354b4b4b058d;hpb=1373140cfa15adfcad5213945106b8b5f4ef8c88;p=lgpl%2Fargeo-commons.git diff --git a/org.argeo.init/src/org/argeo/init/osgi/OsgiBootUtils.java b/org.argeo.init/src/org/argeo/init/osgi/OsgiBootUtils.java index d8efe8343..e0b2f1551 100644 --- a/org.argeo.init/src/org/argeo/init/osgi/OsgiBootUtils.java +++ b/org.argeo.init/src/org/argeo/init/osgi/OsgiBootUtils.java @@ -1,12 +1,12 @@ package org.argeo.init.osgi; -import java.text.DateFormat; -import java.text.SimpleDateFormat; +import java.lang.System.Logger; +import java.lang.System.Logger.Level; import java.util.ArrayList; -import java.util.Date; import java.util.HashMap; import java.util.List; import java.util.Map; +import java.util.Objects; import java.util.Optional; import java.util.ServiceLoader; import java.util.StringTokenizer; @@ -18,33 +18,45 @@ import org.osgi.framework.launch.FrameworkFactory; /** Utilities, mostly related to logging. */ public class OsgiBootUtils { - /** ISO8601 (as per log4j) and difference to UTC */ - private static DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss,SSS Z"); + private final static Logger logger = System.getLogger(OsgiBootUtils.class.getName()); - static boolean debug = System.getProperty(OsgiBoot.PROP_ARGEO_OSGI_BOOT_DEBUG) == null ? false - : !System.getProperty(OsgiBoot.PROP_ARGEO_OSGI_BOOT_DEBUG).trim().equals("false"); +// /** ISO8601 (as per log4j) and difference to UTC */ +// private static DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss,SSS Z"); +// static boolean debug = System.getProperty(OsgiBoot.PROP_ARGEO_OSGI_BOOT_DEBUG) == null ? false +// : !System.getProperty(OsgiBoot.PROP_ARGEO_OSGI_BOOT_DEBUG).trim().equals("false"); + + @Deprecated public static void info(Object obj) { - System.out.println("# OSGiBOOT # " + dateFormat.format(new Date()) + " # " + obj); +// System.out.println("# OSGiBOOT # " + dateFormat.format(new Date()) + " # " + obj); + logger.log(Level.INFO, () -> Objects.toString(obj)); } + @Deprecated public static void debug(Object obj) { - if (debug) - System.out.println("# OSGiBOOT DBG # " + dateFormat.format(new Date()) + " # " + obj); +// if (debug) +// System.out.println("# OSGiBOOT DBG # " + dateFormat.format(new Date()) + " # " + obj); + logger.log(Level.TRACE, () -> Objects.toString(obj)); } + @Deprecated public static void warn(Object obj) { - System.out.println("# OSGiBOOT WARN # " + dateFormat.format(new Date()) + " # " + obj); +// System.out.println("# OSGiBOOT WARN # " + dateFormat.format(new Date()) + " # " + obj); + logger.log(Level.WARNING, () -> Objects.toString(obj)); } + @Deprecated public static void error(Object obj, Throwable e) { - System.err.println("# OSGiBOOT ERR # " + dateFormat.format(new Date()) + " # " + obj); - if (e != null) - e.printStackTrace(); +// System.err.println("# OSGiBOOT ERR # " + dateFormat.format(new Date()) + " # " + obj); +// if (e != null) +// e.printStackTrace(); + logger.log(Level.ERROR, () -> Objects.toString(obj), e); } + @Deprecated public static boolean isDebug() { - return debug; +// return debug; + return logger.isLoggable(Level.TRACE); } public static String stateAsString(int state) { @@ -137,6 +149,7 @@ public class OsgiBootUtils { return framework; } + @Deprecated public static Map equinoxArgsToConfiguration(String[] args) { // FIXME implement it return new HashMap<>();