2 * Licensed to the Apache Software Foundation (ASF) under one or more
3 * contributor license agreements. See the NOTICE file distributed with
4 * this work for additional information regarding copyright ownership.
5 * The ASF licenses this file to You under the Apache License, Version 2.0
6 * (the "License"); you may not use this file except in compliance with
7 * the License. You may obtain a copy of the License at
9 * http://www.apache.org/licenses/LICENSE-2.0
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
18 package org.apache.log4j.helpers;
20 import java.util.ArrayList;
21 import java.util.List;
23 import org.apache.log4j.Level;
26 * An extension of the Level class that provides support for java.util.logging
30 * @author Scott Deboy (sdeboy@apache.org)
33 public class UtilLoggingLevel extends Level {
36 * Serialization version id.
38 private static final long serialVersionUID = 909301162611820211L;
41 * Numerical value for SEVERE.
43 public static final int SEVERE_INT = 22000;
45 * Numerical value for WARNING.
47 public static final int WARNING_INT = 21000;
49 //INFO level defined in parent as 20000..no need to redefine here
52 * Numerical value for CONFIG.
54 public static final int CONFIG_INT = 14000;
56 * Numerical value for FINE.
58 public static final int FINE_INT = 13000;
60 * Numerical value for FINER.
62 public static final int FINER_INT = 12000;
64 * Numerical value for FINEST.
66 public static final int FINEST_INT = 11000;
68 * Numerical value for UNKNOWN.
70 public static final int UNKNOWN_INT = 10000;
75 public static final UtilLoggingLevel SEVERE =
76 new UtilLoggingLevel(SEVERE_INT, "SEVERE", 0);
80 public static final UtilLoggingLevel WARNING =
81 new UtilLoggingLevel(WARNING_INT, "WARNING", 4);
85 //note: we've aligned the int values of the java.util.logging INFO level with log4j's level
86 public static final UtilLoggingLevel INFO =
87 new UtilLoggingLevel(INFO_INT, "INFO", 5);
91 public static final UtilLoggingLevel CONFIG =
92 new UtilLoggingLevel(CONFIG_INT, "CONFIG", 6);
96 public static final UtilLoggingLevel FINE =
97 new UtilLoggingLevel(FINE_INT, "FINE", 7);
101 public static final UtilLoggingLevel FINER =
102 new UtilLoggingLevel(FINER_INT, "FINER", 8);
106 public static final UtilLoggingLevel FINEST =
107 new UtilLoggingLevel(FINEST_INT, "FINEST", 9);
110 * Create new instance.
111 * @param level numeric value for level.
112 * @param levelStr symbolic name for level.
113 * @param syslogEquivalent Equivalent syslog severity.
115 protected UtilLoggingLevel(final int level,
116 final String levelStr,
117 final int syslogEquivalent) {
118 super(level, levelStr, syslogEquivalent);
122 * Convert an integer passed as argument to a level. If the
123 * conversion fails, then this method returns the specified default.
124 * @param val numeric value.
125 * @param defaultLevel level to be returned if no level matches
127 * @return matching level or default level.
129 public static UtilLoggingLevel toLevel(final int val,
130 final UtilLoggingLevel defaultLevel) {
159 * Gets level matching numeric value.
160 * @param val numeric value.
161 * @return matching level or UtilLoggerLevel.FINEST if no match.
163 public static Level toLevel(final int val) {
164 return toLevel(val, FINEST);
168 * Gets list of supported levels.
169 * @return list of supported levels.
171 public static List getAllPossibleLevels() {
172 ArrayList list = new ArrayList();
184 * Get level with specified symbolic name.
185 * @param s symbolic name.
186 * @return matching level or Level.DEBUG if no match.
188 public static Level toLevel(final String s) {
189 return toLevel(s, Level.DEBUG);
194 * Get level with specified symbolic name.
195 * @param sArg symbolic name.
196 * @param defaultLevel level to return if no match.
197 * @return matching level or defaultLevel if no match.
199 public static Level toLevel(final String sArg,
200 final Level defaultLevel) {
205 String s = sArg.toUpperCase();
207 if (s.equals("SEVERE")) {
211 //if(s.equals("FINE")) return Level.FINE;
212 if (s.equals("WARNING")) {
216 if (s.equals("INFO")) {
220 if (s.equals("CONFI")) {
224 if (s.equals("FINE")) {
228 if (s.equals("FINER")) {
232 if (s.equals("FINEST")) {