1 package net.sf.openrocket.logging;
3 import java.util.Locale;
6 * The logging level. The natural order of the LogLevel orders the levels
7 * from highest priority to lowest priority. Comparisons of the relative levels
8 * should be performed using the methods {@link #atLeast(LogLevel)},
9 * {@link #moreThan(LogLevel)} and {@link #compareTo(LogLevel)}.
11 * A description of the level can be obtained using {@link #toString()}.
13 * @author Sampo Niskanen <sampo.niskanen@iki.fi>
15 public enum LogLevel {
17 * Level for indicating a bug or error condition noticed in the software or JRE.
18 * No ERROR level events _should_ occur while running the program.
23 * Level for indicating error conditions or atypical events that can occur during
24 * normal operation (errors while loading files, weird computation results etc).
29 * Level for logging user actions (adding and modifying components, running
30 * simulations etc). A user action should be logged as soon as possible on this
31 * level. The level is separate so that additional INFO messages won't purge
32 * user actions from a bounded log buffer.
37 * Level for indicating general level actions the software is performing and
38 * other notable events during execution (dialogs shown, simulations run etc).
43 * Level for indicating mid-results, outcomes of methods and other debugging
44 * information. The data logged should be of value when analyzing error
45 * conditions and what has caused them. Places that are called repeatedly
46 * during e.g. flight simulation should use the VBOSE level instead.
51 * Level of verbose debug logging to be used in areas which are called repeatedly,
52 * such as computational methods used in simulations. This level is separated to
53 * allow filtering out the verbose logs generated during simulations, DnD etc.
54 * from the normal debug logs.
58 /** The log level with highest priority */
59 public static final LogLevel HIGHEST;
60 /** The log level with lowest priority */
61 public static final LogLevel LOWEST;
62 /** The maximum length of a level textual description */
63 public static final int LENGTH;
67 for (LogLevel l : LogLevel.values()) {
68 length = Math.max(length, l.toString().length());
72 LogLevel[] values = LogLevel.values();
74 LOWEST = values[values.length - 1];
78 * Return true if this log level is of a priority at least that of
81 public boolean atLeast(LogLevel level) {
82 return this.compareTo(level) <= 0;
86 * Return true if this log level is of a priority greater than that of
89 public boolean moreThan(LogLevel level) {
90 return this.compareTo(level) < 0;
95 * Return a log level corresponding to a string. The string is case-insensitive. If the
96 * string is case-insensitively equal to "all", then the lowest logging level is returned.
98 * @param value the string name of a log level, or "all"
99 * @param defaultLevel the value to return if the string doesn't correspond to any log level or is null
100 * @return the corresponding log level, of defaultLevel.
102 public static LogLevel fromString(String value, LogLevel defaultLevel) {
104 // Normalize the string
108 value = value.toUpperCase(Locale.ENGLISH).trim();
110 // Find the correct level
111 LogLevel level = defaultLevel;
112 if (value.equals("ALL")) {
113 LogLevel[] values = LogLevel.values();
114 level = values[values.length - 1];
117 level = LogLevel.valueOf(value);
118 } catch (Exception e) {