01: package xdoclet.modules.ojb;
02:
03: /* Copyright 2004-2005 The Apache Software Foundation
04: *
05: * Licensed under the Apache License, Version 2.0 (the "License");
06: * you may not use this file except in compliance with the License.
07: * You may obtain a copy of the License at
08: *
09: * 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: * Logs the given debug message to stdout (if verbose is on) and to the log for the given class
29: * (if the log level has been set to debug or higher).
30: *
31: * @param alsoStdout Whether to also put the message to stdout
32: * @param clazz The clazz
33: * @param posInfo The position info, e.g. method name
34: * @param msg The message
35: */
36: public static void debug(boolean alsoStdout, Class clazz,
37: String posInfo, Object msg) {
38: if (alsoStdout) {
39: System.out.println(msg.toString());
40: }
41:
42: String name = clazz.getName();
43:
44: if (posInfo != null) {
45: name += "." + posInfo;
46: }
47:
48: Log log = LogFactory.getLog(name);
49:
50: if (log.isDebugEnabled()) {
51: log.debug(msg);
52: }
53: }
54:
55: /**
56: * Logs the given warning to stdout and to the log for the given class
57: * (if the log level has been set to warn or higher).
58: *
59: * @param alsoStdout Whether to also put the message to stdout
60: * @param clazz The clazz
61: * @param posInfo The position info, e.g. method name
62: * @param msg The message
63: */
64: public static void warn(boolean alsoStdout, Class clazz,
65: String posInfo, Object msg) {
66: if (alsoStdout) {
67: System.out.println("Warning: " + msg.toString());
68: }
69:
70: String name = clazz.getName();
71:
72: if (posInfo != null) {
73: name += "." + posInfo;
74: }
75:
76: Log log = LogFactory.getLog(name);
77:
78: if (log.isWarnEnabled()) {
79: log.warn(msg);
80: }
81: }
82: }
|