001: package org.enhydra.shark.logging;
002:
003: import org.enhydra.shark.api.client.wfmc.wapi.WMSessionHandle;
004: import org.enhydra.shark.api.internal.logging.LoggingManager;
005: import org.enhydra.shark.api.internal.working.CallbackUtilities;
006:
007: import com.lutris.logging.LogChannel;
008: import com.lutris.logging.Logger;
009:
010: /**
011: * Implementation of LoggingManager interface.
012: *
013: * @author Sasa Bojanic
014: * @author Nenad Bogdanovic
015: */
016: public class EnhydraLoggingManager implements LoggingManager {
017:
018: public static final String ENHYDRA_LOG_CLASS = "LogClassName";
019:
020: public static final String ENHYDRA_DEFAULT_LOG_CLASS = "com.lutris.logging.StandardLogger";
021:
022: private static final String DEFAULT_LOG_CHANNEL = "EnhydraLoggingManager.DEFAULT_LOG_CHANNEL";
023:
024: private static String defaultLogChannel = "Enhydra";
025:
026: private CallbackUtilities cus;
027:
028: private Logger standardLogger;
029:
030: /**
031: * Configures StandardLoggingManager.
032: *
033: * @param cus an instance of CallbackUtilities used to get properties for configuring
034: * logging in Shark.
035: * @exception Exception thrown if configuring doesn't succeed.
036: */
037: public void configure(CallbackUtilities cus) throws Exception {
038: this .cus = cus;
039:
040: String logClassName = this .cus.getProperty(
041: EnhydraLoggingManager.ENHYDRA_LOG_CLASS,
042: ENHYDRA_DEFAULT_LOG_CLASS);
043: defaultLogChannel = this .cus.getProperty(DEFAULT_LOG_CHANNEL,
044: defaultLogChannel);
045:
046: standardLogger = (Logger) Class.forName(logClassName, true,
047: this .getClass().getClassLoader()).getConstructor(
048: new Class[] { Boolean.TYPE }).newInstance(
049: new Object[] { new Boolean(true) });
050: }
051:
052: // ////////////////////////////////////////////////////////////////
053: // LoggingManager API implementation
054: // ////////////////////////////////////////////////////////////////
055:
056: /**
057: * Log a message object with the <i>ERROR</i> Level.
058: *
059: * @param msg the message to log.
060: * @exception Exception If something unexpected happens.
061: */
062: public void error(WMSessionHandle shandle, String msg)
063: throws Exception {
064: error(shandle, defaultLogChannel, msg);
065: }
066:
067: /**
068: * Log a message object with the <i>ERROR</i> Level.
069: *
070: * @param msg the message to log.
071: * @param ex the exception to log, including its stack trace.
072: * @exception Exception If something unexpected happens.
073: */
074: public void error(WMSessionHandle shandle, String msg, Exception ex)
075: throws Exception {
076: error(shandle, defaultLogChannel, msg, ex);
077: }
078:
079: /**
080: * Log a message object with the <i>ERROR</i> Level.
081: *
082: * @param channel the log channel to be used for logging.
083: * @param msg the message to log.
084: * @exception Exception If something unexpected happens.
085: */
086: public void error(WMSessionHandle shandle, String channel,
087: String msg) throws Exception {
088: LogChannel logChannel = standardLogger.getChannel(channel);
089: if (logChannel != null)
090: logChannel.write(Logger.ERROR, msg);
091: else
092: throw new Exception("Logger does not exist!");
093:
094: }
095:
096: /**
097: * Log a message object with the <i>ERROR</i> Level.
098: *
099: * @param channel the log channel to be used for logging.
100: * @param msg the message to log.
101: * @param ex the exception to log, including its stack trace.
102: * @exception Exception If something unexpected happens.
103: */
104: public void error(WMSessionHandle shandle, String channel,
105: String msg, Exception ex) throws Exception {
106:
107: LogChannel logChannel = standardLogger.getChannel(channel);
108:
109: if (logChannel != null)
110: logChannel.write(Logger.ERROR, msg, ex);
111: else
112: throw new Exception("Logger does not exist!");
113: }
114:
115: /**
116: * Log a message object with the <i>WARN</i> Level.
117: *
118: * @param msg the message to log.
119: * @exception Exception If something unexpected happens.
120: */
121: public void warn(WMSessionHandle shandle, String msg)
122: throws Exception {
123: warn(shandle, defaultLogChannel, msg);
124: }
125:
126: /**
127: * Log a message object with the <i>WARN</i> Level.
128: *
129: * @param msg the message to log.
130: * @param ex the exception to log, including its stack trace.
131: * @exception Exception If something unexpected happens.
132: */
133: public void warn(WMSessionHandle shandle, String msg, Exception ex)
134: throws Exception {
135: warn(shandle, defaultLogChannel, msg, ex);
136: }
137:
138: /**
139: * Log a message object with the <i>WARN</i> Level.
140: *
141: * @param channel the log channel to be used for logging.
142: * @param msg the message to log.
143: * @exception Exception If something unexpected happens.
144: */
145: public void warn(WMSessionHandle shandle, String channel, String msg)
146: throws Exception {
147: LogChannel logChannel = standardLogger.getChannel(channel);
148: if (logChannel != null)
149: logChannel.write(Logger.WARNING, msg);
150: else
151: throw new Exception("Logger does not exist!");
152: }
153:
154: /**
155: * Log a message object with the <i>WARN</i> Level.
156: *
157: * @param channel the log channel to be used for logging.
158: * @param msg the message to log.
159: * @param ex the exception to log, including its stack trace.
160: * @exception Exception If something unexpected happens.
161: */
162: public void warn(WMSessionHandle shandle, String channel,
163: String msg, Exception ex) throws Exception {
164: LogChannel logChannel = standardLogger.getChannel(channel);
165: if (logChannel != null)
166: logChannel.write(Logger.WARNING, msg, ex);
167: else
168: throw new Exception("Logger does not exist!");
169: }
170:
171: /**
172: * Log a message object with the <i>INFO</i> Level.
173: *
174: * @param msg the message to log.
175: * @exception Exception If something unexpected happens.
176: */
177: public void info(WMSessionHandle shandle, String msg)
178: throws Exception {
179: info(shandle, defaultLogChannel, msg);
180: }
181:
182: /**
183: * Log a message object with the <i>INFO</i> Level.
184: *
185: * @param msg the message to log.
186: * @param ex the exception to log, including its stack trace.
187: * @exception Exception If something unexpected happens.
188: */
189: public void info(WMSessionHandle shandle, String msg, Exception ex)
190: throws Exception {
191: info(shandle, defaultLogChannel, msg, ex);
192: }
193:
194: /**
195: * Log a message object with the <i>INFO</i> Level.
196: *
197: * @param channel the log channel to be used for logging.
198: * @param msg the message to log.
199: * @exception Exception If something unexpected happens.
200: */
201: public void info(WMSessionHandle shandle, String channel, String msg)
202: throws Exception {
203: LogChannel logChannel = standardLogger.getChannel(channel);
204: if (logChannel != null)
205: logChannel.write(Logger.INFO, msg);
206: else
207: throw new Exception("Logger does not exist!");
208: }
209:
210: /**
211: * Log a message object with the <i>INFO</i> Level.
212: *
213: * @param channel the log channel to be used for logging.
214: * @param msg the message to log.
215: * @param ex the exception to log, including its stack trace.
216: * @exception Exception If something unexpected happens.
217: */
218: public void info(WMSessionHandle shandle, String channel,
219: String msg, Exception ex) throws Exception {
220: LogChannel logChannel = standardLogger.getChannel(channel);
221: if (logChannel != null)
222: logChannel.write(Logger.INFO, msg, ex);
223: else
224: throw new Exception("Logger does not exist!");
225: }
226:
227: /**
228: * Log a message object with the <i>DEBUG</i> level.
229: *
230: * @param msg the message to log.
231: * @exception Exception If something unexpected happens.
232: */
233: public void debug(WMSessionHandle shandle, String msg)
234: throws Exception {
235: debug(shandle, defaultLogChannel, msg);
236: }
237:
238: /**
239: * Log a message object with the <i>DEBUG</i> level.
240: *
241: * @param msg the message to log.
242: * @param ex the exception to log, including its stack trace.
243: * @exception Exception If something unexpected happens.
244: */
245: public void debug(WMSessionHandle shandle, String msg, Exception ex)
246: throws Exception {
247: debug(shandle, defaultLogChannel, msg, ex);
248: }
249:
250: /**
251: * Log a message object with the <i>DEBUG</i> level.
252: *
253: * @param channel the log channel to be used for logging.
254: * @param msg the message to log.
255: * @exception Exception If something unexpected happens.
256: */
257: public void debug(WMSessionHandle shandle, String channel,
258: String msg) throws Exception {
259: LogChannel logChannel = standardLogger.getChannel(channel);
260: if (logChannel != null)
261: logChannel.write(Logger.DEBUG, msg);
262: else
263: throw new Exception("Logger does not exist!");
264: }
265:
266: /**
267: * Log a message object with the <i>DEBUG</i> level.
268: *
269: * @param channel the log channel to be used for logging.
270: * @param msg the message to log.
271: * @param ex the exception to log, including its stack trace.
272: * @exception Exception If something unexpected happens.
273: */
274: public void debug(WMSessionHandle shandle, String channel,
275: String msg, Exception ex) throws Exception {
276: LogChannel logChannel = standardLogger.getChannel(channel);
277: if (logChannel != null)
278: logChannel.write(Logger.DEBUG, msg, ex);
279: else
280: throw new Exception("Logger does not exist!");
281: }
282:
283: public boolean isEnabled(WMSessionHandle shandle, int level)
284: throws Exception {
285: LogChannel logChannel = standardLogger
286: .getChannel(defaultLogChannel);
287: return isEnabled(level, logChannel.getLevel(defaultLogChannel));
288: }
289:
290: public boolean isEnabled(WMSessionHandle shandle, String channel,
291: int level) throws Exception {
292: LogChannel logChannel = standardLogger.getChannel(channel);
293: return isEnabled(level, logChannel.getLevel(channel));
294: }
295:
296: protected boolean isEnabled(int sharkLevel, int logerLevel)
297: throws Exception {
298: int shl4jlev = -1;
299: switch (sharkLevel) {
300: case LoggingManager.DEBUG_LEVEL:
301: shl4jlev = Logger.DEBUG;
302: break;
303: case LoggingManager.INFO_LEVEL:
304: shl4jlev = Logger.INFO;
305: break;
306: case LoggingManager.WARN_LEVEL:
307: shl4jlev = Logger.WARNING;
308: break;
309: case LoggingManager.ERROR_LEVEL:
310: shl4jlev = Logger.ERROR;
311: break;
312: case LoggingManager.FATAL_LEVEL:
313: shl4jlev = Logger.EMERGENCY;
314: break;
315: default:
316: throw new Exception("Non-existing shark log level "
317: + sharkLevel);
318: }
319:
320: return shl4jlev >= logerLevel;
321: }
322: }
|