author | dfuchs |
Thu, 06 Apr 2017 14:38:15 +0100 | |
changeset 44538 | a603c475d649 |
parent 32037 | ab4526f4ac10 |
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 |
||
27 |
package java.util.logging; |
|
28 |
||
29 |
/** |
|
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
|
30 |
* This {@code Handler} publishes log records to {@code System.err}. |
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 |
* By default the {@code SimpleFormatter} is used to generate brief summaries. |
2 | 32 |
* <p> |
33 |
* <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
|
34 |
* By default each {@code ConsoleHandler} 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
|
35 |
* {@code LogManager} configuration properties where {@code <handler-name>} |
14321
7f9f265ac11e
7159567: inconsistent configuration of MemoryHandler
jgish
parents:
5506
diff
changeset
|
36 |
* refers to the fully-qualified class name of the handler. |
7f9f265ac11e
7159567: inconsistent configuration of MemoryHandler
jgish
parents:
5506
diff
changeset
|
37 |
* If properties are not defined |
2 | 38 |
* (or have invalid values) then the specified default values are used. |
39 |
* <ul> |
|
14321
7f9f265ac11e
7159567: inconsistent configuration of MemoryHandler
jgish
parents:
5506
diff
changeset
|
40 |
* <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
|
41 |
* specifies the default 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
|
42 |
* (defaults to {@code Level.INFO}). </li> |
14321
7f9f265ac11e
7159567: inconsistent configuration of MemoryHandler
jgish
parents:
5506
diff
changeset
|
43 |
* <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
|
44 |
* 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
|
45 |
* (defaults to no {@code Filter}). </li> |
14321
7f9f265ac11e
7159567: inconsistent configuration of MemoryHandler
jgish
parents:
5506
diff
changeset
|
46 |
* <li> <handler-name>.formatter |
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
|
47 |
* specifies the name of a {@code Formatter} 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
|
48 |
* (defaults to {@code java.util.logging.SimpleFormatter}). </li> |
14321
7f9f265ac11e
7159567: inconsistent configuration of MemoryHandler
jgish
parents:
5506
diff
changeset
|
49 |
* <li> <handler-name>.encoding |
2 | 50 |
* the name of the character set encoding to use (defaults to |
14321
7f9f265ac11e
7159567: inconsistent configuration of MemoryHandler
jgish
parents:
5506
diff
changeset
|
51 |
* the default platform encoding). </li> |
7f9f265ac11e
7159567: inconsistent configuration of MemoryHandler
jgish
parents:
5506
diff
changeset
|
52 |
* </ul> |
7f9f265ac11e
7159567: inconsistent configuration of MemoryHandler
jgish
parents:
5506
diff
changeset
|
53 |
* <p> |
7f9f265ac11e
7159567: inconsistent configuration of MemoryHandler
jgish
parents:
5506
diff
changeset
|
54 |
* For example, the properties for {@code ConsoleHandler} would be: |
7f9f265ac11e
7159567: inconsistent configuration of MemoryHandler
jgish
parents:
5506
diff
changeset
|
55 |
* <ul> |
7f9f265ac11e
7159567: inconsistent configuration of MemoryHandler
jgish
parents:
5506
diff
changeset
|
56 |
* <li> java.util.logging.ConsoleHandler.level=INFO </li> |
7f9f265ac11e
7159567: inconsistent configuration of MemoryHandler
jgish
parents:
5506
diff
changeset
|
57 |
* <li> java.util.logging.ConsoleHandler.formatter=java.util.logging.SimpleFormatter </li> |
7f9f265ac11e
7159567: inconsistent configuration of MemoryHandler
jgish
parents:
5506
diff
changeset
|
58 |
* </ul> |
7f9f265ac11e
7159567: inconsistent configuration of MemoryHandler
jgish
parents:
5506
diff
changeset
|
59 |
* <p> |
7f9f265ac11e
7159567: inconsistent configuration of MemoryHandler
jgish
parents:
5506
diff
changeset
|
60 |
* For a custom handler, e.g. com.foo.MyHandler, the properties would be: |
7f9f265ac11e
7159567: inconsistent configuration of MemoryHandler
jgish
parents:
5506
diff
changeset
|
61 |
* <ul> |
7f9f265ac11e
7159567: inconsistent configuration of MemoryHandler
jgish
parents:
5506
diff
changeset
|
62 |
* <li> com.foo.MyHandler.level=INFO </li> |
7f9f265ac11e
7159567: inconsistent configuration of MemoryHandler
jgish
parents:
5506
diff
changeset
|
63 |
* <li> com.foo.MyHandler.formatter=java.util.logging.SimpleFormatter </li> |
2 | 64 |
* </ul> |
24196
61c9885d76e2
8029451: Tidy warnings cleanup for java.util package; minor changes in java.nio, java.sql
yan
parents:
23010
diff
changeset
|
65 |
* |
2 | 66 |
* @since 1.4 |
67 |
*/ |
|
68 |
public class ConsoleHandler extends StreamHandler { |
|
69 |
||
70 |
/** |
|
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
|
71 |
* Create a {@code ConsoleHandler} for {@code System.err}. |
2 | 72 |
* <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
|
73 |
* The {@code ConsoleHandler} is configured 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
|
74 |
* {@code LogManager} properties (or their default values). |
2 | 75 |
* |
76 |
*/ |
|
77 |
public ConsoleHandler() { |
|
22110
06e486bc20b6
8030801: SocketHandler(host, port) requires permission ("java.util.logging.LoggingPermission" "control")
plevart
parents:
19808
diff
changeset
|
78 |
// configure with specific defaults for ConsoleHandler |
06e486bc20b6
8030801: SocketHandler(host, port) requires permission ("java.util.logging.LoggingPermission" "control")
plevart
parents:
19808
diff
changeset
|
79 |
super(Level.INFO, new SimpleFormatter(), null); |
06e486bc20b6
8030801: SocketHandler(host, port) requires permission ("java.util.logging.LoggingPermission" "control")
plevart
parents:
19808
diff
changeset
|
80 |
|
06e486bc20b6
8030801: SocketHandler(host, port) requires permission ("java.util.logging.LoggingPermission" "control")
plevart
parents:
19808
diff
changeset
|
81 |
setOutputStreamPrivileged(System.err); |
2 | 82 |
} |
83 |
||
84 |
/** |
|
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
|
85 |
* Publish a {@code LogRecord}. |
2 | 86 |
* <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
|
87 |
* The logging request was made initially to a {@code Logger} object, |
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
|
88 |
* which initialized the {@code LogRecord} and forwarded it here. |
24196
61c9885d76e2
8029451: Tidy warnings cleanup for java.util package; minor changes in java.nio, java.sql
yan
parents:
23010
diff
changeset
|
89 |
* |
2 | 90 |
* @param record description of the log event. A null record is |
91 |
* silently ignored and is not published |
|
92 |
*/ |
|
19808
39cb79123ab2
6823527: java.util.logging.Handler has thread safety issues
dfuchs
parents:
18156
diff
changeset
|
93 |
@Override |
2 | 94 |
public void publish(LogRecord record) { |
95 |
super.publish(record); |
|
96 |
flush(); |
|
97 |
} |
|
98 |
||
99 |
/** |
|
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
|
100 |
* Override {@code StreamHandler.close} to do a flush but not |
2 | 101 |
* to close the output stream. That is, we do <b>not</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
|
102 |
* close {@code System.err}. |
2 | 103 |
*/ |
19808
39cb79123ab2
6823527: java.util.logging.Handler has thread safety issues
dfuchs
parents:
18156
diff
changeset
|
104 |
@Override |
2 | 105 |
public void close() { |
106 |
flush(); |
|
107 |
} |
|
108 |
} |