KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jboss > logging > XLevel


1 /*
2   * JBoss, Home of Professional Open Source
3   * Copyright 2005, JBoss Inc., and individual contributors as indicated
4   * by the @authors tag. See the copyright.txt in the distribution for a
5   * full listing of individual contributors.
6   *
7   * This is free software; you can redistribute it and/or modify it
8   * under the terms of the GNU Lesser General Public License as
9   * published by the Free Software Foundation; either version 2.1 of
10   * the License, or (at your option) any later version.
11   *
12   * This software is distributed in the hope that it will be useful,
13   * but WITHOUT ANY WARRANTY; without even the implied warranty of
14   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15   * Lesser General Public License for more details.
16   *
17   * You should have received a copy of the GNU Lesser General Public
18   * License along with this software; if not, write to the Free
19   * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
20   * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
21   */

22 package org.jboss.logging;
23
24 import org.apache.log4j.Level;
25
26 /**
27  * Provides custom extention levels for use with the Log4j logging framework.
28  *
29  * <p>
30  * Adds a trace level that is below the standard Log4j <tt>DEBUG</tt> level.
31  *
32  * <p>
33  * This is a custom level that is 100 below the {@link Level#DEBUG_INT}
34  * and represents a lower level useful for logging events that should only
35  * be displayed when deep debugging is required.
36  *
37  * @see org.apache.log4j.Level
38  *
39  * @author <a HREF="mailto:Scott.Stark@jboss.org">Scott Stark</a>
40  * @version $Revision: 1958 $
41  */

42 public class XLevel
43    extends Level
44 {
45    /** The integer representation of the level, ({@link Level#DEBUG_INT} - 100) */
46    public static final int TRACE_INT = Level.DEBUG_INT - 100;
47
48    /** The string name of the trace level. */
49    public static final String JavaDoc TRACE_STR = "TRACE";
50    
51    /** The TRACE level object singleton */
52    public static final XLevel TRACE = new XLevel(TRACE_INT, TRACE_STR, 7);
53
54    /**
55     * Construct a <tt>XLevel</tt>.
56     */

57    protected XLevel(final int level, final String JavaDoc strLevel, final int syslogEquiv)
58    {
59       super(level, strLevel, syslogEquiv);
60    }
61    
62
63    /////////////////////////////////////////////////////////////////////////
64
// Factory Methods //
65
/////////////////////////////////////////////////////////////////////////
66

67    /**
68     * Convert an integer passed as argument to a level. If the conversion
69     * fails, then this method returns the specified default.
70     *
71     * @return the Level object for name if one exists, defaultLevel otherwize.
72     */

73    public static Level toLevel(final String JavaDoc name, final Level defaultLevel)
74    {
75       if (name == null)
76          return defaultLevel;
77
78       String JavaDoc upper = name.toUpperCase();
79       if (upper.equals(TRACE_STR)) {
80          return TRACE;
81       }
82
83       return Level.toLevel(name, defaultLevel);
84    }
85
86    /**
87     * Convert an integer passed as argument to a level.
88     *
89     * @return the Level object for name if one exists
90     */

91    public static Level toLevel(final String JavaDoc name)
92    {
93       return toLevel(name, TRACE);
94    }
95    
96    /**
97     * Convert an integer passed as argument to a priority. If the conversion
98     * fails, then this method returns the specified default.
99     * @return the Level object for i if one exists, defaultLevel otherwize.
100     */

101    public static Level toLevel(int i)
102    {
103       return toLevel(i, TRACE);
104    }
105
106    /**
107     * Convert an integer passed as argument to a level. If the conversion
108     * fails, then this method returns the specified default.
109     *
110     * @return the Level object for i if one exists, defaultLevel otherwize.
111     */

112    public static Level toLevel(final int i, final Level defaultLevel)
113    {
114       Level p;
115       if (i == TRACE_INT)
116          p = TRACE;
117       else
118          p = Level.toLevel(i);
119       return p;
120    }
121 }
122
Popular Tags