KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sun > enterprise > config > backup > LoggerHelper


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  * LoggerHelper.java
26  *
27  * Created on January 20, 2004, 5:55 PM
28  *
29  * @author bnevins
30  * <BR> <I>$Source: /cvs/glassfish/admin/backup/src/java/com/sun/enterprise/config/backup/LoggerHelper.java,v $
31  *
32  * Copyright 2000-2001 by iPlanet/Sun Microsystems, Inc.,
33  * 901 San Antonio Road, Palo Alto, California, 94303, U.S.A.
34  * All rights reserved.
35  *
36  * This software is the confidential and proprietary information
37  * of iPlanet/Sun Microsystems, Inc. ("Confidential Information").
38  * You shall not disclose such Confidential Information and shall
39  * use it only in accordance with the terms of the license
40  * agreement you entered into with iPlanet/Sun Microsystems.
41  *
42  */

43
44 package com.sun.enterprise.config.backup;
45
46 import java.util.logging.*;
47
48 // Resource Bundle:
49
// com/sun/logging/enterprise/system/tools/deployment/backend/LogStrings.properties
50

51 class LoggerHelper
52 {
53     private LoggerHelper()
54     {
55     }
56     
57     ///////////////////////////////////////////////////////////////////////////
58

59     final static Logger get()
60     {
61         // the final should cause this to be inlined...
62
return logger;
63     }
64     
65     ///////////////////////////////////////////////////////////////////////////
66

67     final static void setLevel(BackupRequest req)
68     {
69         // the final should cause this to be inlined...
70
if(req.terse)
71             logger.setLevel(Level.WARNING);
72         else if(req.verbose)
73             logger.setLevel(Level.FINEST);
74         else
75             logger.setLevel(Level.INFO);
76         
77         /* test logging messages
78          String me = System.getProperty("user.name");
79         if(me != null && me.equals("bnevins"))
80         {
81             logger.finest("finest");
82             logger.finer("finer");
83             logger.fine("fine");
84             logger.info("info");
85             logger.warning("warning");
86             logger.severe("severe");
87         }
88          **/

89     }
90
91     ///////////////////////////////////////////////////////////////////////////
92
//////// Convenience methods ///////////////////////////////
93
///////////////////////////////////////////////////////////////////////////
94

95     final static void finest(String JavaDoc s) { logger.finest(s); }
96     final static void finest(String JavaDoc s, Object JavaDoc o) { logger.log(Level.FINEST, s, new Object JavaDoc[] { o }); }
97     final static void finer(String JavaDoc s) { logger.finer(s); }
98     final static void finer(String JavaDoc s, Object JavaDoc o) { logger.log(Level.FINER, s, new Object JavaDoc[] { o }); }
99     final static void fine(String JavaDoc s) { logger.fine(s); }
100     final static void fine(String JavaDoc s, Object JavaDoc o) { logger.log(Level.FINE, s, new Object JavaDoc[] { o }); }
101     final static void info(String JavaDoc s) { logger.info(s); }
102     final static void info(String JavaDoc s, Object JavaDoc o) { logger.log(Level.INFO, s, new Object JavaDoc[] { o }); }
103     final static void warning(String JavaDoc s) { logger.warning(s); }
104     final static void warning(String JavaDoc s, Object JavaDoc o) { logger.log(Level.WARNING, s, new Object JavaDoc[] { o }); }
105     final static void severe(String JavaDoc s) { logger.severe(s); }
106     final static void severe(String JavaDoc s, Object JavaDoc o) { logger.log(Level.SEVERE, s, new Object JavaDoc[] { o }); }
107     
108     ///////////////////////////////////////////////////////////////////////////
109

110     private static Logger logger = null;
111
112     static
113     {
114         try
115         {
116             //System.setProperty("java.util.logging.ConsoleHandler.level", Constants.logLevel);
117
logger = Logger.getLogger("backup", Constants.loggingResourceBundle);
118             
119             // attach a handler that will at least be capable of spitting out FINEST messages
120
// the Level of the Logger itself will determine what the handler actually gets...
121
Handler h = new ConsoleHandler();
122             h.setLevel(Level.FINEST);
123             logger.addHandler(h);
124         }
125         catch(Throwable JavaDoc t)
126         {
127             try
128             {
129                 logger = Logger.getLogger("backup");
130                 logger.warning("Couldn't create Backup Logger with a resource bundle. Created a Logger without a Resource Bundle.");
131             }
132             catch(Throwable JavaDoc t2)
133             {
134                 // now what?
135
}
136         }
137     }
138 }
139
140
Popular Tags