01: /*
02: * Licensed to the Apache Software Foundation (ASF) under one or more
03: * contributor license agreements. See the NOTICE file distributed with
04: * this work for additional information regarding copyright ownership.
05: * The ASF licenses this file to You under the Apache License, Version 2.0
06: * (the "License"); you may not use this file except in compliance with
07: * the License. You may obtain a copy of the License at
08: *
09: * http://www.apache.org/licenses/LICENSE-2.0
10: *
11: * Unless required by applicable law or agreed to in writing, software
12: * distributed under the License is distributed on an "AS IS" BASIS,
13: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14: * See the License for the specific language governing permissions and
15: * limitations under the License.
16: */
17:
18: package java.util.logging;
19:
20: /**
21: * A handler that writes log messages to the standard output stream
22: * <code>System.err</code>.
23: * <p>
24: * This handler reads the following properties from the log manager to
25: * initialize itself:
26: * <ul>
27: * <li>java.util.logging.ConsoleHandler.level specifies the logging level,
28: * defaults to <code>Level.INFO</code> if this property is not found or has an
29: * invalid value;
30: * <li>java.util.logging.ConsoleHandler.filter specifies the name of the filter
31: * class to be associated with this handler, defaults to <code>null</code> if
32: * this property is not found or has an invalid value;
33: * <li>java.util.logging.ConsoleHandler.formatter specifies the name of the
34: * formatter class to be associated with this handler, defaults to
35: * <code>java.util.logging.SimpleFormatter</code> if this property is not
36: * found or has an invalid value;
37: * <li>java.util.logging.ConsoleHandler.encoding specifies the encoding this
38: * handler will use to encode log messages, defaults to <code>null</code> if
39: * this property is not found or has an invalid value.
40: * </ul>
41: * </p>
42: * <p>
43: * This class is not thread-safe.
44: * </p>
45: */
46: public class ConsoleHandler extends StreamHandler {
47:
48: /**
49: * Constructs a <code>ConsoleHandler</code> object.
50: */
51: public ConsoleHandler() {
52: super (System.err);
53: }
54:
55: /**
56: * Closes this handler. The <code>System.err</code> is flushed but not
57: * closed.
58: */
59: @Override
60: public void close() {
61: super .close(false);
62: }
63:
64: /**
65: * Logs a record if necessary. A flush operation will be done.
66: *
67: * @param record
68: * the log record to be logged
69: */
70: @Override
71: public void publish(LogRecord record) {
72: super.publish(record);
73: super.flush();
74: }
75: }
|