forked from BruceEckel/OnJava8-Examples
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathLoggingLevelManipulation.java
More file actions
185 lines (184 loc) · 5.68 KB
/
LoggingLevelManipulation.java
File metadata and controls
185 lines (184 loc) · 5.68 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
// logging/LoggingLevelManipulation.java
// (c)2016 MindView LLC: see Copyright.txt
// We make no guarantees that this code is fit for any purpose.
// Visit http://mindviewinc.com/Books/OnJava/ for more book information.
// {ErrorOutputExpected}
import java.util.logging.Level;
import java.util.logging.Logger;
public class LoggingLevelManipulation {
private static Logger
lgr = Logger.getLogger("com"),
lgr2 = Logger.getLogger("com.mindviewinc"),
util= Logger.getLogger("onjava"),
test= Logger.getLogger("com.mindviewinc.test"),
rand = Logger.getLogger("random");
static void printLogMessages(Logger logger) {
logger.finest(logger.getName() + " Finest");
logger.finer(logger.getName() + " Finer");
logger.fine(logger.getName() + " Fine");
logger.config(logger.getName() + " Config");
logger.info(logger.getName() + " Info");
logger.warning(logger.getName()+" Warning");
logger.severe(logger.getName() + " Severe");
}
static void logMessages() {
printLogMessages(lgr);
printLogMessages(lgr2);
printLogMessages(util);
printLogMessages(test);
printLogMessages(rand);
}
static void printLevels() {
System.out.println(" -- printing levels -- "
+ lgr.getName()
+ " : " + lgr.getLevel()
+ " " + lgr2.getName()
+ " : " + lgr2.getLevel()
+ " " + util.getName()
+ " : " + util.getLevel()
+ " " + test.getName()
+ " : " + test.getLevel()
+ " " + rand.getName()
+ " : " + rand.getLevel());
}
public static void main(String[] args) {
printLevels();
lgr.setLevel(Level.SEVERE);
printLevels();
System.out.println("net level: SEVERE");
logMessages();
util.setLevel(Level.FINEST);
test.setLevel(Level.FINEST);
rand.setLevel(Level.FINEST);
printLevels();
System.out.println(
"individual loggers set to FINEST");
logMessages();
lgr.setLevel(Level.FINEST);
printLevels();
System.out.println("net level: FINEST");
logMessages();
}
}
/* Output:
-- printing levels -- com : null com.mindviewinc : null
onjava : null com.mindviewinc.test : null random : null
-- printing levels -- com : SEVERE com.mindviewinc : null
onjava : null com.mindviewinc.test : null random : null
net level: SEVERE
-- printing levels -- com : SEVERE com.mindviewinc : null
onjava : FINEST com.mindviewinc.test : FINEST random :
FINEST
individual loggers set to FINEST
-- printing levels -- com : FINEST com.mindviewinc : null
onjava : FINEST com.mindviewinc.test : FINEST random :
FINEST
net level: FINEST
___[ Error Output ]___
Dec 15, 2015 9:58:43 PM LoggingLevelManipulation
printLogMessages
SEVERE: com Severe
Dec 15, 2015 9:58:43 PM LoggingLevelManipulation
printLogMessages
SEVERE: com.mindviewinc Severe
Dec 15, 2015 9:58:43 PM LoggingLevelManipulation
printLogMessages
INFO: onjava Info
Dec 15, 2015 9:58:43 PM LoggingLevelManipulation
printLogMessages
WARNING: onjava Warning
Dec 15, 2015 9:58:43 PM LoggingLevelManipulation
printLogMessages
SEVERE: onjava Severe
Dec 15, 2015 9:58:43 PM LoggingLevelManipulation
printLogMessages
SEVERE: com.mindviewinc.test Severe
Dec 15, 2015 9:58:43 PM LoggingLevelManipulation
printLogMessages
INFO: random Info
Dec 15, 2015 9:58:43 PM LoggingLevelManipulation
printLogMessages
WARNING: random Warning
Dec 15, 2015 9:58:43 PM LoggingLevelManipulation
printLogMessages
SEVERE: random Severe
Dec 15, 2015 9:58:43 PM LoggingLevelManipulation
printLogMessages
SEVERE: com Severe
Dec 15, 2015 9:58:43 PM LoggingLevelManipulation
printLogMessages
SEVERE: com.mindviewinc Severe
Dec 15, 2015 9:58:43 PM LoggingLevelManipulation
printLogMessages
INFO: onjava Info
Dec 15, 2015 9:58:43 PM LoggingLevelManipulation
printLogMessages
WARNING: onjava Warning
Dec 15, 2015 9:58:43 PM LoggingLevelManipulation
printLogMessages
SEVERE: onjava Severe
Dec 15, 2015 9:58:43 PM LoggingLevelManipulation
printLogMessages
INFO: com.mindviewinc.test Info
Dec 15, 2015 9:58:43 PM LoggingLevelManipulation
printLogMessages
WARNING: com.mindviewinc.test Warning
Dec 15, 2015 9:58:43 PM LoggingLevelManipulation
printLogMessages
SEVERE: com.mindviewinc.test Severe
Dec 15, 2015 9:58:43 PM LoggingLevelManipulation
printLogMessages
INFO: random Info
Dec 15, 2015 9:58:43 PM LoggingLevelManipulation
printLogMessages
WARNING: random Warning
Dec 15, 2015 9:58:43 PM LoggingLevelManipulation
printLogMessages
SEVERE: random Severe
Dec 15, 2015 9:58:43 PM LoggingLevelManipulation
printLogMessages
INFO: com Info
Dec 15, 2015 9:58:43 PM LoggingLevelManipulation
printLogMessages
WARNING: com Warning
Dec 15, 2015 9:58:43 PM LoggingLevelManipulation
printLogMessages
SEVERE: com Severe
Dec 15, 2015 9:58:43 PM LoggingLevelManipulation
printLogMessages
INFO: com.mindviewinc Info
Dec 15, 2015 9:58:43 PM LoggingLevelManipulation
printLogMessages
WARNING: com.mindviewinc Warning
Dec 15, 2015 9:58:43 PM LoggingLevelManipulation
printLogMessages
SEVERE: com.mindviewinc Severe
Dec 15, 2015 9:58:43 PM LoggingLevelManipulation
printLogMessages
INFO: onjava Info
Dec 15, 2015 9:58:43 PM LoggingLevelManipulation
printLogMessages
WARNING: onjava Warning
Dec 15, 2015 9:58:43 PM LoggingLevelManipulation
printLogMessages
SEVERE: onjava Severe
Dec 15, 2015 9:58:43 PM LoggingLevelManipulation
printLogMessages
INFO: com.mindviewinc.test Info
Dec 15, 2015 9:58:43 PM LoggingLevelManipulation
printLogMessages
WARNING: com.mindviewinc.test Warning
Dec 15, 2015 9:58:43 PM LoggingLevelManipulation
printLogMessages
SEVERE: com.mindviewinc.test Severe
Dec 15, 2015 9:58:43 PM LoggingLevelManipulation
printLogMessages
INFO: random Info
Dec 15, 2015 9:58:43 PM LoggingLevelManipulation
printLogMessages
WARNING: random Warning
Dec 15, 2015 9:58:43 PM LoggingLevelManipulation
printLogMessages
SEVERE: random Severe
___[ Error Output is Expected ]___
*/