Clover icon

Coverage Report

  1. Project Clover database Thu Aug 13 2020 12:04:21 BST
  2. Package jalview.javascript.log4j

File Level.java

 

Coverage histogram

../../../img/srcFileCovDistChart0.png
56% of files have more coverage

Code metrics

24
57
8
1
271
135
28
0.49
7.12
8
3.5

Classes

Class Line # Actions
Level 20 57 28
0.00%
 

Contributing tests

No tests hitting this source file were found.

Source view

1    package jalview.javascript.log4j;
2   
3    import java.io.IOException;
4    import java.io.ObjectInputStream;
5    import java.io.ObjectOutputStream;
6    import java.io.ObjectStreamException;
7    import java.io.Serializable;
8   
9    /**
10    * Defines the minimum set of levels recognized by the system, that is
11    * <code>OFF</code>, <code>FATAL</code>, <code>ERROR</code>, <code>WARN</code>,
12    * <code>INFO</code>, <code>DEBUG</code> and <code>ALL</code>.
13    *
14    * <p>
15    * The <code>Level</code> class may be subclassed to define a larger level set.
16    * </p>
17    *
18    * @author Ceki G&uuml;lc&uuml;
19    */
 
20    public class Level extends Priority implements Serializable
21    {
22   
23    private static final String ALL_NAME = "ALL";
24   
25    private static final String TRACE_NAME = "TRACE";
26   
27    private static final String DEBUG_NAME = "DEBUG";
28   
29    private static final String INFO_NAME = "INFO";
30   
31    private static final String WARN_NAME = "WARN";
32   
33    private static final String ERROR_NAME = "ERROR";
34   
35    private static final String FATAL_NAME = "FATAL";
36   
37    private static final String OFF_NAME = "OFF";
38   
39    /**
40    * TRACE level integer value.
41    *
42    * @since 1.2.12
43    */
44    public static final int TRACE_INT = 5000;
45   
46    /**
47    * The <code>OFF</code> has the highest possible rank and is intended to turn
48    * off logging.
49    */
50    final static public Level OFF = new Level(OFF_INT, OFF_NAME, 0);
51   
52    /**
53    * The <code>FATAL</code> level designates very severe error events that will
54    * presumably lead the application to abort.
55    */
56    final static public Level FATAL = new Level(FATAL_INT, FATAL_NAME, 0);
57   
58    /**
59    * The <code>ERROR</code> level designates error events that might still allow
60    * the application to continue running.
61    */
62    final static public Level ERROR = new Level(ERROR_INT, ERROR_NAME, 3);
63   
64    /**
65    * The <code>WARN</code> level designates potentially harmful situations.
66    */
67    final static public Level WARN = new Level(WARN_INT, WARN_NAME, 4);
68   
69    /**
70    * The <code>INFO</code> level designates informational messages that
71    * highlight the progress of the application at coarse-grained level.
72    */
73    final static public Level INFO = new Level(INFO_INT, INFO_NAME, 6);
74   
75    /**
76    * The <code>DEBUG</code> Level designates fine-grained informational events
77    * that are most useful to debug an application.
78    */
79    final static public Level DEBUG = new Level(DEBUG_INT, DEBUG_NAME, 7);
80   
81    /**
82    * The <code>TRACE</code> Level designates finer-grained informational events
83    * than the <code>DEBUG</code level.
84    *
85    * @since 1.2.12
86    */
87    public static final Level TRACE = new Level(TRACE_INT, TRACE_NAME, 7);
88   
89    /**
90    * The <code>ALL</code> has the lowest possible rank and is intended to turn
91    * on all logging.
92    */
93    final static public Level ALL = new Level(ALL_INT, ALL_NAME, 7);
94   
95    /**
96    * Serialization version id.
97    */
98    static final long serialVersionUID = 3491141966387921974L;
99   
100    /**
101    * Instantiate a Level object.
102    */
 
103  0 toggle protected Level(int level, String levelStr, int syslogEquivalent)
104    {
105  0 super(level, levelStr, syslogEquivalent);
106    }
107   
108    /**
109    * Convert the string passed as argument to a level. If the conversion fails,
110    * then this method returns {@link #DEBUG}.
111    */
 
112  0 toggle public static Level toLevel(String sArg)
113    {
114  0 return toLevel(sArg, Level.DEBUG);
115    }
116   
117    /**
118    * Convert an integer passed as argument to a level. If the conversion fails,
119    * then this method returns {@link #DEBUG}.
120    */
 
121  0 toggle public static Level toLevel(int val)
122    {
123  0 return toLevel(val, Level.DEBUG);
124    }
125   
126    /**
127    * Convert an integer passed as argument to a level. If the conversion fails,
128    * then this method returns the specified default.
129    */
 
130  0 toggle public static Level toLevel(int val, Level defaultLevel)
131    {
132  0 switch (val)
133    {
134  0 case ALL_INT:
135  0 return ALL;
136  0 case DEBUG_INT:
137  0 return Level.DEBUG;
138  0 case INFO_INT:
139  0 return Level.INFO;
140  0 case WARN_INT:
141  0 return Level.WARN;
142  0 case ERROR_INT:
143  0 return Level.ERROR;
144  0 case FATAL_INT:
145  0 return Level.FATAL;
146  0 case OFF_INT:
147  0 return OFF;
148  0 case TRACE_INT:
149  0 return Level.TRACE;
150  0 default:
151  0 return defaultLevel;
152    }
153    }
154   
155    /**
156    * Convert the string passed as argument to a level. If the conversion fails,
157    * then this method returns the value of <code>defaultLevel</code>.
158    */
 
159  0 toggle public static Level toLevel(String sArg, Level defaultLevel)
160    {
161  0 if (sArg == null)
162    {
163  0 return defaultLevel;
164    }
165  0 String s = sArg.toUpperCase();
166   
167  0 if (s.equals(ALL_NAME))
168    {
169  0 return Level.ALL;
170    }
171  0 if (s.equals(DEBUG_NAME))
172    {
173  0 return Level.DEBUG;
174    }
175  0 if (s.equals(INFO_NAME))
176    {
177  0 return Level.INFO;
178    }
179  0 if (s.equals(WARN_NAME))
180    {
181  0 return Level.WARN;
182    }
183  0 if (s.equals(ERROR_NAME))
184    {
185  0 return Level.ERROR;
186    }
187  0 if (s.equals(FATAL_NAME))
188    {
189  0 return Level.FATAL;
190    }
191  0 if (s.equals(OFF_NAME))
192    {
193  0 return Level.OFF;
194    }
195  0 if (s.equals(TRACE_NAME))
196    {
197  0 return Level.TRACE;
198    }
199    //
200    // For Turkish i problem, see bug 40937
201    //
202  0 if (s.equals("\u0130NFO"))
203    {
204  0 return Level.INFO;
205    }
206  0 return defaultLevel;
207    }
208   
209    /**
210    * Custom deserialization of Level.
211    *
212    * @param s
213    * serialization stream.
214    * @throws IOException
215    * if IO exception.
216    * @throws ClassNotFoundException
217    * if class not found.
218    */
 
219  0 toggle private void readObject(final ObjectInputStream s)
220    throws IOException, ClassNotFoundException
221    {
222  0 s.defaultReadObject();
223  0 level = s.readInt();
224  0 syslogEquivalent = s.readInt();
225  0 levelStr = s.readUTF();
226  0 if (levelStr == null)
227    {
228  0 levelStr = "";
229    }
230    }
231   
232    /**
233    * Serialize level.
234    *
235    * @param s
236    * serialization stream.
237    * @throws IOException
238    * if exception during serialization.
239    */
 
240  0 toggle private void writeObject(final ObjectOutputStream s) throws IOException
241    {
242  0 s.defaultWriteObject();
243  0 s.writeInt(level);
244  0 s.writeInt(syslogEquivalent);
245  0 s.writeUTF(levelStr);
246    }
247   
248    /**
249    * Resolved deserialized level to one of the stock instances. May be overriden
250    * in classes derived from Level.
251    *
252    * @return resolved object.
253    * @throws ObjectStreamException
254    * if exception during resolution.
255    */
 
256  0 toggle private Object readResolve() throws ObjectStreamException
257    {
258    //
259    // if the deserizalized object is exactly an instance of Level
260    //
261  0 if (getClass() == Level.class)
262    {
263  0 return toLevel(level);
264    }
265    //
266    // extension of Level can't substitute stock item
267    //
268  0 return this;
269    }
270   
271    }