release 0.9.6
[debian/openrocket] / src / net / sf / openrocket / logging / LogLevel.java
1 package net.sf.openrocket.logging;
2
3 /**
4  * The logging level.  The natural order of the LogLevel orders the levels
5  * from highest priority to lowest priority.  Comparisons of the relative levels
6  * should be performed using the methods {@link #atLeast(LogLevel)},
7  * {@link #moreThan(LogLevel)} and {@link #compareTo(LogLevel)}.
8  * <p>
9  * A description of the level can be obtained using {@link #toString()}.
10  * 
11  * @author Sampo Niskanen <sampo.niskanen@iki.fi>
12  */
13 public enum LogLevel {
14         /**
15          * Level for indicating a bug or error condition noticed in the software or JRE.
16          * No ERROR level events _should_ occur while running the program. 
17          */
18         ERROR,
19         /** 
20          * Level for indicating error conditions or untypical events that can occur during
21          * normal operation (errors while loading files, weird computation results etc).
22          */
23         WARN,
24         /** 
25          * Level for logging user actions (adding and modifying components, running
26          * simulations etc).
27          */
28         USER,
29         /**
30          * Level for indicating general level actions the software is performing and
31          * other notable events during execution (dialogs shown, simulations run etc).
32          */
33         INFO,
34         /**
35          * Level for indicating mid-results and other debugging information.  No debug
36          * logging should be performed in performance-intensive places to avoid slowing
37          * the system.  On the other hand for example cached results should be logged.
38          */
39         DEBUG;
40
41         
42         /** The maximum length of a level textual description */
43         public static final int LENGTH;
44         static {
45                 int length = 0;
46                 for (LogLevel l: LogLevel.values()) {
47                         length = Math.max(length, l.toString().length());
48                 }
49                 LENGTH = length;
50         }
51         
52         /**
53          * Return true if this log level is of a priority at least that of
54          * <code>level</code>.
55          */
56         public boolean atLeast(LogLevel level) {
57                 return this.compareTo(level) <= 0;
58         }
59
60         /**
61          * Return true if this log level is of a priority greater than that of
62          * <code>level</code>.
63          */
64         public boolean moreThan(LogLevel level) {
65                 return this.compareTo(level) < 0;
66         }
67         
68 }