001: /**********************************************************************
002: Copyright (c) 2004 Andy Jefferson and others. All rights reserved.
003: Licensed under the Apache License, Version 2.0 (the "License");
004: you may not use this file except in compliance with the License.
005: You may obtain a copy of the License at
006:
007: http://www.apache.org/licenses/LICENSE-2.0
008:
009: Unless required by applicable law or agreed to in writing, software
010: distributed under the License is distributed on an "AS IS" BASIS,
011: WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
012: See the License for the specific language governing permissions and
013: limitations under the License.
014:
015: Contributors:
016: ...
017: **********************************************************************/package org.jpox.util;
018:
019: /**
020: * Logging framework for JPOX.
021: * Allows use of Log4J, JDK1.4, or no logging.
022: * Performs a similar role to Apache CommonsLogging yet doesnt need
023: * an extra jar to be present in the CLASSPATH and also allows for no
024: * available logger.
025: *
026: * @version $Revision: 1.24 $
027: **/
028: public abstract class JPOXLogger {
029: /** Log for JDO issues */
030: public static final JPOXLogger JDO;
031:
032: /** Log for JPA issues */
033: public static final JPOXLogger JPA;
034:
035: /** Log for Persistence issues */
036: public static final JPOXLogger PERSISTENCE;
037:
038: /** Log for Lifecycle issues */
039: public static final JPOXLogger LIFECYCLE;
040:
041: /** Log for Query issues */
042: public static final JPOXLogger QUERY;
043:
044: /** Log for REACHABILITY issues */
045: public static final JPOXLogger REACHABILITY;
046:
047: /** Log for METADATA issues */
048: public static final JPOXLogger METADATA;
049:
050: /** Log for MANAGEMENT issues */
051: public static final JPOXLogger MANAGEMENT;
052:
053: /** Log for Cache issues */
054: public static final JPOXLogger CACHE;
055:
056: /** Log for General issues */
057: public static final JPOXLogger GENERAL;
058:
059: /** Log for Transaction issues */
060: public static final JPOXLogger TRANSACTION;
061:
062: /** Log for Connection issues */
063: public static final JPOXLogger CONNECTION;
064:
065: /** Log for JCA issues */
066: public static final JPOXLogger JCA;
067:
068: /** Log for ClassLoading issues */
069: public static final JPOXLogger CLASSLOADING;
070:
071: /** Log for PLUGIN issues */
072: public static final JPOXLogger PLUGIN;
073:
074: /** Log for POID issues */
075: public static final JPOXLogger POID;
076:
077: /** Log for javax.naming issues */
078: public static final JPOXLogger NAMING;
079:
080: /** Log for Datastore issues */
081: public static final JPOXLogger DATASTORE;
082:
083: /** Log for Datastore persistence issues */
084: public static final JPOXLogger DATASTORE_PERSIST;
085:
086: /** Log for Datastore retrieval issues */
087: public static final JPOXLogger DATASTORE_RETRIEVE;
088:
089: /** Log for Datastore Schema issues */
090: public static final JPOXLogger DATASTORE_SCHEMA;
091:
092: /** Log for IDE */
093: public static final JPOXLogger IDE;
094:
095: /** Log for Enhancer */
096: public static final JPOXLogger ENHANCER;
097:
098: /** Log for SchemaTool */
099: public static final JPOXLogger SCHEMATOOL;
100:
101: static {
102: // Set the log type to be used based on what is available from this ClassLoader
103: // Note that we could have registered in the PluginManager but that needs to log too
104: Class loggerClass = org.jpox.util.NullLogger.class;
105: try {
106: JPOXLogger.class.getClassLoader().loadClass(
107: "org.apache.log4j.Logger");
108: loggerClass = org.jpox.util.Log4JLogger.class;
109: } catch (Exception e) {
110: if (JavaUtils.isJRE1_4OrAbove()) {
111: loggerClass = org.jpox.util.JDK14Logger.class;
112: }
113: }
114:
115: // Create the Loggers for our predefined categories
116: // TODO Would be nice to not have to do this, and just allocate them when the first request
117: // comes in for a particular one, but that would impact on all calling methods
118: JDO = getLoggerInstance(loggerClass, "JPOX.JDO");
119: JPA = getLoggerInstance(loggerClass, "JPOX.JPA");
120:
121: PERSISTENCE = getLoggerInstance(loggerClass, "JPOX.Persistence");
122: LIFECYCLE = getLoggerInstance(loggerClass, "JPOX.Lifecycle");
123: QUERY = getLoggerInstance(loggerClass, "JPOX.Query");
124: REACHABILITY = getLoggerInstance(loggerClass,
125: "JPOX.Reachability");
126: METADATA = getLoggerInstance(loggerClass, "JPOX.MetaData");
127: CACHE = getLoggerInstance(loggerClass, "JPOX.Cache");
128: GENERAL = getLoggerInstance(loggerClass, "JPOX.General");
129: TRANSACTION = getLoggerInstance(loggerClass, "JPOX.Transaction");
130: PLUGIN = getLoggerInstance(loggerClass, "JPOX.Plugin");
131: POID = getLoggerInstance(loggerClass, "JPOX.Store.Poid");
132: CLASSLOADING = getLoggerInstance(loggerClass,
133: "JPOX.ClassLoading");
134: NAMING = getLoggerInstance(loggerClass, "JPOX.Naming");
135: MANAGEMENT = getLoggerInstance(loggerClass, "JPOX.Management");
136: CONNECTION = getLoggerInstance(loggerClass, "JPOX.Connection");
137: JCA = getLoggerInstance(loggerClass, "JPOX.JCA");
138:
139: DATASTORE = getLoggerInstance(loggerClass, "JPOX.Datastore");
140: DATASTORE_PERSIST = getLoggerInstance(loggerClass,
141: "JPOX.Datastore.Persist");
142: DATASTORE_RETRIEVE = getLoggerInstance(loggerClass,
143: "JPOX.Datastore.Retrieve");
144: DATASTORE_SCHEMA = getLoggerInstance(loggerClass,
145: "JPOX.Datastore.Schema");
146:
147: IDE = getLoggerInstance(loggerClass, "JPOX.IDE");
148: ENHANCER = getLoggerInstance(loggerClass, "JPOX.Enhancer");
149: SCHEMATOOL = getLoggerInstance(loggerClass, "JPOX.SchemaTool");
150: }
151:
152: /**
153: * Method to create a logger instance.
154: * @param loggerClass The logger class
155: * @param logCategory The category (or null)
156: * @return The logger
157: */
158: private static JPOXLogger getLoggerInstance(Class loggerClass,
159: String logCategory) {
160: return (JPOXLogger) ClassUtils.newInstance(loggerClass,
161: new Class[] { String.class },
162: new Object[] { logCategory });
163: }
164:
165: /**
166: * Log a debug message.
167: * @param msg The message
168: */
169: public abstract void debug(Object msg);
170:
171: /**
172: * Log a debug message with throwable.
173: * @param msg The message
174: * @param thr A throwable
175: */
176: public abstract void debug(Object msg, Throwable thr);
177:
178: /**
179: * Log an info message.
180: * @param msg The message
181: */
182: public abstract void info(Object msg);
183:
184: /**
185: * Log an info message with throwable.
186: * @param msg The message
187: * @param thr A throwable
188: */
189: public abstract void info(Object msg, Throwable thr);
190:
191: /**
192: * Log a warning message.
193: * @param msg The message
194: */
195: public abstract void warn(Object msg);
196:
197: /**
198: * Log a warning message with throwable.
199: * @param msg The message
200: * @param thr A throwable
201: */
202: public abstract void warn(Object msg, Throwable thr);
203:
204: /**
205: * Log an error message.
206: * @param msg The message
207: */
208: public abstract void error(Object msg);
209:
210: /**
211: * Log an error message with throwable.
212: * @param msg The message
213: * @param thr A throwable
214: */
215: public abstract void error(Object msg, Throwable thr);
216:
217: /**
218: * Log a fatal message.
219: * @param msg The message
220: */
221: public abstract void fatal(Object msg);
222:
223: /**
224: * Log a fatal message with throwable.
225: * @param msg The message
226: * @param thr A throwable
227: */
228: public abstract void fatal(Object msg, Throwable thr);
229:
230: /**
231: * Accessor for whether debug logging is enabled
232: * @return Whether it is enabled
233: */
234: public abstract boolean isDebugEnabled();
235:
236: /**
237: * Accessor for whether info logging is enabled
238: * @return Whether it is enabled
239: */
240: public abstract boolean isInfoEnabled();
241: }
|