1/*
2 * Licensed to the Apache Software Foundation (ASF) under one or more
3 * contributor license agreements.  See the NOTICE file distributed with
4 * this work for additional information regarding copyright ownership.
5 * The ASF licenses this file to You under the Apache License, Version 2.0
6 * (the "License"); you may not use this file except in compliance with
7 * the License.  You may obtain a copy of the License at
8 *
9 *     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
18package java.util.logging;
19
20/**
21 * A handler that writes log messages to the standard output stream
22 * {@code System.err}.
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} 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} if this
32 * 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} if this property is not found or
36 * 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} if this
39 * property is not found or has an invalid value.
40 * </ul>
41 * <p>
42 * This class is not thread-safe.
43 */
44public class ConsoleHandler extends StreamHandler {
45
46    /**
47     * Constructs a {@code ConsoleHandler} object.
48     */
49    public ConsoleHandler() {
50        super(System.err);
51    }
52
53    /**
54     * Closes this handler. The {@code System.err} is flushed but not closed.
55     */
56    @Override
57    public void close() {
58        super.close(false);
59    }
60
61    /**
62     * Logs a record if necessary. A flush operation will be done.
63     *
64     * @param record
65     *            the log record to be logged.
66     */
67    @Override
68    public void publish(LogRecord record) {
69        super.publish(record);
70        super.flush();
71    }
72}
73