Path: blob/master/src/java.logging/share/classes/java/util/logging/ConsoleHandler.java
41159 views
/*1* Copyright (c) 2000, 2013, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation. Oracle designates this7* particular file as subject to the "Classpath" exception as provided8* by Oracle in the LICENSE file that accompanied this code.9*10* This code is distributed in the hope that it will be useful, but WITHOUT11* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or12* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License13* version 2 for more details (a copy is included in the LICENSE file that14* accompanied this code).15*16* You should have received a copy of the GNU General Public License version17* 2 along with this work; if not, write to the Free Software Foundation,18* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.19*20* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA21* or visit www.oracle.com if you need additional information or have any22* questions.23*/242526package java.util.logging;2728/**29* This {@code Handler} publishes log records to {@code System.err}.30* By default the {@code SimpleFormatter} is used to generate brief summaries.31* <p>32* <b>Configuration:</b>33* By default each {@code ConsoleHandler} is initialized using the following34* {@code LogManager} configuration properties where {@code <handler-name>}35* refers to the fully-qualified class name of the handler.36* If properties are not defined37* (or have invalid values) then the specified default values are used.38* <ul>39* <li> <handler-name>.level40* specifies the default level for the {@code Handler}41* (defaults to {@code Level.INFO}). </li>42* <li> <handler-name>.filter43* specifies the name of a {@code Filter} class to use44* (defaults to no {@code Filter}). </li>45* <li> <handler-name>.formatter46* specifies the name of a {@code Formatter} class to use47* (defaults to {@code java.util.logging.SimpleFormatter}). </li>48* <li> <handler-name>.encoding49* the name of the character set encoding to use (defaults to50* the default platform encoding). </li>51* </ul>52* <p>53* For example, the properties for {@code ConsoleHandler} would be:54* <ul>55* <li> java.util.logging.ConsoleHandler.level=INFO </li>56* <li> java.util.logging.ConsoleHandler.formatter=java.util.logging.SimpleFormatter </li>57* </ul>58* <p>59* For a custom handler, e.g. com.foo.MyHandler, the properties would be:60* <ul>61* <li> com.foo.MyHandler.level=INFO </li>62* <li> com.foo.MyHandler.formatter=java.util.logging.SimpleFormatter </li>63* </ul>64*65* @since 1.466*/67public class ConsoleHandler extends StreamHandler {6869/**70* Create a {@code ConsoleHandler} for {@code System.err}.71* <p>72* The {@code ConsoleHandler} is configured based on73* {@code LogManager} properties (or their default values).74*75*/76public ConsoleHandler() {77// configure with specific defaults for ConsoleHandler78super(Level.INFO, new SimpleFormatter(), null);7980setOutputStreamPrivileged(System.err);81}8283/**84* Publish a {@code LogRecord}.85* <p>86* The logging request was made initially to a {@code Logger} object,87* which initialized the {@code LogRecord} and forwarded it here.88*89* @param record description of the log event. A null record is90* silently ignored and is not published91*/92@Override93public void publish(LogRecord record) {94super.publish(record);95flush();96}9798/**99* Override {@code StreamHandler.close} to do a flush but not100* to close the output stream. That is, we do <b>not</b>101* close {@code System.err}.102*/103@Override104public void close() {105flush();106}107}108109110