fix log handler level
authorDavid ‘Bombe’ Roden <bombe@pterodactylus.net>
Fri, 9 May 2008 19:32:17 +0000 (19:32 +0000)
committerDavid ‘Bombe’ Roden <bombe@pterodactylus.net>
Fri, 9 May 2008 19:32:17 +0000 (19:32 +0000)
add method to create logger in the custom hierarchy

git-svn-id: http://trooper/svn/projects/jSite/trunk@802 c3eda9e8-030b-0410-8277-bc7414b0a119

src/net/pterodactylus/util/logging/Logging.java

index 443c05d..66ca181 100644 (file)
@@ -38,6 +38,13 @@ public class Logging {
        /** The log handler. */
        private static final LogHandler logHandler = new LogHandler();
 
+       static {
+               logHandler.setLevel(Level.ALL);
+       }
+
+       /** The root name of the hierarchy. */
+       private static String hierarchyRootName;
+
        /**
         * Adds a listener to the log handler.
         * 
@@ -60,12 +67,28 @@ public class Logging {
 
        /**
         * Sets up logging and installs the log handler.
+        * 
+        * @param hierarchyName
+        *            The name of the hierarchy root logger
         */
-       public static void setup() {
-               Logger rootLogger = Logger.getAnonymousLogger().getParent();
+       public static void setup(String hierarchyName) {
+               hierarchyRootName = hierarchyName;
+               Logger rootLogger = Logger.getLogger(hierarchyName);
                rootLogger.addHandler(logHandler);
+               rootLogger.setUseParentHandlers(false);
                rootLogger.setLevel(Level.ALL);
-               logHandler.setLevel(Level.INFO);
+       }
+
+       /**
+        * Returns a named logger from the jSite hierarchy.
+        * 
+        * @param name
+        *            The name of the logger
+        * @return The logger
+        */
+       public static Logger getLogger(String name) {
+               Logger logger = Logger.getLogger(hierarchyRootName + "." + name);
+               return logger;
        }
 
        /**
@@ -82,6 +105,7 @@ public class Logging {
                 * Package-private constructor.
                 */
                LogHandler() {
+                       /* do nothing. */
                }
 
                /** The list of the listeners. */
@@ -132,6 +156,7 @@ public class Logging {
                 */
                @Override
                public void close() throws SecurityException {
+                       /* do nothing. */
                }
 
                /**
@@ -139,6 +164,7 @@ public class Logging {
                 */
                @Override
                public void flush() {
+                       /* do nothing. */
                }
 
                /**