[jbossws-commits] JBossWS SVN: r3599 - in branches/maeste_palin/integration/sunri/src/main: java/org/jboss/wsf/stack/sunri/log and 2 other directories.

jbossws-commits at lists.jboss.org jbossws-commits at lists.jboss.org
Fri Jun 15 10:36:18 EDT 2007


Author: maeste
Date: 2007-06-15 10:36:18 -0400 (Fri, 15 Jun 2007)
New Revision: 3599

Added:
   branches/maeste_palin/integration/sunri/src/main/java/org/jboss/wsf/stack/sunri/log/JBossLogHandler.java
   branches/maeste_palin/integration/sunri/src/main/java/org/jboss/wsf/stack/sunri/log/JDKLogRedirector.java
   branches/maeste_palin/integration/sunri/src/main/java/org/jboss/wsf/stack/sunri/log/NamespaceFilter.java
Removed:
   branches/maeste_palin/integration/sunri/src/main/java/org/jboss/wsf/spi/
Modified:
   branches/maeste_palin/integration/sunri/src/main/resources/jbossws-sunri42.sar/jbossws.beans/META-INF/jboss-beans.xml
   branches/maeste_palin/integration/sunri/src/main/resources/jbossws-sunri50.sar/META-INF/jbossws-beans.xml
Log:
moving JDKLogRedirect on integration/sunri source directory. Second and final step


Copied: branches/maeste_palin/integration/sunri/src/main/java/org/jboss/wsf/stack/sunri/log/JBossLogHandler.java (from rev 3598, branches/maeste_palin/integration/sunri/src/main/java/org/jboss/wsf/spi/utils/log/JBossLogHandler.java)
===================================================================
--- branches/maeste_palin/integration/sunri/src/main/java/org/jboss/wsf/stack/sunri/log/JBossLogHandler.java	                        (rev 0)
+++ branches/maeste_palin/integration/sunri/src/main/java/org/jboss/wsf/stack/sunri/log/JBossLogHandler.java	2007-06-15 14:36:18 UTC (rev 3599)
@@ -0,0 +1,116 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2005, JBoss Inc., and individual contributors as indicated
+ * by the @authors tag. See the copyright.txt 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.wsf.stack.sunri.log;
+
+import java.util.logging.ErrorManager;
+import java.util.logging.Handler;
+import java.util.logging.Level;
+import java.util.logging.LogRecord;
+import java.util.logging.SimpleFormatter;
+
+import org.jboss.logging.Logger;
+
+/**
+ * A Handler (java.util.logging.Handler) class redirecting messages
+ * to the jboss logging system.
+ * 
+ * @author Alessio Soldano, <alessio.soldano at javalinux.it>
+ * @author Stefano Maestri, <stefano.maestri at javalinux.it>
+ * @since 14-Jun-2007
+ *
+ */
+public class JBossLogHandler extends Handler
+{
+
+   public JBossLogHandler()
+   {
+      super.setFormatter(new SimpleFormatter());
+   }
+
+   @Override
+   public void publish(LogRecord record)
+   {
+      if (!isLoggable(record))
+      {
+         return;
+      }
+      String msg;
+      try
+      {
+         msg = getFormatter().formatMessage(record);
+      }
+      catch (Exception ex)
+      {
+         // We don't want to throw an exception here, but we
+         // report the exception to any registered ErrorManager.
+         reportError(null, ex, ErrorManager.FORMAT_FAILURE);
+         return;
+      }
+      if (record.getLevel() == Level.INFO)
+      {
+         Logger.getLogger(record.getSourceClassName()).info(msg);
+      }
+      else if (record.getLevel() == Level.SEVERE)
+      {
+         Logger.getLogger(record.getSourceClassName()).error(msg);
+      }
+      else if (record.getLevel() == Level.WARNING)
+      {
+         Logger.getLogger(record.getSourceClassName()).warn(msg);
+      }
+      else if (record.getLevel() == Level.FINE)
+      {
+         Logger.getLogger(record.getSourceClassName()).debug(msg);
+      }
+      else if (record.getLevel() == Level.FINER || record.getLevel() == Level.FINEST)
+      {
+         Logger.getLogger(record.getSourceClassName()).trace(msg);
+      }
+      else
+      {
+         Logger.getLogger(record.getSourceClassName()).debug(msg);
+      }
+   }
+
+   @Override
+   public boolean isLoggable(LogRecord record)
+   {
+      if (record == null)
+      {
+         return false;
+      }
+      return super.isLoggable(record);
+   }
+
+   @Override
+   public void flush()
+   {
+      //nothing to do
+   }
+
+   @Override
+   public void close() throws SecurityException
+   {
+      //nothing to do
+   }
+
+}
\ No newline at end of file

Copied: branches/maeste_palin/integration/sunri/src/main/java/org/jboss/wsf/stack/sunri/log/JDKLogRedirector.java (from rev 3598, branches/maeste_palin/integration/sunri/src/main/java/org/jboss/wsf/spi/utils/log/JDKLogRedirector.java)
===================================================================
--- branches/maeste_palin/integration/sunri/src/main/java/org/jboss/wsf/stack/sunri/log/JDKLogRedirector.java	                        (rev 0)
+++ branches/maeste_palin/integration/sunri/src/main/java/org/jboss/wsf/stack/sunri/log/JDKLogRedirector.java	2007-06-15 14:36:18 UTC (rev 3599)
@@ -0,0 +1,114 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2005, JBoss Inc., and individual contributors as indicated
+ * by the @authors tag. See the copyright.txt 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.wsf.stack.sunri.log;
+
+import java.util.LinkedList;
+import java.util.List;
+import java.util.logging.Filter;
+import java.util.logging.Handler;
+import java.util.logging.Level;
+
+import org.jboss.logging.Logger;
+
+/**
+ * Redirects JDK Logger output to the JBoss Logger.
+ * 
+ * @author Alessio Soldano, <alessio.soldano at javalinux.it>
+ * @author Stefano Maestri, <stefano.maestri at javalinux.it>
+ * @since 14-Jun-2007
+ *
+ */
+public class JDKLogRedirector
+{
+   private List<String> namespaces = new LinkedList<String>();
+   private static Logger myLogger = Logger.getLogger(JDKLogRedirector.class);
+
+   public JDKLogRedirector()
+   {
+   }
+
+   public void changeHandlers()
+   {
+      for (String ns : namespaces)
+      {
+         changeHandler(ns);
+      }
+   }
+
+   /**
+    * Modifies the jdk root logger in order not to log records coming from
+    * loggers with the provided namespace; these records are then logged
+    * through the JBoss Logger.
+    * 
+    * @param ns
+    */
+   public void changeHandler(String ns)
+   {
+      if (ns == null)
+         ns = "";
+      myLogger.debug("Changing current root logger's log handlers to hide records with namespace " + ns);
+      java.util.logging.Logger jdkRootLogger = java.util.logging.Logger.getLogger("");
+      Handler[] handlers = jdkRootLogger.getHandlers();
+      for (int i = 0; i < handlers.length; i++)
+      {
+         Handler handler = handlers[i];
+         if (!(handler instanceof JBossLogHandler))
+         {
+            StringBuffer sb = new StringBuffer("Disableing handler ");
+            sb.append(handler).append(" with level ").append(handler.getLevel());
+            myLogger.debug(sb);
+            Filter f = handler.getFilter();
+            if (f != null && f instanceof NamespaceFilter)
+            {
+               ((NamespaceFilter)f).addNamespace(ns);
+            }
+            else
+            {
+               NamespaceFilter nsFilter = new NamespaceFilter(false);
+               nsFilter.addNamespace(ns);
+               handler.setFilter(nsFilter);
+            }
+         }
+      }
+      myLogger.debug("Adding JBossLogHandler to log records with namespace " + ns);
+      Handler jbossLogHandler = new JBossLogHandler();
+      jbossLogHandler.setLevel(Level.ALL);
+      java.util.logging.Logger.getLogger(ns).addHandler(jbossLogHandler);
+   }
+
+   public void addNamespace(String ns)
+   {
+      namespaces.add(ns);
+      changeHandler(ns);
+   }
+
+   public List<String> getNamespaces()
+   {
+      return namespaces;
+   }
+
+   public void setNamespaces(List<String> namespaces)
+   {
+      this.namespaces = namespaces;
+      changeHandlers();
+   }
+}

Copied: branches/maeste_palin/integration/sunri/src/main/java/org/jboss/wsf/stack/sunri/log/NamespaceFilter.java (from rev 3598, branches/maeste_palin/integration/sunri/src/main/java/org/jboss/wsf/spi/utils/log/NamespaceFilter.java)
===================================================================
--- branches/maeste_palin/integration/sunri/src/main/java/org/jboss/wsf/stack/sunri/log/NamespaceFilter.java	                        (rev 0)
+++ branches/maeste_palin/integration/sunri/src/main/java/org/jboss/wsf/stack/sunri/log/NamespaceFilter.java	2007-06-15 14:36:18 UTC (rev 3599)
@@ -0,0 +1,96 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2005, JBoss Inc., and individual contributors as indicated
+ * by the @authors tag. See the copyright.txt 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.wsf.stack.sunri.log;
+
+import java.util.LinkedHashSet;
+import java.util.Set;
+import java.util.logging.Filter;
+import java.util.logging.LogRecord;
+
+/**
+ * A log filter allowing logging of LogRecord depending on the
+ * namespace of the Logger they have been collected by. 
+ * 
+ * @author Alessio Soldano, <alessio.soldano at javalinux.it>
+ * @author Stefano Maestri, <stefano.maestri at javalinux.it>
+ * @since 14-Jun-2007
+ *
+ */
+public class NamespaceFilter implements Filter
+{
+
+   private Set<String> namespaces;
+   private boolean show;
+
+   public NamespaceFilter(boolean show)
+   {
+      this.show = show;
+   }
+
+   public boolean isLoggable(LogRecord record)
+   {
+      String loggerName = record.getLoggerName();
+      if (loggerName == null)
+      {
+         return true;
+      }
+      else
+      {
+         for (String ns : namespaces)
+         {
+            if (loggerName.startsWith(ns))
+            {
+               return show;
+            }
+         }
+         return !show;
+      }
+   }
+
+   public void addNamespace(String ns)
+   {
+      if (namespaces == null)
+         namespaces = new LinkedHashSet<String>();
+      namespaces.add(ns);
+   }
+
+   public Set<String> getNamespaces()
+   {
+      return namespaces;
+   }
+
+   public void setNamespaces(Set<String> namespaces)
+   {
+      this.namespaces = namespaces;
+   }
+
+   public boolean isShow()
+   {
+      return show;
+   }
+
+   public void setShow(boolean show)
+   {
+      this.show = show;
+   }
+
+}

Modified: branches/maeste_palin/integration/sunri/src/main/resources/jbossws-sunri42.sar/jbossws.beans/META-INF/jboss-beans.xml
===================================================================
--- branches/maeste_palin/integration/sunri/src/main/resources/jbossws-sunri42.sar/jbossws.beans/META-INF/jboss-beans.xml	2007-06-15 14:32:43 UTC (rev 3598)
+++ branches/maeste_palin/integration/sunri/src/main/resources/jbossws-sunri42.sar/jbossws.beans/META-INF/jboss-beans.xml	2007-06-15 14:36:18 UTC (rev 3599)
@@ -214,7 +214,7 @@
     </property>
   </bean>
   
-  <bean name="JDKLogRedirector" class="org.jboss.wsf.spi.utils.log.JDKLogRedirector">
+  <bean name="JDKLogRedirector" class="org.jboss.wsf.stack.sunri.log.JDKLogRedirector">
     <property name="namespaces">
       <list class="java.util.LinkedList" elementClass="java.lang.String">
 	    <value>javax.enterprise.resource.webservices.jaxws</value>

Modified: branches/maeste_palin/integration/sunri/src/main/resources/jbossws-sunri50.sar/META-INF/jbossws-beans.xml
===================================================================
--- branches/maeste_palin/integration/sunri/src/main/resources/jbossws-sunri50.sar/META-INF/jbossws-beans.xml	2007-06-15 14:32:43 UTC (rev 3598)
+++ branches/maeste_palin/integration/sunri/src/main/resources/jbossws-sunri50.sar/META-INF/jbossws-beans.xml	2007-06-15 14:36:18 UTC (rev 3599)
@@ -245,7 +245,7 @@
     <depends>WebServiceMainDeployer</depends>
   </bean>
   
-  <bean name="JDKLogRedirector" class="org.jboss.wsf.spi.utils.log.JDKLogRedirector">
+  <bean name="JDKLogRedirector" class="org.jboss.wsf.stack.sunri.log.JDKLogRedirector">
     <property name="namespaces">
       <list class="java.util.LinkedList" elementClass="java.lang.String">
 	    <value>javax.enterprise.resource.webservices.jaxws</value>




More information about the jbossws-commits mailing list