[jbossws-commits] JBossWS SVN: r3581 - in branches/maeste_palin/integration: spi/src/main/java/org/jboss/wsf/spi/utils/log and 2 other directories.
jbossws-commits at lists.jboss.org
jbossws-commits at lists.jboss.org
Thu Jun 14 08:50:57 EDT 2007
Author: palin
Date: 2007-06-14 08:50:56 -0400 (Thu, 14 Jun 2007)
New Revision: 3581
Added:
branches/maeste_palin/integration/spi/src/main/java/org/jboss/wsf/spi/utils/log/
branches/maeste_palin/integration/spi/src/main/java/org/jboss/wsf/spi/utils/log/JBossLogHandler.java
branches/maeste_palin/integration/spi/src/main/java/org/jboss/wsf/spi/utils/log/JDKLogRedirector.java
branches/maeste_palin/integration/spi/src/main/java/org/jboss/wsf/spi/utils/log/NamespaceFilter.java
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:
First implementation of JDKLogRedirector for JBWS-1675 JBWS-1678
Added: branches/maeste_palin/integration/spi/src/main/java/org/jboss/wsf/spi/utils/log/JBossLogHandler.java
===================================================================
--- branches/maeste_palin/integration/spi/src/main/java/org/jboss/wsf/spi/utils/log/JBossLogHandler.java (rev 0)
+++ branches/maeste_palin/integration/spi/src/main/java/org/jboss/wsf/spi/utils/log/JBossLogHandler.java 2007-06-14 12:50:56 UTC (rev 3581)
@@ -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.spi.utils.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
Added: branches/maeste_palin/integration/spi/src/main/java/org/jboss/wsf/spi/utils/log/JDKLogRedirector.java
===================================================================
--- branches/maeste_palin/integration/spi/src/main/java/org/jboss/wsf/spi/utils/log/JDKLogRedirector.java (rev 0)
+++ branches/maeste_palin/integration/spi/src/main/java/org/jboss/wsf/spi/utils/log/JDKLogRedirector.java 2007-06-14 12:50:56 UTC (rev 3581)
@@ -0,0 +1,112 @@
+/*
+ * 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.spi.utils.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>();
+
+ 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 = "";
+ Logger.getLogger(this.getClass()).info("Changing current root logger's log handlers to hide logs 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());
+ Logger.getLogger(this.getClass()).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);
+ }
+ }
+ }
+ 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();
+ }
+}
Added: branches/maeste_palin/integration/spi/src/main/java/org/jboss/wsf/spi/utils/log/NamespaceFilter.java
===================================================================
--- branches/maeste_palin/integration/spi/src/main/java/org/jboss/wsf/spi/utils/log/NamespaceFilter.java (rev 0)
+++ branches/maeste_palin/integration/spi/src/main/java/org/jboss/wsf/spi/utils/log/NamespaceFilter.java 2007-06-14 12:50:56 UTC (rev 3581)
@@ -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.spi.utils.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-14 12:48:59 UTC (rev 3580)
+++ branches/maeste_palin/integration/sunri/src/main/resources/jbossws-sunri42.sar/jbossws.beans/META-INF/jboss-beans.xml 2007-06-14 12:50:56 UTC (rev 3581)
@@ -213,5 +213,14 @@
</list>
</property>
</bean>
-
+
+ <bean name="JDKLogRedirector" class="org.jboss.wsf.spi.utils.log.JDKLogRedirector">
+ <property name="namespaces">
+ <list class="java.util.LinkedList" elementClass="java.lang.String">
+ <value>javax.enterprise.resource.webservices.jaxws</value>
+ <value>com.sun</value>
+ </list>
+ </property>
+ </bean>
+
</deployment>
\ No newline at end of file
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-14 12:48:59 UTC (rev 3580)
+++ branches/maeste_palin/integration/sunri/src/main/resources/jbossws-sunri50.sar/META-INF/jbossws-beans.xml 2007-06-14 12:50:56 UTC (rev 3581)
@@ -244,5 +244,14 @@
</uninstall>
<depends>WebServiceMainDeployer</depends>
</bean>
+
+ <bean name="JDKLogRedirector" class="org.jboss.wsf.spi.utils.log.JDKLogRedirector">
+ <property name="namespaces">
+ <list class="java.util.LinkedList" elementClass="java.lang.String">
+ <value>javax.enterprise.resource.webservices.jaxws</value>
+ <value>com.sun</value>
+ </list>
+ </property>
+ </bean>
</deployment>
More information about the jbossws-commits
mailing list