0
# Level Management
1
2
Level and priority system providing standard Log4j levels with conversion utilities and level comparison methods. The Level class extends Priority and provides the standard logging level hierarchy.
3
4
## Capabilities
5
6
### Standard Levels
7
8
Pre-defined level constants representing the standard Log4j logging hierarchy.
9
10
```java { .api }
11
/**
12
* Turn off all logging
13
*/
14
public static final Level OFF;
15
16
/**
17
* Very severe error events that will presumably lead the application to abort
18
*/
19
public static final Level FATAL;
20
21
/**
22
* Error events that might still allow the application to continue running
23
*/
24
public static final Level ERROR;
25
26
/**
27
* Potentially harmful situations
28
*/
29
public static final Level WARN;
30
31
/**
32
* Informational messages that highlight the progress of the application
33
*/
34
public static final Level INFO;
35
36
/**
37
* Fine-grained informational events for debugging
38
*/
39
public static final Level DEBUG;
40
41
/**
42
* Finer-grained informational events than DEBUG
43
*/
44
public static final Level TRACE;
45
46
/**
47
* Turn on all logging
48
*/
49
public static final Level ALL;
50
```
51
52
**Level Integer Constants:**
53
54
```java { .api }
55
// Level integer values for comparison
56
public static final int TRACE_INT = 5000;
57
public static final int X_TRACE_INT = DEBUG_INT - 100; // 9900 - Extended trace level
58
public static final int DEBUG_INT = 10000;
59
public static final int INFO_INT = 20000;
60
public static final int WARN_INT = 30000;
61
public static final int ERROR_INT = 40000;
62
public static final int FATAL_INT = 50000;
63
public static final int OFF_INT = Integer.MAX_VALUE;
64
public static final int ALL_INT = Integer.MIN_VALUE;
65
```
66
67
**Usage Examples:**
68
69
```java
70
import org.apache.log4j.Level;
71
72
// Use predefined levels
73
Level debugLevel = Level.DEBUG;
74
Level infoLevel = Level.INFO;
75
Level errorLevel = Level.ERROR;
76
77
// Compare levels
78
boolean isDebugHigher = Level.DEBUG.isGreaterOrEqual(Level.TRACE); // true
79
boolean isInfoLower = Level.INFO.isGreaterOrEqual(Level.ERROR); // false
80
```
81
82
### Level Conversion
83
84
Methods to convert strings and integers to Level instances with optional defaults.
85
86
```java { .api }
87
/**
88
* Convert string to level, defaults to DEBUG if conversion fails
89
* @param sArg String representation of level
90
* @return Corresponding Level
91
*/
92
public static Level toLevel(String sArg);
93
94
/**
95
* Convert string to level with custom default
96
* @param sArg String representation of level
97
* @param defaultLevel Default level if conversion fails
98
* @return Corresponding Level
99
*/
100
public static Level toLevel(String sArg, Level defaultLevel);
101
102
/**
103
* Convert integer to level, defaults to DEBUG if conversion fails
104
* @param val Integer representation of level
105
* @return Corresponding Level
106
*/
107
public static Level toLevel(int val);
108
109
/**
110
* Convert integer to level with custom default
111
* @param val Integer representation of level
112
* @param defaultLevel Default level if conversion fails
113
* @return Corresponding Level
114
*/
115
public static Level toLevel(int val, Level defaultLevel);
116
```
117
118
**Usage Examples:**
119
120
```java
121
// String conversion
122
Level level1 = Level.toLevel("INFO"); // Level.INFO
123
Level level2 = Level.toLevel("INVALID"); // Level.DEBUG (default)
124
Level level3 = Level.toLevel("INVALID", Level.WARN); // Level.WARN (custom default)
125
126
// Integer conversion
127
Level level4 = Level.toLevel(20000); // Level.INFO
128
Level level5 = Level.toLevel(99999); // Level.DEBUG (default)
129
Level level6 = Level.toLevel(99999, Level.ERROR); // Level.ERROR (custom default)
130
131
// Case insensitive
132
Level level7 = Level.toLevel("debug"); // Level.DEBUG
133
Level level8 = Level.toLevel("WaRn"); // Level.WARN
134
```
135
136
### Priority Base Class
137
138
Base Priority class providing core level functionality (deprecated, use Level instead).
139
140
```java { .api }
141
/**
142
* Priority class (deprecated - use Level instead)
143
*/
144
public class Priority {
145
/**
146
* Integer representation of priority level
147
*/
148
transient int level;
149
150
/**
151
* String representation of priority level
152
*/
153
transient String levelStr;
154
155
/**
156
* Syslog equivalent integer
157
*/
158
transient int syslogEquivalent;
159
160
/**
161
* Compare priorities for equality
162
* @param o Object to compare
163
* @return true if equal priority levels
164
*/
165
public boolean equals(Object o);
166
167
/**
168
* Check if this priority is greater than or equal to another
169
* @param r Priority to compare against
170
* @return true if this priority >= r
171
*/
172
public boolean isGreaterOrEqual(Priority r);
173
174
/**
175
* Get syslog equivalent value
176
* @return Syslog equivalent integer
177
*/
178
public final int getSyslogEquivalent();
179
180
/**
181
* Get integer representation
182
* @return Priority level as integer
183
*/
184
public final int toInt();
185
186
/**
187
* Get string representation
188
* @return Priority level as string
189
*/
190
public final String toString();
191
}
192
```
193
194
**Usage Examples:**
195
196
```java
197
// Priority comparison (though Level should be used instead)
198
Priority p1 = Level.INFO;
199
Priority p2 = Level.DEBUG;
200
201
boolean isGreater = p1.isGreaterOrEqual(p2); // true (INFO > DEBUG)
202
boolean areEqual = p1.equals(Level.INFO); // true
203
204
// Get representations
205
int intValue = p1.toInt(); // 20000
206
String stringValue = p1.toString(); // "INFO"
207
int syslogEquiv = p1.getSyslogEquivalent(); // 6
208
```
209
210
### Deprecated Priority Constants
211
212
Legacy Priority constants (deprecated - use Level equivalents instead).
213
214
```java { .api }
215
/**
216
* @deprecated Use Level.FATAL instead
217
*/
218
@Deprecated
219
public static final Priority FATAL;
220
221
/**
222
* @deprecated Use Level.ERROR instead
223
*/
224
@Deprecated
225
public static final Priority ERROR;
226
227
/**
228
* @deprecated Use Level.WARN instead
229
*/
230
@Deprecated
231
public static final Priority WARN;
232
233
/**
234
* @deprecated Use Level.INFO instead
235
*/
236
@Deprecated
237
public static final Priority INFO;
238
239
/**
240
* @deprecated Use Level.DEBUG instead
241
*/
242
@Deprecated
243
public static final Priority DEBUG;
244
```
245
246
### Deprecated Priority Conversion
247
248
Legacy Priority conversion methods (deprecated - use Level.toLevel() instead).
249
250
```java { .api }
251
/**
252
* @deprecated Use Level.toLevel(String) instead
253
* @param sArg String to convert
254
* @return Corresponding Priority
255
*/
256
@Deprecated
257
public static Priority toPriority(String sArg);
258
259
/**
260
* @deprecated Use Level.toLevel(int) instead
261
* @param val Integer to convert
262
* @return Corresponding Priority
263
*/
264
@Deprecated
265
public static Priority toPriority(int val);
266
267
/**
268
* @deprecated Use Level.toLevel(String, Level) instead
269
* @param sArg String to convert
270
* @param defaultPriority Default if conversion fails
271
* @return Corresponding Priority
272
*/
273
@Deprecated
274
public static Priority toPriority(String sArg, Priority defaultPriority);
275
276
/**
277
* @deprecated Use Level.toLevel(int, Level) instead
278
* @param val Integer to convert
279
* @param defaultPriority Default if conversion fails
280
* @return Corresponding Priority
281
*/
282
@Deprecated
283
public static Priority toPriority(int val, Priority defaultPriority);
284
285
/**
286
* Get all possible priorities as array (deprecated)
287
* @return Array of all Priority instances
288
* @deprecated This method will be removed with no replacement
289
*/
290
@Deprecated
291
public static Priority[] getAllPossiblePriorities();
292
```
293
294
**Migration Examples:**
295
296
```java
297
// Old (deprecated)
298
Priority oldLevel = Priority.toPriority("INFO");
299
300
// New (recommended)
301
Level newLevel = Level.toLevel("INFO");
302
303
// Old conversion with default
304
Priority oldDefault = Priority.toPriority("INVALID", Priority.WARN);
305
306
// New conversion with default
307
Level newDefault = Level.toLevel("INVALID", Level.WARN);
308
```