From c26d3413ceab0f0d987711e33f0b7755d0cc5176 Mon Sep 17 00:00:00 2001
From: brinn <brinn>
Date: Thu, 8 Sep 2011 13:57:44 +0000
Subject: [PATCH] add: method initDebug()

SVN: 22835
---
 .../cisd/common/logging/LogInitializer.java   | 39 ++++++++++++++++++-
 1 file changed, 37 insertions(+), 2 deletions(-)

diff --git a/common/source/java/ch/systemsx/cisd/common/logging/LogInitializer.java b/common/source/java/ch/systemsx/cisd/common/logging/LogInitializer.java
index f70e5b4892d..77f0c8ec0f9 100644
--- a/common/source/java/ch/systemsx/cisd/common/logging/LogInitializer.java
+++ b/common/source/java/ch/systemsx/cisd/common/logging/LogInitializer.java
@@ -22,6 +22,8 @@ import java.net.URISyntaxException;
 import java.net.URL;
 
 import org.apache.log4j.BasicConfigurator;
+import org.apache.log4j.Level;
+import org.apache.log4j.Logger;
 import org.apache.log4j.helpers.LogLog;
 import org.apache.log4j.xml.DOMConfigurator;
 
@@ -97,8 +99,8 @@ public class LogInitializer
         // For non-XML files, you will use
         // <code>PropertyConfigurator.configureAndWatch(String)</code>
         DOMConfigurator.configureAndWatch(logFile.getPath());
-        LogLog.debug(String.format("Log configured from file '%s' (watching).", logFile
-                .getAbsolutePath()));
+        LogLog.debug(String.format("Log configured from file '%s' (watching).",
+                logFile.getAbsolutePath()));
     }
 
     private final static void configureFromURL(final URL url)
@@ -140,6 +142,36 @@ public class LogInitializer
      * </p>
      */
     public final static synchronized void init()
+    {
+        init(false);
+    }
+
+    /**
+     * Initializes logging system for log level DEBUG. Does nothing if already initialized.
+     * <p>
+     * Logging configuration file is assumed to be in
+     * <code>&lt;working directory&gt;/etc/log.xml</code>. If not found we look for a classpath
+     * resource named <code>/etc/log.xml</code>.<br>
+     * If nothing found in both locations <code>org.apache.log4j.BaseConfigurator.configure()</code>
+     * is used.
+     * </p>
+     */
+    public final static synchronized void initDebug()
+    {
+        init(true);
+    }
+
+    /**
+     * Initializes logging system. Does nothing if already initialized.
+     * <p>
+     * Logging configuration file is assumed to be in
+     * <code>&lt;working directory&gt;/etc/log.xml</code>. If not found we look for a classpath
+     * resource named <code>/etc/log.xml</code>.<br>
+     * If nothing found in both locations <code>org.apache.log4j.BaseConfigurator.configure()</code>
+     * is used.
+     * </p>
+     */
+    private final static synchronized void init(boolean debug)
     {
         if (initialized)
         {
@@ -152,6 +184,7 @@ public class LogInitializer
             if (logFile.exists())
             {
                 configureFromFile(logFile);
+                Logger.getRootLogger().setLevel(Level.DEBUG);
                 finishInit();
                 return;
             }
@@ -162,11 +195,13 @@ public class LogInitializer
             if (url != null)
             {
                 configureFromURL(url);
+                Logger.getRootLogger().setLevel(Level.DEBUG);
                 finishInit();
                 return;
             }
         }
         BasicConfigurator.configure();
+        Logger.getRootLogger().setLevel(Level.DEBUG);
         finishInit();
     }
 }
-- 
GitLab