KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sun > enterprise > tools > guiframework > util > LogUtil


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 package com.sun.enterprise.tools.guiframework.util;
25
26 import java.util.logging.Level JavaDoc;
27 import java.util.logging.Logger JavaDoc;
28
29
30 /**
31  * This class provides helper methods for logging messages on from within this
32  * framework. These utility methods are meant for internal framework use.
33  */

34 public class LogUtil {
35
36     /**
37      * This helper method logs a framework message at the given log level.
38      *
39      * <UL>
40      * <LI>FINEST indicates a highly detailed tracing message.
41      * <LI>FINER indicates a fairly detailed tracing message.
42      * <LI>FINE is a message level providing tracing information.
43      * <LI>CONFIG is a message level for static configuration messages.
44      * <LI>INFO is a message level for informational messages.
45      * <LI>WARNING is a message level indicating a potential problem.
46      * <LI>SEVERE is a message level indicating a serious failure.
47      * </UL>
48      */

49     public static void log(Level JavaDoc level, String JavaDoc msg, Object JavaDoc[] params) {
50     _logger.log(level, msg, params);
51     }
52
53
54     /**
55      *
56      */

57     public static void log(Level JavaDoc level, String JavaDoc msg, Object JavaDoc param1) {
58     _logger.log(level, msg, param1);
59     }
60
61
62     /**
63      *
64      */

65     public static void log(Level JavaDoc level, String JavaDoc msg) {
66     _logger.log(level, msg);
67     }
68
69
70     /**
71      *
72      */

73     public static void log(Level JavaDoc level, String JavaDoc msg, Throwable JavaDoc thrown) {
74     _logger.log(level, msg, thrown);
75     }
76
77
78     /**
79      * This method is sets to the log Levels which will be logged. Any Level
80      * more severe than the given level will be logged.
81      *
82      * <UL>
83      * <LI>FINEST indicates a highly detailed tracing message.
84      * <LI>FINER indicates a fairly detailed tracing message.
85      * <LI>FINE is a message level providing tracing information.
86      * <LI>CONFIG is a message level for static configuration messages.
87      * <LI>INFO is a message level for informational messages.
88      * <LI>WARNING is a message level indicating a potential problem.
89      * <LI>SEVERE is a message level indicating a serious failure.
90      * </UL>
91      */

92     public static void setLevel(Level JavaDoc level) {
93     _logger.setLevel(level);
94     }
95
96
97     /**
98      * This method is used to determine if the given log Level will be logged.
99      */

100     public static boolean isLoggable(Level JavaDoc level) {
101     return _logger.isLoggable(level);
102     }
103
104
105     /**
106      * This is the Framework logger name
107      */

108     public static final String JavaDoc FRAMEWORK_LOGGER_NAME =
109     "com.sun.enterprise.tools.guiframework";
110
111     /**
112      * This is the bundle name
113      */

114     public static final String JavaDoc BUNDLE_NAME =
115     "LogStrings";
116
117     /**
118      * This is the Logger to use for Framework log messages
119      */

120     public static final Logger JavaDoc _logger = Logger.getLogger(
121     FRAMEWORK_LOGGER_NAME, FRAMEWORK_LOGGER_NAME+"."+BUNDLE_NAME);
122     
123     public static Level JavaDoc stringToLogLevel(String JavaDoc level) {
124         if (level == null)
125             return Level.INFO;
126         if (level.equalsIgnoreCase("FINEST"))
127             return Level.FINEST;
128         if (level.equalsIgnoreCase("FINER"))
129             return Level.FINER;
130         if (level.equalsIgnoreCase("FINE"))
131             return Level.FINE;
132         if (level.equalsIgnoreCase("CONFIG"))
133             return Level.CONFIG;
134         if (level.equalsIgnoreCase("INFO"))
135             return Level.INFO;
136         if (level.equalsIgnoreCase("WARNING"))
137             return Level.WARNING;
138         if (level.equalsIgnoreCase("SEVERE"))
139             return Level.SEVERE;
140         return Level.INFO;
141     }
142     
143
144     /**
145      * The following constants are for the convience of specifying the
146      * equivalent Level constants.
147      */

148     public static final Level JavaDoc FINEST = Level.FINEST;
149     public static final Level JavaDoc FINER = Level.FINER;
150     public static final Level JavaDoc FINE = Level.FINE;
151     public static final Level JavaDoc CONFIG = Level.CONFIG;
152     public static final Level JavaDoc INFO = Level.INFO;
153     public static final Level JavaDoc WARNING = Level.WARNING;
154     public static final Level JavaDoc SEVERE = Level.SEVERE;
155 }
156
Popular Tags