001 /**
002 * Licensed to the Apache Software Foundation (ASF) under one or more
003 * contributor license agreements. See the NOTICE file distributed with
004 * this work for additional information regarding copyright ownership.
005 * The ASF licenses this file to You under the Apache License, Version 2.0
006 * (the "License"); you may not use this file except in compliance with
007 * the License. You may obtain a copy of the License at
008 *
009 * http://www.apache.org/licenses/LICENSE-2.0
010 *
011 * Unless required by applicable law or agreed to in writing, software
012 * distributed under the License is distributed on an "AS IS" BASIS,
013 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014 * See the License for the specific language governing permissions and
015 * limitations under the License.
016 */
017
018 package org.apache.geronimo.system.logging.log4j;
019
020 import org.apache.log4j.Level;
021
022 /**
023 * Extention levels for Log4j
024 *
025 * @version $Rev: 706640 $ $Date: 2008-10-21 14:44:05 +0000 (Tue, 21 Oct 2008) $
026 */
027 public final class XLevel extends Level {
028 public static final int TRACE_INT = Level.DEBUG_INT - 1;
029 private static String TRACE_NAME = "TRACE";
030
031 /**
032 * The Log4j Level Object to use for trace level messages
033 */
034 public static final XLevel TRACE = new XLevel(TRACE_INT, TRACE_NAME, 7);
035
036 protected XLevel(int level, String name, int syslogEquiv) {
037 super(level, name, syslogEquiv);
038 }
039
040 /**
041 * Convert the String argument to a level. If the conversion
042 * fails then this method returns {@link #TRACE}.
043 */
044 public static Level toLevel(String name) {
045 return toLevel(name, XLevel.TRACE);
046 }
047
048 /**
049 * Convert the String argument to a level. If the conversion
050 * fails, return the level specified by the second argument,
051 * i.e. defaultValue.
052 */
053 public static Level toLevel(String name, Level defaultValue) {
054 if (name == null) {
055 return defaultValue;
056 }
057 if (name.toUpperCase().equals(TRACE_NAME)) {
058 return XLevel.TRACE;
059 }
060 return Level.toLevel(name, defaultValue);
061 }
062
063 /**
064 * Convert an integer passed as argument to a level. If the
065 * conversion fails, then this method returns {@link #DEBUG}.
066 */
067 public static Level toLevel(int level) throws IllegalArgumentException {
068 if (level == TRACE_INT) {
069 return XLevel.TRACE;
070 } else {
071 return Level.toLevel(level);
072 }
073 }
074 }