[jboss-svn-commits] JBoss Common SVN: r3221 - jboss-logmanager/trunk/src/main/java/org/jboss/logmanager/handlers.

jboss-svn-commits at lists.jboss.org jboss-svn-commits at lists.jboss.org
Thu Jun 4 17:26:43 EDT 2009


Author: david.lloyd at jboss.com
Date: 2009-06-04 17:26:43 -0400 (Thu, 04 Jun 2009)
New Revision: 3221

Added:
   jboss-logmanager/trunk/src/main/java/org/jboss/logmanager/handlers/Handlers.java
Modified:
   jboss-logmanager/trunk/src/main/java/org/jboss/logmanager/handlers/ExtHandler.java
Log:
More handler stuff

Modified: jboss-logmanager/trunk/src/main/java/org/jboss/logmanager/handlers/ExtHandler.java
===================================================================
--- jboss-logmanager/trunk/src/main/java/org/jboss/logmanager/handlers/ExtHandler.java	2009-06-04 16:12:31 UTC (rev 3220)
+++ jboss-logmanager/trunk/src/main/java/org/jboss/logmanager/handlers/ExtHandler.java	2009-06-04 21:26:43 UTC (rev 3221)
@@ -27,11 +27,13 @@
 import java.util.logging.Handler;
 import java.util.logging.LogRecord;
 
+import java.io.Flushable;
+
 /**
  * An extended logger handler.  Use this class as a base class for log handlers which require {@code ExtLogRecord}
  * instances.
  */
-public abstract class ExtHandler extends Handler {
+public abstract class ExtHandler extends Handler implements Flushable {
 
     private static final String LOGGER_CLASS_NAME = org.jboss.logmanager.Logger.class.getName();
 

Added: jboss-logmanager/trunk/src/main/java/org/jboss/logmanager/handlers/Handlers.java
===================================================================
--- jboss-logmanager/trunk/src/main/java/org/jboss/logmanager/handlers/Handlers.java	                        (rev 0)
+++ jboss-logmanager/trunk/src/main/java/org/jboss/logmanager/handlers/Handlers.java	2009-06-04 21:26:43 UTC (rev 3221)
@@ -0,0 +1,68 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2009, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+
+package org.jboss.logmanager.handlers;
+
+import java.io.Flushable;
+
+import java.util.logging.Handler;
+
+/**
+ * Handler utility methods.
+ */
+public final class Handlers {
+
+    private Handlers() {
+    }
+
+    /**
+     * Create a wrapper that exposes the handler's close and flush methods via the I/O API.
+     *
+     * @param handler the logging handler
+     * @return the wrapper
+     */
+    public static Flushable wrap(final Handler handler) {
+        return handler instanceof Flushable ? (Flushable) handler : new Flushable() {
+            public void close() {
+                handler.close();
+            }
+
+            public void flush() {
+                handler.flush();
+            }
+        };
+    }
+
+    /**
+     * Create a {@code Runnable} task that flushes a handler.
+     *
+     * @param handler the handler
+     * @return a flushing task
+     */
+    public static Runnable flusher(final Handler handler) {
+        return new Runnable() {
+            public void run() {
+                handler.flush();
+            }
+        };
+    }
+}




More information about the jboss-svn-commits mailing list