KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > xdoclet > modules > ojb > LogHelper


1 package xdoclet.modules.ojb;
2
3 /* Copyright 2004-2005 The Apache Software Foundation
4  *
5  * Licensed under the Apache License, Version 2.0 (the "License");
6  * you may not use this file except in compliance with the License.
7  * You may obtain a copy of the License at
8  *
9  * http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  */

17
18 import org.apache.commons.logging.Log;
19 import org.apache.commons.logging.LogFactory;
20
21 /**
22  * Helper class for logging and message output.
23  *
24  * @author <a HREF="mailto:tomdz@users.sourceforge.net">Thomas Dudziak (tomdz@users.sourceforge.net)</a>
25  */

26 public class LogHelper
27 {
28     /**
29      * Logs the given debug message to stdout (if verbose is on) and to the log for the given class
30      * (if the log level has been set to debug or higher).
31      *
32      * @param alsoStdout Whether to also put the message to stdout
33      * @param clazz The clazz
34      * @param posInfo The position info, e.g. method name
35      * @param msg The message
36      */

37     public static void debug(boolean alsoStdout, Class JavaDoc clazz, String JavaDoc posInfo, Object JavaDoc msg)
38     {
39         if (alsoStdout)
40         {
41             System.out.println(msg.toString());
42         }
43
44         String JavaDoc name = clazz.getName();
45
46         if (posInfo != null)
47         {
48             name += "." + posInfo;
49         }
50
51         Log log = LogFactory.getLog(name);
52
53         if (log.isDebugEnabled())
54         {
55             log.debug(msg);
56         }
57     }
58
59     /**
60      * Logs the given warning to stdout and to the log for the given class
61      * (if the log level has been set to warn or higher).
62      *
63      * @param alsoStdout Whether to also put the message to stdout
64      * @param clazz The clazz
65      * @param posInfo The position info, e.g. method name
66      * @param msg The message
67      */

68     public static void warn(boolean alsoStdout, Class JavaDoc clazz, String JavaDoc posInfo, Object JavaDoc msg)
69     {
70         if (alsoStdout)
71         {
72             System.out.println("Warning: "+msg.toString());
73         }
74
75         String JavaDoc name = clazz.getName();
76
77         if (posInfo != null)
78         {
79             name += "." + posInfo;
80         }
81
82         Log log = LogFactory.getLog(name);
83
84         if (log.isWarnEnabled())
85         {
86             log.warn(msg);
87         }
88     }
89 }
90
Popular Tags