Author: thomas.diesler(a)jboss.com
Date: 2007-12-20 09:42:37 -0500 (Thu, 20 Dec 2007)
New Revision: 5372
Added:
common/trunk/src/main/java/org/jboss/wsf/common/log/JDKLogHandler.java
common/trunk/src/main/java/org/jboss/wsf/common/log/JDKLogManager.java
common/trunk/src/main/java/org/jboss/wsf/common/log/JDKLogger.java
Removed:
common/trunk/src/main/java/org/jboss/wsf/common/log/JBossLogHandler.java
common/trunk/src/main/java/org/jboss/wsf/common/log/JBossLogManager.java
Modified:
common/trunk/src/main/java/org/jboss/wsf/common/log/JDKLogRedirector.java
Log:
Fix server side jdk logger tracing
Deleted: common/trunk/src/main/java/org/jboss/wsf/common/log/JBossLogHandler.java
===================================================================
--- common/trunk/src/main/java/org/jboss/wsf/common/log/JBossLogHandler.java 2007-12-20
13:59:15 UTC (rev 5371)
+++ common/trunk/src/main/java/org/jboss/wsf/common/log/JBossLogHandler.java 2007-12-20
14:42:37 UTC (rev 5372)
@@ -1,148 +0,0 @@
-/*
- * 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.common.log;
-
-// $Id$
-
-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(a)javalinux.it>
- * @author Stefano Maestri, <stefano.maestri(a)javalinux.it>
- * @author Thomas.Diesler(a)jboss.com
- * @since 14-Jun-2007
- */
-public class JBossLogHandler extends Handler
-{
- public JBossLogHandler()
- {
- super.setFormatter(new SimpleFormatter());
- }
-
- @Override
- public void publish(LogRecord record)
- {
- if (isLoggable(record))
- {
- Logger logger = getJBossLogger(record);
- Level level = record.getLevel();
- if (level == Level.FINER || level == Level.FINEST)
- {
- String msg = getMessage(record);
- logger.trace(msg);
- }
- else if (level == Level.FINE)
- {
- String msg = getMessage(record);
- logger.debug(msg);
- }
- else if (level == Level.INFO || level == Level.CONFIG)
- {
- String msg = getMessage(record);
- logger.info(msg);
- }
- else if (level == Level.WARNING)
- {
- String msg = getMessage(record);
- logger.warn(msg);
- }
- else if (level == Level.SEVERE)
- {
- String msg = getMessage(record);
- logger.error(msg);
- }
- else if (level == Level.OFF)
- {
- // do nothing
- }
- }
- }
-
- private Logger getJBossLogger(LogRecord record)
- {
- return Logger.getLogger(record.getLoggerName());
- }
-
- private String getMessage(LogRecord record)
- {
- String msg = null;
- 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("Cannot obtain message from log record", ex,
ErrorManager.FORMAT_FAILURE);
- }
- return msg;
- }
-
- @Override
- public boolean isLoggable(LogRecord record)
- {
- Logger logger = getJBossLogger(record);
- Level level = record.getLevel();
-
- boolean isLoggable = false;
- if (level == Level.FINER || level == Level.FINEST)
- {
- isLoggable = logger.isTraceEnabled();
- }
- else if (level == Level.FINE)
- {
- isLoggable = logger.isDebugEnabled();
- }
- else if (level == Level.INFO || level == Level.CONFIG)
- {
- isLoggable = logger.isInfoEnabled();
- }
- else if (level == Level.SEVERE || level == Level.WARNING)
- {
- isLoggable = true;
- }
- return isLoggable;
- }
-
- @Override
- public void flush()
- {
- //nothing to do
- }
-
- @Override
- public void close() throws SecurityException
- {
- //nothing to do
- }
-
-}
\ No newline at end of file
Deleted: common/trunk/src/main/java/org/jboss/wsf/common/log/JBossLogManager.java
===================================================================
--- common/trunk/src/main/java/org/jboss/wsf/common/log/JBossLogManager.java 2007-12-20
13:59:15 UTC (rev 5371)
+++ common/trunk/src/main/java/org/jboss/wsf/common/log/JBossLogManager.java 2007-12-20
14:42:37 UTC (rev 5372)
@@ -1,70 +0,0 @@
-/*
- * 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.common.log;
-
-// $Id$
-
-import java.util.logging.Level;
-import java.util.logging.LogManager;
-import java.util.logging.Logger;
-
-/**
- * A LogManager that adds a JBossLogHandler to every Logger
- *
- * @author Thomas.Diesler(a)jboss.com
- * @since 18-Dec-2007
- */
-public class JBossLogManager extends LogManager
-{
- @Override
- public synchronized Logger getLogger(String name)
- {
- Logger logger = super.getLogger(name);
- if (logger == null)
- logger = new JBossLogger(name);
-
- logger.addHandler(new JBossLogHandler());
- return logger;
- }
-
- static class JBossLogger extends Logger
- {
- protected JBossLogger(String name)
- {
- super(name, null);
-
- org.jboss.logging.Logger jbl = org.jboss.logging.Logger.getLogger(name);
- if (jbl.isTraceEnabled())
- {
- setLevel(Level.FINEST);
- }
- else if (jbl.isDebugEnabled())
- {
- setLevel(Level.FINE);
- }
- else if (jbl.isInfoEnabled())
- {
- setLevel(Level.INFO);
- }
- }
- }
-}
\ No newline at end of file
Copied: common/trunk/src/main/java/org/jboss/wsf/common/log/JDKLogHandler.java (from rev
5364, common/trunk/src/main/java/org/jboss/wsf/common/log/JBossLogHandler.java)
===================================================================
--- common/trunk/src/main/java/org/jboss/wsf/common/log/JDKLogHandler.java
(rev 0)
+++ common/trunk/src/main/java/org/jboss/wsf/common/log/JDKLogHandler.java 2007-12-20
14:42:37 UTC (rev 5372)
@@ -0,0 +1,148 @@
+/*
+ * 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.common.log;
+
+// $Id$
+
+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(a)javalinux.it>
+ * @author Stefano Maestri, <stefano.maestri(a)javalinux.it>
+ * @author Thomas.Diesler(a)jboss.com
+ * @since 14-Jun-2007
+ */
+public class JDKLogHandler extends Handler
+{
+ public JDKLogHandler()
+ {
+ super.setFormatter(new SimpleFormatter());
+ }
+
+ @Override
+ public void publish(LogRecord record)
+ {
+ if (isLoggable(record))
+ {
+ Logger logger = getJBossLogger(record);
+ Level level = record.getLevel();
+ if (level == Level.FINER || level == Level.FINEST)
+ {
+ String msg = getMessage(record);
+ logger.trace(msg);
+ }
+ else if (level == Level.FINE)
+ {
+ String msg = getMessage(record);
+ logger.debug(msg);
+ }
+ else if (level == Level.INFO || level == Level.CONFIG)
+ {
+ String msg = getMessage(record);
+ logger.info(msg);
+ }
+ else if (level == Level.WARNING)
+ {
+ String msg = getMessage(record);
+ logger.warn(msg);
+ }
+ else if (level == Level.SEVERE)
+ {
+ String msg = getMessage(record);
+ logger.error(msg);
+ }
+ else if (level == Level.OFF)
+ {
+ // do nothing
+ }
+ }
+ }
+
+ private Logger getJBossLogger(LogRecord record)
+ {
+ return Logger.getLogger(record.getLoggerName());
+ }
+
+ private String getMessage(LogRecord record)
+ {
+ String msg = null;
+ 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("Cannot obtain message from log record", ex,
ErrorManager.FORMAT_FAILURE);
+ }
+ return msg;
+ }
+
+ @Override
+ public boolean isLoggable(LogRecord record)
+ {
+ Logger logger = getJBossLogger(record);
+ Level level = record.getLevel();
+
+ boolean isLoggable = false;
+ if (level == Level.FINER || level == Level.FINEST)
+ {
+ isLoggable = logger.isTraceEnabled();
+ }
+ else if (level == Level.FINE)
+ {
+ isLoggable = logger.isDebugEnabled();
+ }
+ else if (level == Level.INFO || level == Level.CONFIG)
+ {
+ isLoggable = logger.isInfoEnabled();
+ }
+ else if (level == Level.SEVERE || level == Level.WARNING)
+ {
+ isLoggable = true;
+ }
+ return isLoggable;
+ }
+
+ @Override
+ public void flush()
+ {
+ //nothing to do
+ }
+
+ @Override
+ public void close() throws SecurityException
+ {
+ //nothing to do
+ }
+
+}
\ No newline at end of file
Copied: common/trunk/src/main/java/org/jboss/wsf/common/log/JDKLogManager.java (from rev
5364, common/trunk/src/main/java/org/jboss/wsf/common/log/JBossLogManager.java)
===================================================================
--- common/trunk/src/main/java/org/jboss/wsf/common/log/JDKLogManager.java
(rev 0)
+++ common/trunk/src/main/java/org/jboss/wsf/common/log/JDKLogManager.java 2007-12-20
14:42:37 UTC (rev 5372)
@@ -0,0 +1,47 @@
+/*
+ * 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.common.log;
+
+// $Id$
+
+import java.util.logging.LogManager;
+import java.util.logging.Logger;
+
+/**
+ * A LogManager that adds a JBossLogHandler to every Logger
+ *
+ * @author Thomas.Diesler(a)jboss.com
+ * @since 18-Dec-2007
+ */
+public class JDKLogManager extends LogManager
+{
+ @Override
+ public synchronized Logger getLogger(String name)
+ {
+ Logger logger = super.getLogger(name);
+ if (logger == null)
+ logger = new JDKLogger(name);
+
+ logger.addHandler(new JDKLogHandler());
+ return logger;
+ }
+}
\ No newline at end of file
Modified: common/trunk/src/main/java/org/jboss/wsf/common/log/JDKLogRedirector.java
===================================================================
--- common/trunk/src/main/java/org/jboss/wsf/common/log/JDKLogRedirector.java 2007-12-20
13:59:15 UTC (rev 5371)
+++ common/trunk/src/main/java/org/jboss/wsf/common/log/JDKLogRedirector.java 2007-12-20
14:42:37 UTC (rev 5372)
@@ -23,91 +23,68 @@
import java.util.LinkedList;
import java.util.List;
-import java.util.logging.Filter;
+import java.util.logging.ConsoleHandler;
import java.util.logging.Handler;
-import java.util.logging.Level;
+import java.util.logging.LogManager;
+import java.util.logging.Logger;
-import org.jboss.logging.Logger;
-import org.jboss.wsf.common.log.JBossLogHandler;
-
/**
* Redirects JDK Logger output to the JBoss Logger.
*
* @author Alessio Soldano, <alessio.soldano(a)javalinux.it>
* @author Stefano Maestri, <stefano.maestri(a)javalinux.it>
+ * @author Thomas.Diesler(a)jboss.com
* @since 14-Jun-2007
- *
*/
public class JDKLogRedirector
{
private List<String> namespaces = new LinkedList<String>();
- public JDKLogRedirector()
+ public void addNamespace(String ns)
{
+ namespaces.add(ns);
}
- public void changeHandlers()
+ public List<String> getNamespaces()
{
- for (String ns : namespaces)
- {
- changeHandler(ns);
- }
+ return namespaces;
}
- /**
- * 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)
+ public void setNamespaces(List<String> namespaces)
{
- 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);
+ this.namespaces = namespaces;
}
- public void addNamespace(String ns)
+ public void start()
{
- namespaces.add(ns);
- changeHandler(ns);
+ removeRootConsoleHandler();
+ addNamespaceHandlers();
}
- public List<String> getNamespaces()
+ private void removeRootConsoleHandler()
{
- return namespaces;
+ LogManager logManager = LogManager.getLogManager();
+ Logger root = logManager.getLogger("");
+ while (root.getParent() != null)
+ root = root.getParent();
+
+ Handler[] handlers = root.getHandlers();
+ for (int i = 0; i < handlers.length; i++)
+ {
+ Handler handler = handlers[i];
+ if (handler instanceof ConsoleHandler)
+ root.removeHandler(handler);
+ }
}
- public void setNamespaces(List<String> namespaces)
+ private void addNamespaceHandlers()
{
- this.namespaces = namespaces;
- changeHandlers();
+ LogManager logManager = LogManager.getLogManager();
+ for (String ns : namespaces)
+ {
+ JDKLogger log = new JDKLogger(ns);
+ log.addHandler(new JDKLogHandler());
+ logManager.addLogger(log);
+ }
}
}
Added: common/trunk/src/main/java/org/jboss/wsf/common/log/JDKLogger.java
===================================================================
--- common/trunk/src/main/java/org/jboss/wsf/common/log/JDKLogger.java
(rev 0)
+++ common/trunk/src/main/java/org/jboss/wsf/common/log/JDKLogger.java 2007-12-20 14:42:37
UTC (rev 5372)
@@ -0,0 +1,55 @@
+/*
+ * 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.common.log;
+
+// $Id$
+
+import java.util.logging.Level;
+import java.util.logging.Logger;
+
+/**
+ * A LogManager that adds a JBossLogHandler to every Logger
+ *
+ * @author Thomas.Diesler(a)jboss.com
+ * @since 18-Dec-2007
+ */
+public class JDKLogger extends Logger
+{
+ protected JDKLogger(String name)
+ {
+ super(name, null);
+
+ org.jboss.logging.Logger jbl = org.jboss.logging.Logger.getLogger(name);
+ if (jbl.isTraceEnabled())
+ {
+ setLevel(Level.FINEST);
+ }
+ else if (jbl.isDebugEnabled())
+ {
+ setLevel(Level.FINE);
+ }
+ else if (jbl.isInfoEnabled())
+ {
+ setLevel(Level.INFO);
+ }
+ }
+}
\ No newline at end of file
Property changes on: common/trunk/src/main/java/org/jboss/wsf/common/log/JDKLogger.java
___________________________________________________________________
Name: svn:keywords
+ Id Revision
Name: svn:eol-style
+ LF