geronimo-scm mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jdil...@apache.org
Subject cvs commit: incubator-geronimo/modules/common/src/java/org/apache/geronimo/common/log/log4j CachingLog4jLog.java Log4jLog.java NamedNDC.java NamedNDCConverter.java NamedNDCFilter.java PatternLayout.java PatternParser.java XLevel.java
Date Wed, 27 Aug 2003 10:08:45 GMT
jdillon     2003/08/27 03:08:45

  Added:       modules/common/src/java/org/apache/geronimo/common/log/log4j
                        CachingLog4jLog.java Log4jLog.java NamedNDC.java
                        NamedNDCConverter.java NamedNDCFilter.java
                        PatternLayout.java PatternParser.java XLevel.java
  Log:
   o Moving logging bits from core to common
  
  Revision  Changes    Path
  1.1                  incubator-geronimo/modules/common/src/java/org/apache/geronimo/common/log/log4j/CachingLog4jLog.java
  
  Index: CachingLog4jLog.java
  ===================================================================
  /* ====================================================================
   * The Apache Software License, Version 1.1
   *
   * Copyright (c) 2003 The Apache Software Foundation.  All rights
   * reserved.
   *
   * Redistribution and use in source and binary forms, with or without
   * modification, are permitted provided that the following conditions
   * are met:
   *
   * 1. Redistributions of source code must retain the above copyright
   *    notice, this list of conditions and the following disclaimer.
   *
   * 2. Redistributions in binary form must reproduce the above copyright
   *    notice, this list of conditions and the following disclaimer in
   *    the documentation and/or other materials provided with the
   *    distribution.
   *
   * 3. The end-user documentation included with the redistribution,
   *    if any, must include the following acknowledgment:
   *       "This product includes software developed by the
   *        Apache Software Foundation (http://www.apache.org/)."
   *    Alternately, this acknowledgment may appear in the software itself,
   *    if and wherever such third-party acknowledgments normally appear.
   *
   * 4. The names "Apache" and "Apache Software Foundation" and
   *    "Apache Geronimo" must not be used to endorse or promote products
   *    derived from this software without prior written permission. For
   *    written permission, please contact apache@apache.org.
   *
   * 5. Products derived from this software may not be called "Apache",
   *    "Apache Geronimo", nor may "Apache" appear in their name, without
   *    prior written permission of the Apache Software Foundation.
   *
   * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
   * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
   * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
   * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
   * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
   * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
   * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
   * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
   * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
   * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
   * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
   * SUCH DAMAGE.
   * ====================================================================
   *
   * This software consists of voluntary contributions made by many
   * individuals on behalf of the Apache Software Foundation.  For more
   * information on the Apache Software Foundation, please see
   * <http://www.apache.org/>.
   *
   * ====================================================================
   */
  package org.apache.geronimo.common.log.log4j;
  
  import java.lang.ref.WeakReference;
  import java.util.HashSet;
  import java.util.Iterator;
  import java.util.Set;
  import java.util.Timer;
  import java.util.TimerTask;
  
  import org.apache.log4j.Logger;
  import org.apache.log4j.Priority;
  
  import org.apache.commons.logging.Log;
  
  /**
   * This log wrapper caches the trace, debug and info enabled flags.  The flags are updated
   * by a single timer task for all logs.  The error, warn and fatal levels are always enabled.
   *
   * @version $Revision: 1.1 $ $Date: 2003/08/27 10:08:45 $
   */
  public final class CachingLog4jLog
      implements Log
  {
      // @todo this need to be moved to a log manager MBean, but this works as a proof of
concept
      private static final Set logs = new HashSet();
      private static final Timer timer = new Timer();
      private static final TimerTask task = new TimerTask() {
          public void run() {
              HashSet logSnapshot;
              synchronized (logs) {
                  logSnapshot = new HashSet(logs);
              }
  
              for (Iterator i = logSnapshot.iterator(); i.hasNext();) {
                  WeakReference weakReference = (WeakReference) i.next();
                  CachingLog4jLog log = (CachingLog4jLog) weakReference.get();
                  if (log == null) {
                      synchronized (logs) {
                          logs.remove(log);
                      }
                  } else {
                      log.updateLevelInfo();
                  }
              }
  
          }
      };
  
      static {
          timer.schedule(task, 3 * 60 * 1000, 3 * 60 * 1000);
      }
  
      private static void addLog(CachingLog4jLog log) {
          synchronized (logs) {
              logs.add(new WeakReference(log));
          }
      }
  
      private static final String FQCN = CachingLog4jLog.class.getName();
      private final Logger logger;
      private boolean traceEnabled;
      private boolean debugEnabled;
      private boolean infoEnabled;
  
      public CachingLog4jLog(String name) {
          logger = Logger.getLogger(name);
          updateLevelInfo();
          addLog(this);
      }
  
      public CachingLog4jLog(Logger logger) {
          this.logger = logger;
          updateLevelInfo();
          addLog(this);
      }
  
      public boolean isTraceEnabled() {
          return traceEnabled;
      }
  
      public void trace(Object message) {
          if (traceEnabled) {
              logger.log(FQCN, XLevel.TRACE, message, null);
          }
      }
  
      public void trace(Object message, Throwable throwable) {
          if (traceEnabled) {
              logger.log(FQCN, XLevel.TRACE, message, throwable);
          }
      }
  
      public boolean isDebugEnabled() {
          return debugEnabled;
      }
  
      public void debug(Object message) {
          if (debugEnabled) {
              logger.log(FQCN, Priority.DEBUG, message, null);
          }
      }
  
      public void debug(Object message, Throwable throwable) {
          if (debugEnabled) {
              logger.log(FQCN, Priority.DEBUG, message, throwable);
          }
      }
  
      public boolean isInfoEnabled() {
          return infoEnabled;
      }
  
      public void info(Object message) {
          if (infoEnabled) {
              logger.log(FQCN, Priority.INFO, message, null);
          }
      }
  
      public void info(Object message, Throwable throwable) {
          if (infoEnabled) {
              logger.log(FQCN, Priority.INFO, message, throwable);
          }
      }
  
      public boolean isWarnEnabled() {
          return true;
      }
  
      public void warn(Object message) {
          logger.log(FQCN, Priority.WARN, message, null);
      }
  
      public void warn(Object message, Throwable throwable) {
          logger.log(FQCN, Priority.WARN, message, throwable);
      }
  
      public boolean isErrorEnabled() {
          return true;
      }
  
      public void error(Object message) {
          logger.log(FQCN, Priority.ERROR, message, null);
      }
  
      public void error(Object message, Throwable throwable) {
          logger.log(FQCN, Priority.ERROR, message, throwable);
      }
  
      public boolean isFatalEnabled() {
          return true;
      }
  
      public void fatal(Object message) {
          logger.log(FQCN, Priority.FATAL, message, null);
      }
  
      public void fatal(Object message, Throwable throwable) {
          logger.log(FQCN, Priority.FATAL, message, throwable);
      }
  
      private void updateLevelInfo() {
          // This method is proposely not synchronized.
          // The setting of a boolean is atomic so we don't have to worry about inconsistent
state.
          // Normally we would have to worry about an out of date cache running threads (SMP
boxes),
          // but this cache is not time critical (so don't worry about it).
          traceEnabled = logger.isEnabledFor(XLevel.TRACE);
          debugEnabled = logger.isDebugEnabled();
          infoEnabled = logger.isInfoEnabled();
      }
  }
  
  
  
  1.1                  incubator-geronimo/modules/common/src/java/org/apache/geronimo/common/log/log4j/Log4jLog.java
  
  Index: Log4jLog.java
  ===================================================================
  /* ====================================================================
   * The Apache Software License, Version 1.1
   *
   * Copyright (c) 2003 The Apache Software Foundation.  All rights
   * reserved.
   *
   * Redistribution and use in source and binary forms, with or without
   * modification, are permitted provided that the following conditions
   * are met:
   *
   * 1. Redistributions of source code must retain the above copyright
   *    notice, this list of conditions and the following disclaimer.
   *
   * 2. Redistributions in binary form must reproduce the above copyright
   *    notice, this list of conditions and the following disclaimer in
   *    the documentation and/or other materials provided with the
   *    distribution.
   *
   * 3. The end-user documentation included with the redistribution,
   *    if any, must include the following acknowledgment:
   *       "This product includes software developed by the
   *        Apache Software Foundation (http://www.apache.org/)."
   *    Alternately, this acknowledgment may appear in the software itself,
   *    if and wherever such third-party acknowledgments normally appear.
   *
   * 4. The names "Apache" and "Apache Software Foundation" and
   *    "Apache Geronimo" must not be used to endorse or promote products
   *    derived from this software without prior written permission. For
   *    written permission, please contact apache@apache.org.
   *
   * 5. Products derived from this software may not be called "Apache",
   *    "Apache Geronimo", nor may "Apache" appear in their name, without
   *    prior written permission of the Apache Software Foundation.
   *
   * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
   * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
   * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
   * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
   * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
   * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
   * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
   * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
   * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
   * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
   * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
   * SUCH DAMAGE.
   * ====================================================================
   *
   * This software consists of voluntary contributions made by many
   * individuals on behalf of the Apache Software Foundation.  For more
   * information on the Apache Software Foundation, please see
   * <http://www.apache.org/>.
   *
   * ====================================================================
   */
  package org.apache.geronimo.common.log.log4j;
  
  import org.apache.commons.logging.Log;
  import org.apache.log4j.Logger;
  import org.apache.log4j.Priority;
  
  /**
   * A Commons <code>Log</code> implementation for Log4j which supports
   * real <em>trace</em> levels.
   *
   * @version $Revision: 1.1 $ $Date: 2003/08/27 10:08:45 $
   */
  public class Log4jLog
      implements Log
  {
      private String FQCN = getClass().getName();
      private Logger logger;
  
      public Log4jLog() {
      }
  
      public Log4jLog(String name) {
          logger = Logger.getLogger(name);
      }
  
      public Log4jLog(Logger logger) {
          this.logger = logger;
      }
  
      public boolean isTraceEnabled() {
          return logger.isEnabledFor(XLevel.TRACE);
      }
  
      public void trace(Object message) {
          logger.log(FQCN, XLevel.TRACE, message, null);
      }
  
      public void trace(Object message, Throwable throwable) {
          logger.log(FQCN, XLevel.TRACE, message, throwable);
      }
  
      public boolean isDebugEnabled() {
          return logger.isDebugEnabled();
      }
  
      public void debug(Object message) {
          logger.log(FQCN, Priority.DEBUG, message, null);
      }
  
      public void debug(Object message, Throwable throwable) {
          logger.log(FQCN, Priority.DEBUG, message, throwable);
      }
  
      public boolean isInfoEnabled() {
          return logger.isInfoEnabled();
      }
  
      public void info(Object message) {
          logger.log(FQCN, Priority.INFO, message, null);
      }
  
      public void info(Object message, Throwable throwable) {
          logger.log(FQCN, Priority.INFO, message, throwable);
      }
  
      public boolean isWarnEnabled() {
          return true;
      }
  
      public void warn(Object message) {
          logger.log(FQCN, Priority.WARN, message, null);
      }
  
      public void warn(Object message, Throwable throwable) {
          logger.log(FQCN, Priority.WARN, message, throwable);
      }
  
      public boolean isErrorEnabled() {
          return true;
      }
  
      public void error(Object message) {
          logger.log(FQCN, Priority.ERROR, message, null);
      }
  
      public void error(Object message, Throwable throwable) {
          logger.log(FQCN, Priority.ERROR, message, throwable);
      }
  
      public boolean isFatalEnabled() {
          return true;
      }
  
      public void fatal(Object message) {
          logger.log(FQCN, Priority.FATAL, message, null);
      }
  
      public void fatal(Object message, Throwable throwable) {
          logger.log(FQCN, Priority.FATAL, message, throwable);
      }
  }
  
  
  
  1.1                  incubator-geronimo/modules/common/src/java/org/apache/geronimo/common/log/log4j/NamedNDC.java
  
  Index: NamedNDC.java
  ===================================================================
  /* ====================================================================
   * The Apache Software License, Version 1.1
   *
   * Copyright (c) 2003 The Apache Software Foundation.  All rights
   * reserved.
   *
   * Redistribution and use in source and binary forms, with or without
   * modification, are permitted provided that the following conditions
   * are met:
   *
   * 1. Redistributions of source code must retain the above copyright
   *    notice, this list of conditions and the following disclaimer.
   *
   * 2. Redistributions in binary form must reproduce the above copyright
   *    notice, this list of conditions and the following disclaimer in
   *    the documentation and/or other materials provided with the
   *    distribution.
   *
   * 3. The end-user documentation included with the redistribution,
   *    if any, must include the following acknowledgment:
   *       "This product includes software developed by the
   *        Apache Software Foundation (http://www.apache.org/)."
   *    Alternately, this acknowledgment may appear in the software itself,
   *    if and wherever such third-party acknowledgments normally appear.
   *
   * 4. The names "Apache" and "Apache Software Foundation" and
   *    "Apache Geronimo" must not be used to endorse or promote products
   *    derived from this software without prior written permission. For
   *    written permission, please contact apache@apache.org.
   *
   * 5. Products derived from this software may not be called "Apache",
   *    "Apache Geronimo", nor may "Apache" appear in their name, without
   *    prior written permission of the Apache Software Foundation.
   *
   * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
   * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
   * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
   * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
   * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
   * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
   * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
   * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
   * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
   * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
   * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
   * SUCH DAMAGE.
   * ====================================================================
   *
   * This software consists of voluntary contributions made by many
   * individuals on behalf of the Apache Software Foundation.  For more
   * information on the Apache Software Foundation, please see
   * <http://www.apache.org/>.
   *
   * ====================================================================
   */
  package org.apache.geronimo.common.log.log4j;
  
  import java.util.HashMap;
  import java.util.LinkedList;
  import java.util.Map;
  
  /**
   * Provides named nested diagnotic contexts.
   *
   * @version $Revision: 1.1 $ $Date: 2003/08/27 10:08:45 $
   */
  public final class NamedNDC
  {
      /**
       * Mapping from names to NamedNDCs.
       * Currently there is no way to remove a NamedNCD once created, so be sure you really
       * want a new NDC before creating one.
       * @todo make this a weak-valued map
       */
      private static final Map contexts = new HashMap();
  
      /**
       * Gets the NamedNDC by name, or creates a new one of one does not already exist.
       * @param name the name of the desired NamedNDC
       * @return the existing NamedNDC or a new one
       */
      public static NamedNDC getNamedNDC(String name) {
          synchronized (contexts) {
              NamedNDC context = (NamedNDC) contexts.get(name);
              if (context == null) {
                  context = new NamedNDC();
                  contexts.put(name, context);
              }
              return context;
          }
      }
  
      private final ListThreadLocal listThreadLocal = new ListThreadLocal();
  
      private NamedNDC() {
      }
  
      public void push(Object value) {
          listThreadLocal.getList().addLast(value);
      }
  
      public Object get() {
          LinkedList list = listThreadLocal.getList();
          if (list.isEmpty()) {
              return null;
          }
          return list.getLast();
      }
  
      public Object pop() {
          LinkedList list = listThreadLocal.getList();
          if (list.isEmpty()) {
              return null;
          }
          return list.removeLast();
      }
  
      public void clear() {
          listThreadLocal.getList().clear();
      }
  
      private final static class ListThreadLocal extends ThreadLocal {
          public LinkedList getList() {
              return (LinkedList) get();
          }
  
          protected Object initialValue() {
              return new LinkedList();
          }
      }
  }
  
  
  
  1.1                  incubator-geronimo/modules/common/src/java/org/apache/geronimo/common/log/log4j/NamedNDCConverter.java
  
  Index: NamedNDCConverter.java
  ===================================================================
  /* ====================================================================
   * The Apache Software License, Version 1.1
   *
   * Copyright (c) 2003 The Apache Software Foundation.  All rights
   * reserved.
   *
   * Redistribution and use in source and binary forms, with or without
   * modification, are permitted provided that the following conditions
   * are met:
   *
   * 1. Redistributions of source code must retain the above copyright
   *    notice, this list of conditions and the following disclaimer.
   *
   * 2. Redistributions in binary form must reproduce the above copyright
   *    notice, this list of conditions and the following disclaimer in
   *    the documentation and/or other materials provided with the
   *    distribution.
   *
   * 3. The end-user documentation included with the redistribution,
   *    if any, must include the following acknowledgment:
   *       "This product includes software developed by the
   *        Apache Software Foundation (http://www.apache.org/)."
   *    Alternately, this acknowledgment may appear in the software itself,
   *    if and wherever such third-party acknowledgments normally appear.
   *
   * 4. The names "Apache" and "Apache Software Foundation" and
   *    "Apache Geronimo" must not be used to endorse or promote products
   *    derived from this software without prior written permission. For
   *    written permission, please contact apache@apache.org.
   *
   * 5. Products derived from this software may not be called "Apache",
   *    "Apache Geronimo", nor may "Apache" appear in their name, without
   *    prior written permission of the Apache Software Foundation.
   *
   * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
   * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
   * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
   * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
   * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
   * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
   * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
   * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
   * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
   * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
   * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
   * SUCH DAMAGE.
   * ====================================================================
   *
   * This software consists of voluntary contributions made by many
   * individuals on behalf of the Apache Software Foundation.  For more
   * information on the Apache Software Foundation, please see
   * <http://www.apache.org/>.
   *
   * ====================================================================
   */
  package org.apache.geronimo.common.log.log4j;
  
  import org.apache.log4j.helpers.FormattingInfo;
  import org.apache.log4j.helpers.PatternConverter;
  import org.apache.log4j.spi.LoggingEvent;
  
  import org.apache.commons.lang.exception.ExceptionUtils;
  
  /**
   *
   *
   * @version $Revision: 1.1 $ $Date: 2003/08/27 10:08:45 $
   */
  public final class NamedNDCConverter
      extends PatternConverter 
  {
      private final NamedNDC namedNDC;
  
      public NamedNDCConverter(FormattingInfo formattingInfo, String key) {
          super(formattingInfo);
          namedNDC = NamedNDC.getNamedNDC(key);
          assert namedNDC != null;
      }
  
      protected String convert(LoggingEvent loggingEvent) {
          try {
              Object value = namedNDC.get();
              if (value == null) {
                  return null;
              }
              return value.toString();
          } catch (Exception e) {
              return ExceptionUtils.getStackTrace(e);
          }
      }
  }
  
  
  
  1.1                  incubator-geronimo/modules/common/src/java/org/apache/geronimo/common/log/log4j/NamedNDCFilter.java
  
  Index: NamedNDCFilter.java
  ===================================================================
  /* ====================================================================
   * The Apache Software License, Version 1.1
   *
   * Copyright (c) 2003 The Apache Software Foundation.  All rights
   * reserved.
   *
   * Redistribution and use in source and binary forms, with or without
   * modification, are permitted provided that the following conditions
   * are met:
   *
   * 1. Redistributions of source code must retain the above copyright
   *    notice, this list of conditions and the following disclaimer.
   *
   * 2. Redistributions in binary form must reproduce the above copyright
   *    notice, this list of conditions and the following disclaimer in
   *    the documentation and/or other materials provided with the
   *    distribution.
   *
   * 3. The end-user documentation included with the redistribution,
   *    if any, must include the following acknowledgment:
   *       "This product includes software developed by the
   *        Apache Software Foundation (http://www.apache.org/)."
   *    Alternately, this acknowledgment may appear in the software itself,
   *    if and wherever such third-party acknowledgments normally appear.
   *
   * 4. The names "Apache" and "Apache Software Foundation" and
   *    "Apache Geronimo" must not be used to endorse or promote products
   *    derived from this software without prior written permission. For
   *    written permission, please contact apache@apache.org.
   *
   * 5. Products derived from this software may not be called "Apache",
   *    "Apache Geronimo", nor may "Apache" appear in their name, without
   *    prior written permission of the Apache Software Foundation.
   *
   * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
   * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
   * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
   * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
   * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
   * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
   * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
   * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
   * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
   * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
   * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
   * SUCH DAMAGE.
   * ====================================================================
   *
   * This software consists of voluntary contributions made by many
   * individuals on behalf of the Apache Software Foundation.  For more
   * information on the Apache Software Foundation, please see
   * <http://www.apache.org/>.
   *
   * ====================================================================
   */
  package org.apache.geronimo.common.log.log4j;
  
  import org.apache.log4j.spi.Filter;
  import org.apache.log4j.spi.LoggingEvent;
  
  /**
   *
   *
   * @version $Revision: 1.1 $ $Date: 2003/08/27 10:08:45 $
   */
  public class NamedNDCFilter extends Filter {
      private NamedNDC namedNDC;
      private String name;
      private String value;
      private boolean acceptOnMatch = true;
  
      public String getName() {
          return name;
      }
  
      public void setName(final String name) {
          this.name = name;
          namedNDC = NamedNDC.getNamedNDC(name);
      }
  
      public String getValue() {
          return value;
      }
  
      public void setValue(final String value) {
          this.value = value;
      }
  
      public boolean getAcceptOnMatch() {
          return acceptOnMatch;
      }
  
      public void setAcceptOnMatch(final boolean acceptOnMatch) {
          this.acceptOnMatch = acceptOnMatch;
      }
  
      public int decide(LoggingEvent event) {
          if (value == null) {
              return Filter.NEUTRAL;
          }
  
          Object ndcValue = namedNDC.get();
          if (ndcValue == null) {
              return Filter.NEUTRAL;
          }
  
          if (value.equals(ndcValue.toString())) {
              if (acceptOnMatch) {
                  return Filter.ACCEPT;
              } else {
                  return Filter.DENY;
              }
          }
          return Filter.NEUTRAL;
      }
  }
  
  
  
  1.1                  incubator-geronimo/modules/common/src/java/org/apache/geronimo/common/log/log4j/PatternLayout.java
  
  Index: PatternLayout.java
  ===================================================================
  /* ====================================================================
   * The Apache Software License, Version 1.1
   *
   * Copyright (c) 2003 The Apache Software Foundation.  All rights
   * reserved.
   *
   * Redistribution and use in source and binary forms, with or without
   * modification, are permitted provided that the following conditions
   * are met:
   *
   * 1. Redistributions of source code must retain the above copyright
   *    notice, this list of conditions and the following disclaimer.
   *
   * 2. Redistributions in binary form must reproduce the above copyright
   *    notice, this list of conditions and the following disclaimer in
   *    the documentation and/or other materials provided with the
   *    distribution.
   *
   * 3. The end-user documentation included with the redistribution,
   *    if any, must include the following acknowledgment:
   *       "This product includes software developed by the
   *        Apache Software Foundation (http://www.apache.org/)."
   *    Alternately, this acknowledgment may appear in the software itself,
   *    if and wherever such third-party acknowledgments normally appear.
   *
   * 4. The names "Apache" and "Apache Software Foundation" and
   *    "Apache Geronimo" must not be used to endorse or promote products
   *    derived from this software without prior written permission. For
   *    written permission, please contact apache@apache.org.
   *
   * 5. Products derived from this software may not be called "Apache",
   *    "Apache Geronimo", nor may "Apache" appear in their name, without
   *    prior written permission of the Apache Software Foundation.
   *
   * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
   * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
   * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
   * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
   * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
   * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
   * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
   * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
   * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
   * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
   * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
   * SUCH DAMAGE.
   * ====================================================================
   *
   * This software consists of voluntary contributions made by many
   * individuals on behalf of the Apache Software Foundation.  For more
   * information on the Apache Software Foundation, please see
   * <http://www.apache.org/>.
   *
   * ====================================================================
   */
  package org.apache.geronimo.common.log.log4j;
  
  
  /**
   * An extension to the standard log4j PatternLayout for printing a NamedNDC.
   *
   * @version $Revision: 1.1 $ $Date: 2003/08/27 10:08:45 $
   */
  public class PatternLayout
      extends org.apache.log4j.PatternLayout
  {
      protected org.apache.log4j.helpers.PatternParser createPatternParser(String pattern)
{
          return new PatternParser(pattern);
      }
  }
  
  
  
  1.1                  incubator-geronimo/modules/common/src/java/org/apache/geronimo/common/log/log4j/PatternParser.java
  
  Index: PatternParser.java
  ===================================================================
  /* ====================================================================
   * The Apache Software License, Version 1.1
   *
   * Copyright (c) 2003 The Apache Software Foundation.  All rights
   * reserved.
   *
   * Redistribution and use in source and binary forms, with or without
   * modification, are permitted provided that the following conditions
   * are met:
   *
   * 1. Redistributions of source code must retain the above copyright
   *    notice, this list of conditions and the following disclaimer.
   *
   * 2. Redistributions in binary form must reproduce the above copyright
   *    notice, this list of conditions and the following disclaimer in
   *    the documentation and/or other materials provided with the
   *    distribution.
   *
   * 3. The end-user documentation included with the redistribution,
   *    if any, must include the following acknowledgment:
   *       "This product includes software developed by the
   *        Apache Software Foundation (http://www.apache.org/)."
   *    Alternately, this acknowledgment may appear in the software itself,
   *    if and wherever such third-party acknowledgments normally appear.
   *
   * 4. The names "Apache" and "Apache Software Foundation" and
   *    "Apache Geronimo" must not be used to endorse or promote products
   *    derived from this software without prior written permission. For
   *    written permission, please contact apache@apache.org.
   *
   * 5. Products derived from this software may not be called "Apache",
   *    "Apache Geronimo", nor may "Apache" appear in their name, without
   *    prior written permission of the Apache Software Foundation.
   *
   * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
   * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
   * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
   * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
   * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
   * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
   * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
   * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
   * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
   * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
   * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
   * SUCH DAMAGE.
   * ====================================================================
   *
   * This software consists of voluntary contributions made by many
   * individuals on behalf of the Apache Software Foundation.  For more
   * information on the Apache Software Foundation, please see
   * <http://www.apache.org/>.
   *
   * ====================================================================
   */
  package org.apache.geronimo.common.log.log4j;
  
  import org.apache.log4j.helpers.PatternConverter;
  
  /**
   * A simple extension of the log4j pattern parser which adds support for the
   * 'a' letter for a NamedNDC.
   *
   * @version $Revision: 1.1 $ $Date: 2003/08/27 10:08:45 $
   */
  public class PatternParser
      extends org.apache.log4j.helpers.PatternParser
  {
      public PatternParser(String pattern) {
          super(pattern);
      }
  
      protected void finalizeConverter(char c) {
          PatternConverter pc = null;
          switch (c) {
          case 'a':
              String key = extractOption();
              pc = new NamedNDCConverter(formattingInfo, key);
              currentLiteral.setLength(0);
              break;
          default:
              super.finalizeConverter(c);
              return;
          }
          addConverter(pc);
      }
  }
  
  
  
  1.1                  incubator-geronimo/modules/common/src/java/org/apache/geronimo/common/log/log4j/XLevel.java
  
  Index: XLevel.java
  ===================================================================
  /* ====================================================================
   * The Apache Software License, Version 1.1
   *
   * Copyright (c) 2003 The Apache Software Foundation.  All rights
   * reserved.
   *
   * Redistribution and use in source and binary forms, with or without
   * modification, are permitted provided that the following conditions
   * are met:
   *
   * 1. Redistributions of source code must retain the above copyright
   *    notice, this list of conditions and the following disclaimer.
   *
   * 2. Redistributions in binary form must reproduce the above copyright
   *    notice, this list of conditions and the following disclaimer in
   *    the documentation and/or other materials provided with the
   *    distribution.
   *
   * 3. The end-user documentation included with the redistribution,
   *    if any, must include the following acknowledgment:
   *       "This product includes software developed by the
   *        Apache Software Foundation (http://www.apache.org/)."
   *    Alternately, this acknowledgment may appear in the software itself,
   *    if and wherever such third-party acknowledgments normally appear.
   *
   * 4. The names "Apache" and "Apache Software Foundation" and
   *    "Apache Geronimo" must not be used to endorse or promote products
   *    derived from this software without prior written permission. For
   *    written permission, please contact apache@apache.org.
   *
   * 5. Products derived from this software may not be called "Apache",
   *    "Apache Geronimo", nor may "Apache" appear in their name, without
   *    prior written permission of the Apache Software Foundation.
   *
   * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
   * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
   * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
   * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
   * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
   * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
   * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
   * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
   * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
   * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
   * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
   * SUCH DAMAGE.
   * ====================================================================
   *
   * This software consists of voluntary contributions made by many
   * individuals on behalf of the Apache Software Foundation.  For more
   * information on the Apache Software Foundation, please see
   * <http://www.apache.org/>.
   *
   * ====================================================================
   */
  package org.apache.geronimo.common.log.log4j;
  
  import org.apache.log4j.Level;
  
  /**
   * Extention levels for Log4j
   *
   * @version $Revision: 1.1 $ $Date: 2003/08/27 10:08:45 $
   */
  public final class XLevel
      extends Level
  {
      public static final int TRACE_INT = Level.DEBUG_INT - 1;
      private static String TRACE_NAME = "TRACE";
  
      /**
       * The Log4j Level Object to use for trace level messages
       */
      public static final XLevel TRACE = new XLevel(TRACE_INT, TRACE_NAME, 7);
  
      protected XLevel(int level, String name, int syslogEquiv) {
          super(level, name, syslogEquiv);
      }
  
      /**
       * Convert the String argument to a level. If the conversion
       * fails then this method returns {@link #TRACE}.
       */
      public static Level toLevel(String name) {
          return toLevel(name, XLevel.TRACE);
      }
  
      /**
       * Convert the String argument to a level. If the conversion
       * fails, return the level specified by the second argument,
       * i.e. defaultValue.
       */
      public static Level toLevel(String name, Level defaultValue) {
          if (name == null) {
              return defaultValue;
          }
          if (name.toUpperCase().equals(TRACE_NAME)) {
              return XLevel.TRACE;
          }
          return Level.toLevel(name, defaultValue);
      }
  
      /**
       * Convert an integer passed as argument to a level. If the
       * conversion fails, then this method returns {@link #DEBUG}.
       */
      public static Level toLevel(int level) throws IllegalArgumentException {
          if (level == TRACE_INT) {
              return XLevel.TRACE;
          } else {
              return Level.toLevel(level);
          }
      }
  }
  
  
  

Mime
View raw message