author | dfuchs |
Thu, 06 Apr 2017 14:38:15 +0100 | |
changeset 44538 | a603c475d649 |
parent 37782 | ad8fe7507ecc |
permissions | -rw-r--r-- |
2 | 1 |
/* |
23010
6dadb192ad81
8029235: Update copyright year to match last edit in jdk8 jdk repository for 2013
lana
parents:
22110
diff
changeset
|
2 |
* Copyright (c) 2000, 2013, Oracle and/or its affiliates. All rights reserved. |
2 | 3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
4 |
* |
|
5 |
* This code is free software; you can redistribute it and/or modify it |
|
6 |
* under the terms of the GNU General Public License version 2 only, as |
|
5506 | 7 |
* published by the Free Software Foundation. Oracle designates this |
2 | 8 |
* particular file as subject to the "Classpath" exception as provided |
5506 | 9 |
* by Oracle in the LICENSE file that accompanied this code. |
2 | 10 |
* |
11 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
|
12 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
|
13 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
|
14 |
* version 2 for more details (a copy is included in the LICENSE file that |
|
15 |
* accompanied this code). |
|
16 |
* |
|
17 |
* You should have received a copy of the GNU General Public License version |
|
18 |
* 2 along with this work; if not, write to the Free Software Foundation, |
|
19 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
|
20 |
* |
|
5506 | 21 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
22 |
* or visit www.oracle.com if you need additional information or have any |
|
23 |
* questions. |
|
2 | 24 |
*/ |
25 |
||
26 |
package java.util.logging; |
|
27 |
||
28 |
/** |
|
32037
ab4526f4ac10
8133115: docs: replace <tt> tags (obsolete in html5) for java.util.logging, java.util.prefs, java.util.zip, java.util.jar
avstepan
parents:
25859
diff
changeset
|
29 |
* {@code Handler} that buffers requests in a circular buffer in memory. |
2 | 30 |
* <p> |
32037
ab4526f4ac10
8133115: docs: replace <tt> tags (obsolete in html5) for java.util.logging, java.util.prefs, java.util.zip, java.util.jar
avstepan
parents:
25859
diff
changeset
|
31 |
* Normally this {@code Handler} simply stores incoming {@code LogRecords} |
2 | 32 |
* into its memory buffer and discards earlier records. This buffering |
33 |
* is very cheap and avoids formatting costs. On certain trigger |
|
32037
ab4526f4ac10
8133115: docs: replace <tt> tags (obsolete in html5) for java.util.logging, java.util.prefs, java.util.zip, java.util.jar
avstepan
parents:
25859
diff
changeset
|
34 |
* conditions, the {@code MemoryHandler} will push out its current buffer |
ab4526f4ac10
8133115: docs: replace <tt> tags (obsolete in html5) for java.util.logging, java.util.prefs, java.util.zip, java.util.jar
avstepan
parents:
25859
diff
changeset
|
35 |
* contents to a target {@code Handler}, which will typically publish |
2 | 36 |
* them to the outside world. |
37 |
* <p> |
|
38 |
* There are three main models for triggering a push of the buffer: |
|
39 |
* <ul> |
|
40 |
* <li> |
|
32037
ab4526f4ac10
8133115: docs: replace <tt> tags (obsolete in html5) for java.util.logging, java.util.prefs, java.util.zip, java.util.jar
avstepan
parents:
25859
diff
changeset
|
41 |
* An incoming {@code LogRecord} has a type that is greater than |
ab4526f4ac10
8133115: docs: replace <tt> tags (obsolete in html5) for java.util.logging, java.util.prefs, java.util.zip, java.util.jar
avstepan
parents:
25859
diff
changeset
|
42 |
* a pre-defined level, the {@code pushLevel}. </li> |
2 | 43 |
* <li> |
32037
ab4526f4ac10
8133115: docs: replace <tt> tags (obsolete in html5) for java.util.logging, java.util.prefs, java.util.zip, java.util.jar
avstepan
parents:
25859
diff
changeset
|
44 |
* An external class calls the {@code push} method explicitly. </li> |
2 | 45 |
* <li> |
32037
ab4526f4ac10
8133115: docs: replace <tt> tags (obsolete in html5) for java.util.logging, java.util.prefs, java.util.zip, java.util.jar
avstepan
parents:
25859
diff
changeset
|
46 |
* A subclass overrides the {@code log} method and scans each incoming |
ab4526f4ac10
8133115: docs: replace <tt> tags (obsolete in html5) for java.util.logging, java.util.prefs, java.util.zip, java.util.jar
avstepan
parents:
25859
diff
changeset
|
47 |
* {@code LogRecord} and calls {@code push} if a record matches some |
14321
7f9f265ac11e
7159567: inconsistent configuration of MemoryHandler
jgish
parents:
5506
diff
changeset
|
48 |
* desired criteria. </li> |
2 | 49 |
* </ul> |
50 |
* <p> |
|
51 |
* <b>Configuration:</b> |
|
32037
ab4526f4ac10
8133115: docs: replace <tt> tags (obsolete in html5) for java.util.logging, java.util.prefs, java.util.zip, java.util.jar
avstepan
parents:
25859
diff
changeset
|
52 |
* By default each {@code MemoryHandler} is initialized using the following |
ab4526f4ac10
8133115: docs: replace <tt> tags (obsolete in html5) for java.util.logging, java.util.prefs, java.util.zip, java.util.jar
avstepan
parents:
25859
diff
changeset
|
53 |
* {@code LogManager} configuration properties where {@code <handler-name>} |
14321
7f9f265ac11e
7159567: inconsistent configuration of MemoryHandler
jgish
parents:
5506
diff
changeset
|
54 |
* refers to the fully-qualified class name of the handler. |
7f9f265ac11e
7159567: inconsistent configuration of MemoryHandler
jgish
parents:
5506
diff
changeset
|
55 |
* If properties are not defined |
2 | 56 |
* (or have invalid values) then the specified default values are used. |
57 |
* If no default value is defined then a RuntimeException is thrown. |
|
58 |
* <ul> |
|
14321
7f9f265ac11e
7159567: inconsistent configuration of MemoryHandler
jgish
parents:
5506
diff
changeset
|
59 |
* <li> <handler-name>.level |
32037
ab4526f4ac10
8133115: docs: replace <tt> tags (obsolete in html5) for java.util.logging, java.util.prefs, java.util.zip, java.util.jar
avstepan
parents:
25859
diff
changeset
|
60 |
* specifies the level for the {@code Handler} |
ab4526f4ac10
8133115: docs: replace <tt> tags (obsolete in html5) for java.util.logging, java.util.prefs, java.util.zip, java.util.jar
avstepan
parents:
25859
diff
changeset
|
61 |
* (defaults to {@code Level.ALL}). </li> |
14321
7f9f265ac11e
7159567: inconsistent configuration of MemoryHandler
jgish
parents:
5506
diff
changeset
|
62 |
* <li> <handler-name>.filter |
32037
ab4526f4ac10
8133115: docs: replace <tt> tags (obsolete in html5) for java.util.logging, java.util.prefs, java.util.zip, java.util.jar
avstepan
parents:
25859
diff
changeset
|
63 |
* specifies the name of a {@code Filter} class to use |
ab4526f4ac10
8133115: docs: replace <tt> tags (obsolete in html5) for java.util.logging, java.util.prefs, java.util.zip, java.util.jar
avstepan
parents:
25859
diff
changeset
|
64 |
* (defaults to no {@code Filter}). </li> |
14321
7f9f265ac11e
7159567: inconsistent configuration of MemoryHandler
jgish
parents:
5506
diff
changeset
|
65 |
* <li> <handler-name>.size |
7f9f265ac11e
7159567: inconsistent configuration of MemoryHandler
jgish
parents:
5506
diff
changeset
|
66 |
* defines the buffer size (defaults to 1000). </li> |
18156 | 67 |
* <li> <handler-name>.push |
32037
ab4526f4ac10
8133115: docs: replace <tt> tags (obsolete in html5) for java.util.logging, java.util.prefs, java.util.zip, java.util.jar
avstepan
parents:
25859
diff
changeset
|
68 |
* defines the {@code pushLevel} (defaults to {@code level.SEVERE}). </li> |
14321
7f9f265ac11e
7159567: inconsistent configuration of MemoryHandler
jgish
parents:
5506
diff
changeset
|
69 |
* <li> <handler-name>.target |
32037
ab4526f4ac10
8133115: docs: replace <tt> tags (obsolete in html5) for java.util.logging, java.util.prefs, java.util.zip, java.util.jar
avstepan
parents:
25859
diff
changeset
|
70 |
* specifies the name of the target {@code Handler } class. |
14321
7f9f265ac11e
7159567: inconsistent configuration of MemoryHandler
jgish
parents:
5506
diff
changeset
|
71 |
* (no default). </li> |
7f9f265ac11e
7159567: inconsistent configuration of MemoryHandler
jgish
parents:
5506
diff
changeset
|
72 |
* </ul> |
7f9f265ac11e
7159567: inconsistent configuration of MemoryHandler
jgish
parents:
5506
diff
changeset
|
73 |
* <p> |
7f9f265ac11e
7159567: inconsistent configuration of MemoryHandler
jgish
parents:
5506
diff
changeset
|
74 |
* For example, the properties for {@code MemoryHandler} would be: |
7f9f265ac11e
7159567: inconsistent configuration of MemoryHandler
jgish
parents:
5506
diff
changeset
|
75 |
* <ul> |
7f9f265ac11e
7159567: inconsistent configuration of MemoryHandler
jgish
parents:
5506
diff
changeset
|
76 |
* <li> java.util.logging.MemoryHandler.level=INFO </li> |
7f9f265ac11e
7159567: inconsistent configuration of MemoryHandler
jgish
parents:
5506
diff
changeset
|
77 |
* <li> java.util.logging.MemoryHandler.formatter=java.util.logging.SimpleFormatter </li> |
2 | 78 |
* </ul> |
14321
7f9f265ac11e
7159567: inconsistent configuration of MemoryHandler
jgish
parents:
5506
diff
changeset
|
79 |
* <p> |
7f9f265ac11e
7159567: inconsistent configuration of MemoryHandler
jgish
parents:
5506
diff
changeset
|
80 |
* For a custom handler, e.g. com.foo.MyHandler, the properties would be: |
7f9f265ac11e
7159567: inconsistent configuration of MemoryHandler
jgish
parents:
5506
diff
changeset
|
81 |
* <ul> |
7f9f265ac11e
7159567: inconsistent configuration of MemoryHandler
jgish
parents:
5506
diff
changeset
|
82 |
* <li> com.foo.MyHandler.level=INFO </li> |
7f9f265ac11e
7159567: inconsistent configuration of MemoryHandler
jgish
parents:
5506
diff
changeset
|
83 |
* <li> com.foo.MyHandler.formatter=java.util.logging.SimpleFormatter </li> |
7f9f265ac11e
7159567: inconsistent configuration of MemoryHandler
jgish
parents:
5506
diff
changeset
|
84 |
* </ul> |
24196
61c9885d76e2
8029451: Tidy warnings cleanup for java.util package; minor changes in java.nio, java.sql
yan
parents:
23010
diff
changeset
|
85 |
* |
2 | 86 |
* @since 1.4 |
87 |
*/ |
|
88 |
||
89 |
public class MemoryHandler extends Handler { |
|
90 |
private final static int DEFAULT_SIZE = 1000; |
|
19808
39cb79123ab2
6823527: java.util.logging.Handler has thread safety issues
dfuchs
parents:
18156
diff
changeset
|
91 |
private volatile Level pushLevel; |
2 | 92 |
private int size; |
93 |
private Handler target; |
|
94 |
private LogRecord buffer[]; |
|
95 |
int start, count; |
|
96 |
||
22110
06e486bc20b6
8030801: SocketHandler(host, port) requires permission ("java.util.logging.LoggingPermission" "control")
plevart
parents:
19808
diff
changeset
|
97 |
/** |
32037
ab4526f4ac10
8133115: docs: replace <tt> tags (obsolete in html5) for java.util.logging, java.util.prefs, java.util.zip, java.util.jar
avstepan
parents:
25859
diff
changeset
|
98 |
* Create a {@code MemoryHandler} and configure it based on |
ab4526f4ac10
8133115: docs: replace <tt> tags (obsolete in html5) for java.util.logging, java.util.prefs, java.util.zip, java.util.jar
avstepan
parents:
25859
diff
changeset
|
99 |
* {@code LogManager} configuration properties. |
22110
06e486bc20b6
8030801: SocketHandler(host, port) requires permission ("java.util.logging.LoggingPermission" "control")
plevart
parents:
19808
diff
changeset
|
100 |
*/ |
06e486bc20b6
8030801: SocketHandler(host, port) requires permission ("java.util.logging.LoggingPermission" "control")
plevart
parents:
19808
diff
changeset
|
101 |
public MemoryHandler() { |
06e486bc20b6
8030801: SocketHandler(host, port) requires permission ("java.util.logging.LoggingPermission" "control")
plevart
parents:
19808
diff
changeset
|
102 |
// configure with specific defaults for MemoryHandler |
06e486bc20b6
8030801: SocketHandler(host, port) requires permission ("java.util.logging.LoggingPermission" "control")
plevart
parents:
19808
diff
changeset
|
103 |
super(Level.ALL, new SimpleFormatter(), null); |
06e486bc20b6
8030801: SocketHandler(host, port) requires permission ("java.util.logging.LoggingPermission" "control")
plevart
parents:
19808
diff
changeset
|
104 |
|
2 | 105 |
LogManager manager = LogManager.getLogManager(); |
106 |
String cname = getClass().getName(); |
|
107 |
pushLevel = manager.getLevelProperty(cname +".push", Level.SEVERE); |
|
108 |
size = manager.getIntProperty(cname + ".size", DEFAULT_SIZE); |
|
109 |
if (size <= 0) { |
|
110 |
size = DEFAULT_SIZE; |
|
111 |
} |
|
22110
06e486bc20b6
8030801: SocketHandler(host, port) requires permission ("java.util.logging.LoggingPermission" "control")
plevart
parents:
19808
diff
changeset
|
112 |
String targetName = manager.getProperty(cname+".target"); |
14321
7f9f265ac11e
7159567: inconsistent configuration of MemoryHandler
jgish
parents:
5506
diff
changeset
|
113 |
if (targetName == null) { |
22110
06e486bc20b6
8030801: SocketHandler(host, port) requires permission ("java.util.logging.LoggingPermission" "control")
plevart
parents:
19808
diff
changeset
|
114 |
throw new RuntimeException("The handler " + cname |
14321
7f9f265ac11e
7159567: inconsistent configuration of MemoryHandler
jgish
parents:
5506
diff
changeset
|
115 |
+ " does not specify a target"); |
7f9f265ac11e
7159567: inconsistent configuration of MemoryHandler
jgish
parents:
5506
diff
changeset
|
116 |
} |
7f9f265ac11e
7159567: inconsistent configuration of MemoryHandler
jgish
parents:
5506
diff
changeset
|
117 |
Class<?> clz; |
2 | 118 |
try { |
14321
7f9f265ac11e
7159567: inconsistent configuration of MemoryHandler
jgish
parents:
5506
diff
changeset
|
119 |
clz = ClassLoader.getSystemClassLoader().loadClass(targetName); |
37782
ad8fe7507ecc
6850612: Deprecate Class.newInstance since it violates the checked exception language contract
darcy
parents:
32037
diff
changeset
|
120 |
@SuppressWarnings("deprecation") |
ad8fe7507ecc
6850612: Deprecate Class.newInstance since it violates the checked exception language contract
darcy
parents:
32037
diff
changeset
|
121 |
Object o = clz.newInstance(); |
ad8fe7507ecc
6850612: Deprecate Class.newInstance since it violates the checked exception language contract
darcy
parents:
32037
diff
changeset
|
122 |
target = (Handler) o; |
14321
7f9f265ac11e
7159567: inconsistent configuration of MemoryHandler
jgish
parents:
5506
diff
changeset
|
123 |
} catch (ClassNotFoundException | InstantiationException | IllegalAccessException e) { |
7f9f265ac11e
7159567: inconsistent configuration of MemoryHandler
jgish
parents:
5506
diff
changeset
|
124 |
throw new RuntimeException("MemoryHandler can't load handler target \"" + targetName + "\"" , e); |
2 | 125 |
} |
126 |
init(); |
|
127 |
} |
|
128 |
||
129 |
// Initialize. Size is a count of LogRecords. |
|
130 |
private void init() { |
|
131 |
buffer = new LogRecord[size]; |
|
132 |
start = 0; |
|
133 |
count = 0; |
|
134 |
} |
|
135 |
||
136 |
/** |
|
32037
ab4526f4ac10
8133115: docs: replace <tt> tags (obsolete in html5) for java.util.logging, java.util.prefs, java.util.zip, java.util.jar
avstepan
parents:
25859
diff
changeset
|
137 |
* Create a {@code MemoryHandler}. |
2 | 138 |
* <p> |
32037
ab4526f4ac10
8133115: docs: replace <tt> tags (obsolete in html5) for java.util.logging, java.util.prefs, java.util.zip, java.util.jar
avstepan
parents:
25859
diff
changeset
|
139 |
* The {@code MemoryHandler} is configured based on {@code LogManager} |
ab4526f4ac10
8133115: docs: replace <tt> tags (obsolete in html5) for java.util.logging, java.util.prefs, java.util.zip, java.util.jar
avstepan
parents:
25859
diff
changeset
|
140 |
* properties (or their default values) except that the given {@code pushLevel} |
2 | 141 |
* argument and buffer size argument are used. |
142 |
* |
|
143 |
* @param target the Handler to which to publish output. |
|
144 |
* @param size the number of log records to buffer (must be greater than zero) |
|
145 |
* @param pushLevel message level to push on |
|
146 |
* |
|
18156 | 147 |
* @throws IllegalArgumentException if {@code size is <= 0} |
2 | 148 |
*/ |
149 |
public MemoryHandler(Handler target, int size, Level pushLevel) { |
|
22110
06e486bc20b6
8030801: SocketHandler(host, port) requires permission ("java.util.logging.LoggingPermission" "control")
plevart
parents:
19808
diff
changeset
|
150 |
// configure with specific defaults for MemoryHandler |
06e486bc20b6
8030801: SocketHandler(host, port) requires permission ("java.util.logging.LoggingPermission" "control")
plevart
parents:
19808
diff
changeset
|
151 |
super(Level.ALL, new SimpleFormatter(), null); |
06e486bc20b6
8030801: SocketHandler(host, port) requires permission ("java.util.logging.LoggingPermission" "control")
plevart
parents:
19808
diff
changeset
|
152 |
|
2 | 153 |
if (target == null || pushLevel == null) { |
154 |
throw new NullPointerException(); |
|
155 |
} |
|
156 |
if (size <= 0) { |
|
157 |
throw new IllegalArgumentException(); |
|
158 |
} |
|
159 |
this.target = target; |
|
160 |
this.pushLevel = pushLevel; |
|
161 |
this.size = size; |
|
162 |
init(); |
|
163 |
} |
|
164 |
||
165 |
/** |
|
32037
ab4526f4ac10
8133115: docs: replace <tt> tags (obsolete in html5) for java.util.logging, java.util.prefs, java.util.zip, java.util.jar
avstepan
parents:
25859
diff
changeset
|
166 |
* Store a {@code LogRecord} in an internal buffer. |
2 | 167 |
* <p> |
32037
ab4526f4ac10
8133115: docs: replace <tt> tags (obsolete in html5) for java.util.logging, java.util.prefs, java.util.zip, java.util.jar
avstepan
parents:
25859
diff
changeset
|
168 |
* If there is a {@code Filter}, its {@code isLoggable} |
2 | 169 |
* method is called to check if the given log record is loggable. |
170 |
* If not we return. Otherwise the given record is copied into |
|
171 |
* an internal circular buffer. Then the record's level property is |
|
32037
ab4526f4ac10
8133115: docs: replace <tt> tags (obsolete in html5) for java.util.logging, java.util.prefs, java.util.zip, java.util.jar
avstepan
parents:
25859
diff
changeset
|
172 |
* compared with the {@code pushLevel}. If the given level is |
ab4526f4ac10
8133115: docs: replace <tt> tags (obsolete in html5) for java.util.logging, java.util.prefs, java.util.zip, java.util.jar
avstepan
parents:
25859
diff
changeset
|
173 |
* greater than or equal to the {@code pushLevel} then {@code push} |
2 | 174 |
* is called to write all buffered records to the target output |
32037
ab4526f4ac10
8133115: docs: replace <tt> tags (obsolete in html5) for java.util.logging, java.util.prefs, java.util.zip, java.util.jar
avstepan
parents:
25859
diff
changeset
|
175 |
* {@code Handler}. |
2 | 176 |
* |
177 |
* @param record description of the log event. A null record is |
|
178 |
* silently ignored and is not published |
|
179 |
*/ |
|
19808
39cb79123ab2
6823527: java.util.logging.Handler has thread safety issues
dfuchs
parents:
18156
diff
changeset
|
180 |
@Override |
2 | 181 |
public synchronized void publish(LogRecord record) { |
182 |
if (!isLoggable(record)) { |
|
183 |
return; |
|
184 |
} |
|
185 |
int ix = (start+count)%buffer.length; |
|
186 |
buffer[ix] = record; |
|
187 |
if (count < buffer.length) { |
|
188 |
count++; |
|
189 |
} else { |
|
190 |
start++; |
|
191 |
start %= buffer.length; |
|
192 |
} |
|
193 |
if (record.getLevel().intValue() >= pushLevel.intValue()) { |
|
194 |
push(); |
|
195 |
} |
|
196 |
} |
|
197 |
||
198 |
/** |
|
32037
ab4526f4ac10
8133115: docs: replace <tt> tags (obsolete in html5) for java.util.logging, java.util.prefs, java.util.zip, java.util.jar
avstepan
parents:
25859
diff
changeset
|
199 |
* Push any buffered output to the target {@code Handler}. |
2 | 200 |
* <p> |
201 |
* The buffer is then cleared. |
|
202 |
*/ |
|
203 |
public synchronized void push() { |
|
204 |
for (int i = 0; i < count; i++) { |
|
205 |
int ix = (start+i)%buffer.length; |
|
206 |
LogRecord record = buffer[ix]; |
|
207 |
target.publish(record); |
|
208 |
} |
|
209 |
// Empty the buffer. |
|
210 |
start = 0; |
|
211 |
count = 0; |
|
212 |
} |
|
213 |
||
214 |
/** |
|
32037
ab4526f4ac10
8133115: docs: replace <tt> tags (obsolete in html5) for java.util.logging, java.util.prefs, java.util.zip, java.util.jar
avstepan
parents:
25859
diff
changeset
|
215 |
* Causes a flush on the target {@code Handler}. |
2 | 216 |
* <p> |
32037
ab4526f4ac10
8133115: docs: replace <tt> tags (obsolete in html5) for java.util.logging, java.util.prefs, java.util.zip, java.util.jar
avstepan
parents:
25859
diff
changeset
|
217 |
* Note that the current contents of the {@code MemoryHandler} |
2 | 218 |
* buffer are <b>not</b> written out. That requires a "push". |
219 |
*/ |
|
19808
39cb79123ab2
6823527: java.util.logging.Handler has thread safety issues
dfuchs
parents:
18156
diff
changeset
|
220 |
@Override |
2 | 221 |
public void flush() { |
222 |
target.flush(); |
|
223 |
} |
|
224 |
||
225 |
/** |
|
32037
ab4526f4ac10
8133115: docs: replace <tt> tags (obsolete in html5) for java.util.logging, java.util.prefs, java.util.zip, java.util.jar
avstepan
parents:
25859
diff
changeset
|
226 |
* Close the {@code Handler} and free all associated resources. |
ab4526f4ac10
8133115: docs: replace <tt> tags (obsolete in html5) for java.util.logging, java.util.prefs, java.util.zip, java.util.jar
avstepan
parents:
25859
diff
changeset
|
227 |
* This will also close the target {@code Handler}. |
2 | 228 |
* |
229 |
* @exception SecurityException if a security manager exists and if |
|
32037
ab4526f4ac10
8133115: docs: replace <tt> tags (obsolete in html5) for java.util.logging, java.util.prefs, java.util.zip, java.util.jar
avstepan
parents:
25859
diff
changeset
|
230 |
* the caller does not have {@code LoggingPermission("control")}. |
2 | 231 |
*/ |
19808
39cb79123ab2
6823527: java.util.logging.Handler has thread safety issues
dfuchs
parents:
18156
diff
changeset
|
232 |
@Override |
2 | 233 |
public void close() throws SecurityException { |
234 |
target.close(); |
|
235 |
setLevel(Level.OFF); |
|
236 |
} |
|
237 |
||
238 |
/** |
|
32037
ab4526f4ac10
8133115: docs: replace <tt> tags (obsolete in html5) for java.util.logging, java.util.prefs, java.util.zip, java.util.jar
avstepan
parents:
25859
diff
changeset
|
239 |
* Set the {@code pushLevel}. After a {@code LogRecord} is copied |
2 | 240 |
* into our internal buffer, if its level is greater than or equal to |
32037
ab4526f4ac10
8133115: docs: replace <tt> tags (obsolete in html5) for java.util.logging, java.util.prefs, java.util.zip, java.util.jar
avstepan
parents:
25859
diff
changeset
|
241 |
* the {@code pushLevel}, then {@code push} will be called. |
2 | 242 |
* |
32037
ab4526f4ac10
8133115: docs: replace <tt> tags (obsolete in html5) for java.util.logging, java.util.prefs, java.util.zip, java.util.jar
avstepan
parents:
25859
diff
changeset
|
243 |
* @param newLevel the new value of the {@code pushLevel} |
2 | 244 |
* @exception SecurityException if a security manager exists and if |
32037
ab4526f4ac10
8133115: docs: replace <tt> tags (obsolete in html5) for java.util.logging, java.util.prefs, java.util.zip, java.util.jar
avstepan
parents:
25859
diff
changeset
|
245 |
* the caller does not have {@code LoggingPermission("control")}. |
2 | 246 |
*/ |
19808
39cb79123ab2
6823527: java.util.logging.Handler has thread safety issues
dfuchs
parents:
18156
diff
changeset
|
247 |
public synchronized void setPushLevel(Level newLevel) throws SecurityException { |
2 | 248 |
if (newLevel == null) { |
249 |
throw new NullPointerException(); |
|
250 |
} |
|
14216
23714b376286
7169884: LogManager checks do not work correctly for sub-types
alanb
parents:
5506
diff
changeset
|
251 |
checkPermission(); |
2 | 252 |
pushLevel = newLevel; |
253 |
} |
|
254 |
||
255 |
/** |
|
32037
ab4526f4ac10
8133115: docs: replace <tt> tags (obsolete in html5) for java.util.logging, java.util.prefs, java.util.zip, java.util.jar
avstepan
parents:
25859
diff
changeset
|
256 |
* Get the {@code pushLevel}. |
2 | 257 |
* |
32037
ab4526f4ac10
8133115: docs: replace <tt> tags (obsolete in html5) for java.util.logging, java.util.prefs, java.util.zip, java.util.jar
avstepan
parents:
25859
diff
changeset
|
258 |
* @return the value of the {@code pushLevel} |
2 | 259 |
*/ |
19808
39cb79123ab2
6823527: java.util.logging.Handler has thread safety issues
dfuchs
parents:
18156
diff
changeset
|
260 |
public Level getPushLevel() { |
2 | 261 |
return pushLevel; |
262 |
} |
|
263 |
||
264 |
/** |
|
32037
ab4526f4ac10
8133115: docs: replace <tt> tags (obsolete in html5) for java.util.logging, java.util.prefs, java.util.zip, java.util.jar
avstepan
parents:
25859
diff
changeset
|
265 |
* Check if this {@code Handler} would actually log a given |
ab4526f4ac10
8133115: docs: replace <tt> tags (obsolete in html5) for java.util.logging, java.util.prefs, java.util.zip, java.util.jar
avstepan
parents:
25859
diff
changeset
|
266 |
* {@code LogRecord} into its internal buffer. |
2 | 267 |
* <p> |
32037
ab4526f4ac10
8133115: docs: replace <tt> tags (obsolete in html5) for java.util.logging, java.util.prefs, java.util.zip, java.util.jar
avstepan
parents:
25859
diff
changeset
|
268 |
* This method checks if the {@code LogRecord} has an appropriate level and |
ab4526f4ac10
8133115: docs: replace <tt> tags (obsolete in html5) for java.util.logging, java.util.prefs, java.util.zip, java.util.jar
avstepan
parents:
25859
diff
changeset
|
269 |
* whether it satisfies any {@code Filter}. However it does <b>not</b> |
ab4526f4ac10
8133115: docs: replace <tt> tags (obsolete in html5) for java.util.logging, java.util.prefs, java.util.zip, java.util.jar
avstepan
parents:
25859
diff
changeset
|
270 |
* check whether the {@code LogRecord} would result in a "push" of the |
ab4526f4ac10
8133115: docs: replace <tt> tags (obsolete in html5) for java.util.logging, java.util.prefs, java.util.zip, java.util.jar
avstepan
parents:
25859
diff
changeset
|
271 |
* buffer contents. It will return false if the {@code LogRecord} is null. |
24196
61c9885d76e2
8029451: Tidy warnings cleanup for java.util package; minor changes in java.nio, java.sql
yan
parents:
23010
diff
changeset
|
272 |
* |
32037
ab4526f4ac10
8133115: docs: replace <tt> tags (obsolete in html5) for java.util.logging, java.util.prefs, java.util.zip, java.util.jar
avstepan
parents:
25859
diff
changeset
|
273 |
* @param record a {@code LogRecord} |
ab4526f4ac10
8133115: docs: replace <tt> tags (obsolete in html5) for java.util.logging, java.util.prefs, java.util.zip, java.util.jar
avstepan
parents:
25859
diff
changeset
|
274 |
* @return true if the {@code LogRecord} would be logged. |
2 | 275 |
* |
276 |
*/ |
|
19808
39cb79123ab2
6823527: java.util.logging.Handler has thread safety issues
dfuchs
parents:
18156
diff
changeset
|
277 |
@Override |
2 | 278 |
public boolean isLoggable(LogRecord record) { |
279 |
return super.isLoggable(record); |
|
280 |
} |
|
281 |
} |