Source Code Cross Referenced for ConsoleHandler.java in  » 6.0-JDK-Core » Collections-Jar-Zip-Logging-regex » java » util » logging » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Home
Java Source Code / Java Documentation
1.6.0 JDK Core
2.6.0 JDK Modules
3.6.0 JDK Modules com.sun
4.6.0 JDK Modules com.sun.java
5.6.0 JDK Modules sun
6.6.0 JDK Platform
7.Ajax
8.Apache Harmony Java SE
9.Aspect oriented
10.Authentication Authorization
11.Blogger System
12.Build
13.Byte Code
14.Cache
15.Chart
16.Chat
17.Code Analyzer
18.Collaboration
19.Content Management System
20.Database Client
21.Database DBMS
22.Database JDBC Connection Pool
23.Database ORM
24.Development
25.EJB Server
26.ERP CRM Financial
27.ESB
28.Forum
29.Game
30.GIS
31.Graphic 3D
32.Graphic Library
33.Groupware
34.HTML Parser
35.IDE
36.IDE Eclipse
37.IDE Netbeans
38.Installer
39.Internationalization Localization
40.Inversion of Control
41.Issue Tracking
42.J2EE
43.J2ME
44.JBoss
45.JMS
46.JMX
47.Library
48.Mail Clients
49.Music
50.Net
51.Parser
52.PDF
53.Portal
54.Profiler
55.Project Management
56.Report
57.RSS RDF
58.Rule Engine
59.Science
60.Scripting
61.Search Engine
62.Security
63.Sevlet Container
64.Source Control
65.Swing Library
66.Template Engine
67.Test Coverage
68.Testing
69.UML
70.Web Crawler
71.Web Framework
72.Web Mail
73.Web Server
74.Web Services
75.Web Services apache cxf 2.2.6
76.Web Services AXIS2
77.Wiki Engine
78.Workflow Engines
79.XML
80.XML UI
Java Source Code / Java Documentation » 6.0 JDK Core » Collections Jar Zip Logging regex » java.util.logging 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001        /*
002         * Copyright 2000-2003 Sun Microsystems, Inc.  All Rights Reserved.
003         * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
004         *
005         * This code is free software; you can redistribute it and/or modify it
006         * under the terms of the GNU General Public License version 2 only, as
007         * published by the Free Software Foundation.  Sun designates this
008         * particular file as subject to the "Classpath" exception as provided
009         * by Sun in the LICENSE file that accompanied this code.
010         *
011         * This code is distributed in the hope that it will be useful, but WITHOUT
012         * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
013         * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
014         * version 2 for more details (a copy is included in the LICENSE file that
015         * accompanied this code).
016         *
017         * You should have received a copy of the GNU General Public License version
018         * 2 along with this work; if not, write to the Free Software Foundation,
019         * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
020         *
021         * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
022         * CA 95054 USA or visit www.sun.com if you need additional information or
023         * have any questions.
024         */
025
026        package java.util.logging;
027
028        import java.io.*;
029        import java.net.*;
030
031        /**
032         * This <tt>Handler</tt> publishes log records to <tt>System.err</tt>.
033         * By default the <tt>SimpleFormatter</tt> is used to generate brief summaries.
034         * <p>
035         * <b>Configuration:</b>
036         * By default each <tt>ConsoleHandler</tt> is initialized using the following
037         * <tt>LogManager</tt> configuration properties.  If properties are not defined
038         * (or have invalid values) then the specified default values are used.
039         * <ul>
040         * <li>   java.util.logging.ConsoleHandler.level 
041         *	  specifies the default level for the <tt>Handler</tt>
042         *	  (defaults to <tt>Level.INFO</tt>).
043         * <li>   java.util.logging.ConsoleHandler.filter
044         *	  specifies the name of a <tt>Filter</tt> class to use
045         *	  (defaults to no <tt>Filter</tt>).
046         * <li>   java.util.logging.ConsoleHandler.formatter
047         * 	  specifies the name of a <tt>Formatter</tt> class to use
048         *  	  (defaults to <tt>java.util.logging.SimpleFormatter</tt>).
049         * <li>   java.util.logging.ConsoleHandler.encoding 
050         *	  the name of the character set encoding to use (defaults to
051         *	  the default platform encoding).
052         * </ul>
053         * <p>
054         * @version 1.19, 05/05/07
055         * @since 1.4
056         */
057
058        public class ConsoleHandler extends StreamHandler {
059            // Private method to configure a ConsoleHandler from LogManager
060            // properties and/or default values as specified in the class
061            // javadoc.
062            private void configure() {
063                LogManager manager = LogManager.getLogManager();
064                String cname = getClass().getName();
065
066                setLevel(manager.getLevelProperty(cname + ".level", Level.INFO));
067                setFilter(manager.getFilterProperty(cname + ".filter", null));
068                setFormatter(manager.getFormatterProperty(cname + ".formatter",
069                        new SimpleFormatter()));
070                try {
071                    setEncoding(manager.getStringProperty(cname + ".encoding",
072                            null));
073                } catch (Exception ex) {
074                    try {
075                        setEncoding(null);
076                    } catch (Exception ex2) {
077                        // doing a setEncoding with null should always work.
078                        // assert false;
079                    }
080                }
081            }
082
083            /**
084             * Create a <tt>ConsoleHandler</tt> for <tt>System.err</tt>.
085             * <p>
086             * The <tt>ConsoleHandler</tt> is configured based on
087             * <tt>LogManager</tt> properties (or their default values).
088             * 
089             */
090            public ConsoleHandler() {
091                sealed = false;
092                configure();
093                setOutputStream(System.err);
094                sealed = true;
095            }
096
097            /**
098             * Publish a <tt>LogRecord</tt>.
099             * <p>
100             * The logging request was made initially to a <tt>Logger</tt> object,
101             * which initialized the <tt>LogRecord</tt> and forwarded it here.
102             * <p>
103             * @param  record  description of the log event. A null record is
104             *                 silently ignored and is not published
105             */
106            public void publish(LogRecord record) {
107                super .publish(record);
108                flush();
109            }
110
111            /**
112             * Override <tt>StreamHandler.close</tt> to do a flush but not
113             * to close the output stream.  That is, we do <b>not</b>
114             * close <tt>System.err</tt>.
115             */
116            public void close() {
117                flush();
118            }
119        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.