KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sun > jdo > spi > persistence > utility > logging > LoggerJDK13


1 /*
2  * The contents of this file are subject to the terms
3  * of the Common Development and Distribution License
4  * (the License). You may not use this file except in
5  * compliance with the License.
6  *
7  * You can obtain a copy of the license at
8  * https://glassfish.dev.java.net/public/CDDLv1.0.html or
9  * glassfish/bootstrap/legal/CDDLv1.0.txt.
10  * See the License for the specific language governing
11  * permissions and limitations under the License.
12  *
13  * When distributing Covered Code, include this CDDL
14  * Header Notice in each file and include the License file
15  * at glassfish/bootstrap/legal/CDDLv1.0.txt.
16  * If applicable, add the following below the CDDL Header,
17  * with the fields enclosed by brackets [] replaced by
18  * you own identifying information:
19  * "Portions Copyrighted [year] [name of copyright owner]"
20  *
21  * Copyright 2006 Sun Microsystems, Inc. All rights reserved.
22  */

23
24 /*
25  * LoggerJDK13.java
26  *
27  * Created on May 15, 2002, 2:00 PM
28  */

29
30 package com.sun.jdo.spi.persistence.utility.logging;
31
32 import java.io.PrintStream JavaDoc;
33
34 /**
35  * This class provides an implementation of the
36  * com.sun.jdo.spi.persistence.utility.Logger interface which
37  * subclasses the AbstractLogger and provides an implementation of
38  * its abstract methods which logs to a PrintStream (System.out).
39  * Note that this logger doesn't explicitly flush the PrintStream and
40  * depends on the JVM for flushing.
41  *
42  * @author Rochelle Raccah
43  * @version %I%
44  */

45 public class LoggerJDK13 extends AbstractLogger
46 {
47     private static final PrintStream JavaDoc _printStream = System.out;
48
49     /** Creates a new LoggerJDK13. The supplied class loader or the
50      * loader which loaded this class must be able to load the bundle.
51      * @param loggerName the full domain name of this logger
52      * @param bundleName the bundle name for message translation
53      * @param loader the loader used for looking up the bundle file
54      * and possibly the logging.properties or alternative file
55      */

56     public LoggerJDK13 (String JavaDoc loggerName, String JavaDoc bundleName,
57         ClassLoader JavaDoc loader)
58     {
59         super(loggerName, bundleName, loader);
60     }
61
62     private static PrintStream JavaDoc getPrintStream () { return _printStream; }
63
64     /**
65      * Log a message.
66      * <p>
67      * If the logger is currently enabled for the message
68      * level then the given message, and the exception dump,
69      * is forwarded to all the
70      * registered output Handler objects.
71      * <p>
72      * @param level The level for this message
73      * @param msg The string message (or a key in the message catalog)
74      * @param thrown The exception to log
75      */

76     public synchronized void log (int level, String JavaDoc msg, Throwable JavaDoc thrown)
77     {
78         if (isLoggable(level))
79         {
80             logInternal(level, getMessage(msg));
81             thrown.printStackTrace(getPrintStream());
82         }
83     }
84
85     /**
86      * This method does the actual logging. It is expected that if a
87      * check for isLoggable is desired for performance reasons, it has
88      * already been done, as it should not be done here. This
89      * implementation uses a print stream for logging.
90      * @param level the level to print
91      * @param message the message to print
92      */

93     protected synchronized void logInternal (int level, String JavaDoc message)
94     {
95         getPrintStream().println(getMessageWithPrefix(level, message));
96     }
97 }
98
Popular Tags