Return-Path: X-Original-To: apmail-cxf-commits-archive@www.apache.org Delivered-To: apmail-cxf-commits-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 9414892DB for ; Tue, 20 Mar 2012 18:37:11 +0000 (UTC) Received: (qmail 21927 invoked by uid 500); 20 Mar 2012 18:37:11 -0000 Delivered-To: apmail-cxf-commits-archive@cxf.apache.org Received: (qmail 21888 invoked by uid 500); 20 Mar 2012 18:37:11 -0000 Mailing-List: contact commits-help@cxf.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@cxf.apache.org Delivered-To: mailing list commits@cxf.apache.org Received: (qmail 21852 invoked by uid 99); 20 Mar 2012 18:37:11 -0000 Received: from nike.apache.org (HELO nike.apache.org) (192.87.106.230) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 20 Mar 2012 18:37:11 +0000 X-ASF-Spam-Status: No, hits=-2000.0 required=5.0 tests=ALL_TRUSTED X-Spam-Check-By: apache.org Received: from [140.211.11.4] (HELO eris.apache.org) (140.211.11.4) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 20 Mar 2012 18:37:08 +0000 Received: from eris.apache.org (localhost [127.0.0.1]) by eris.apache.org (Postfix) with ESMTP id BE3AD238897A; Tue, 20 Mar 2012 18:36:46 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r1303075 - in /cxf/branches/2.4.x-fixes: ./ common/common/src/main/java/org/apache/cxf/common/logging/ Date: Tue, 20 Mar 2012 18:36:46 -0000 To: commits@cxf.apache.org From: dkulp@apache.org X-Mailer: svnmailer-1.0.8-patched Message-Id: <20120320183646.BE3AD238897A@eris.apache.org> X-Virus-Checked: Checked by ClamAV on apache.org Author: dkulp Date: Tue Mar 20 18:36:46 2012 New Revision: 1303075 URL: http://svn.apache.org/viewvc?rev=1303075&view=rev Log: Merged revisions 1302936 via svn merge from https://svn.apache.org/repos/asf/cxf/branches/2.5.x-fixes ........ r1302936 | dkulp | 2012-03-20 11:24:35 -0400 (Tue, 20 Mar 2012) | 10 lines Merged revisions 1302574 via git cherry-pick from https://svn.apache.org/repos/asf/cxf/trunk ........ r1302574 | dkulp | 2012-03-19 13:56:40 -0400 (Mon, 19 Mar 2012) | 3 lines [CXF-4180] Some work on the SLF4J loggers to help the performance a little bit and allow it to be used in more cases. ........ ........ Modified: cxf/branches/2.4.x-fixes/ (props changed) cxf/branches/2.4.x-fixes/common/common/src/main/java/org/apache/cxf/common/logging/AbstractDelegatingLogger.java cxf/branches/2.4.x-fixes/common/common/src/main/java/org/apache/cxf/common/logging/LogUtils.java cxf/branches/2.4.x-fixes/common/common/src/main/java/org/apache/cxf/common/logging/Slf4jLogger.java Propchange: cxf/branches/2.4.x-fixes/ ------------------------------------------------------------------------------ Binary property 'svnmerge-integrated' - no diff available. Modified: cxf/branches/2.4.x-fixes/common/common/src/main/java/org/apache/cxf/common/logging/AbstractDelegatingLogger.java URL: http://svn.apache.org/viewvc/cxf/branches/2.4.x-fixes/common/common/src/main/java/org/apache/cxf/common/logging/AbstractDelegatingLogger.java?rev=1303075&r1=1303074&r2=1303075&view=diff ============================================================================== --- cxf/branches/2.4.x-fixes/common/common/src/main/java/org/apache/cxf/common/logging/AbstractDelegatingLogger.java (original) +++ cxf/branches/2.4.x-fixes/common/common/src/main/java/org/apache/cxf/common/logging/AbstractDelegatingLogger.java Tue Mar 20 18:36:46 2012 @@ -277,23 +277,45 @@ public abstract class AbstractDelegating return level.intValue() >= l.intValue() && l != Level.OFF; } + protected boolean supportsHandlers() { + return false; + } + public synchronized void addHandler(Handler handler) throws SecurityException { + if (supportsHandlers()) { + super.addHandler(handler); + return; + } throw new UnsupportedOperationException(); } public synchronized void removeHandler(Handler handler) throws SecurityException { + if (supportsHandlers()) { + super.removeHandler(handler); + return; + } throw new UnsupportedOperationException(); } public synchronized Handler[] getHandlers() { + if (supportsHandlers()) { + return super.getHandlers(); + } throw new UnsupportedOperationException(); } public synchronized void setUseParentHandlers(boolean useParentHandlers) { + if (supportsHandlers()) { + super.setUseParentHandlers(useParentHandlers); + return; + } throw new UnsupportedOperationException(); } public synchronized boolean getUseParentHandlers() { + if (supportsHandlers()) { + return super.getUseParentHandlers(); + } throw new UnsupportedOperationException(); } Modified: cxf/branches/2.4.x-fixes/common/common/src/main/java/org/apache/cxf/common/logging/LogUtils.java URL: http://svn.apache.org/viewvc/cxf/branches/2.4.x-fixes/common/common/src/main/java/org/apache/cxf/common/logging/LogUtils.java?rev=1303075&r1=1303074&r2=1303075&view=diff ============================================================================== --- cxf/branches/2.4.x-fixes/common/common/src/main/java/org/apache/cxf/common/logging/LogUtils.java (original) +++ cxf/branches/2.4.x-fixes/common/common/src/main/java/org/apache/cxf/common/logging/LogUtils.java Tue Mar 20 18:36:46 2012 @@ -95,17 +95,34 @@ public final class LogUtils { } } if (StringUtils.isEmpty(cname)) { - Class.forName("org.slf4j.impl.StaticLoggerBinder"); - Class cls = Class.forName("org.slf4j.LoggerFactory"); - Class fcls = cls.getMethod("getILoggerFactory").invoke(null).getClass(); - if (fcls.getName().contains("Log4j")) { - cname = "org.apache.cxf.common.logging.Log4jLogger"; - } else if (fcls.getName().contains("JCL")) { - cls = Class.forName("org.apache.commons.logging.LogFactory"); - fcls = cls.getMethod("getFactory").invoke(null).getClass(); - if (fcls.getName().contains("Log4j")) { + try { + // This Class.forName likely will barf in OSGi, but it's OK + // as we'll just use j.u.l and pax-logging will pick it up fine + // If we don't call this and there isn't a slf4j impl avail, + // you get warnings printed to stderr about NOPLoggers and such + Class.forName("org.slf4j.impl.StaticLoggerBinder"); + Class cls = Class.forName("org.slf4j.LoggerFactory"); + Class fcls = cls.getMethod("getILoggerFactory").invoke(null).getClass(); + String clsName = fcls.getName(); + if (clsName.contains("NOPLogger")) { + //no real slf4j implementation, use j.u.l + cname = null; + } else if (clsName.contains("Log4j")) { cname = "org.apache.cxf.common.logging.Log4jLogger"; + } else if (clsName.contains("JCL")) { + cls = Class.forName("org.apache.commons.logging.LogFactory"); + fcls = cls.getMethod("getFactory").invoke(null).getClass(); + if (fcls.getName().contains("Log4j")) { + cname = "org.apache.cxf.common.logging.Log4jLogger"; + } + } else if (clsName.contains("JDK14") + || clsName.contains("pax.logging")) { + //both of these we can use the appropriate j.u.l API's + //directly and have it work properly + cname = null; } + } catch (Throwable t) { + //ignore - Slf4j not available } } if (!StringUtils.isEmpty(cname)) { Modified: cxf/branches/2.4.x-fixes/common/common/src/main/java/org/apache/cxf/common/logging/Slf4jLogger.java URL: http://svn.apache.org/viewvc/cxf/branches/2.4.x-fixes/common/common/src/main/java/org/apache/cxf/common/logging/Slf4jLogger.java?rev=1303075&r1=1303074&r2=1303075&view=diff ============================================================================== --- cxf/branches/2.4.x-fixes/common/common/src/main/java/org/apache/cxf/common/logging/Slf4jLogger.java (original) +++ cxf/branches/2.4.x-fixes/common/common/src/main/java/org/apache/cxf/common/logging/Slf4jLogger.java Tue Mar 20 18:36:46 2012 @@ -18,6 +18,7 @@ */ package org.apache.cxf.common.logging; +import java.util.logging.Handler; import java.util.logging.Level; import java.util.logging.LogRecord; @@ -52,6 +53,7 @@ public class Slf4jLogger extends Abstrac private final org.slf4j.Logger logger; private LocationAwareLogger locationAwareLogger; + public Slf4jLogger(String name, String resourceBundleName) { super(name, resourceBundleName); @@ -60,6 +62,10 @@ public class Slf4jLogger extends Abstrac locationAwareLogger = (LocationAwareLogger) logger; } } + @Override + protected boolean supportsHandlers() { + return true; + } @Override public Level getLevel() { @@ -83,11 +89,39 @@ public class Slf4jLogger extends Abstrac } @Override + public boolean isLoggable(Level level) { + final int i = level.intValue(); + if (i == Level.OFF.intValue()) { + return false; + } else if (i >= Level.SEVERE.intValue()) { + return logger.isErrorEnabled(); + } else if (i >= Level.WARNING.intValue()) { + return logger.isWarnEnabled(); + } else if (i >= Level.INFO.intValue()) { + return logger.isInfoEnabled(); + } else if (i >= Level.FINER.intValue()) { + return logger.isDebugEnabled(); + } + return logger.isTraceEnabled(); + } + + + @Override protected void internalLogFormatted(String msg, LogRecord record) { Level level = record.getLevel(); Throwable t = record.getThrown(); - + + Handler targets[] = getHandlers(); + if (targets != null) { + for (Handler h : targets) { + h.publish(record); + } + } + if (!getUseParentHandlers()) { + return; + } + /* * As we can not use a "switch ... case" block but only a "if ... else if ..." block, the order of the * comparisons is important. We first try log level FINE then INFO, WARN, FINER, etc