LoggingHelperpublic class LoggingHelper extends Object Helper methods for logging. |
Fields Summary |
---|
private final Logger | logger | public static final String | logRoot | public static final String | packageRoot |
Constructors Summary |
---|
public LoggingHelper(Logger logger)
this.logger = logger;
|
Methods Summary |
---|
public static java.lang.String | getLoggerName(java.lang.Class clasz)Forms a logger name by replacing "com.sun.xml.ws" in the name
of the specified class by "javax.enterprise.xml.webservices"
return clasz.getName().replaceFirst( packageRoot, logRoot);
| public void | throwAndLog(java.lang.Class exceptionClass, java.util.logging.Level level, java.lang.String message, boolean stackTrace)Throws an Exception of a given type with a given message. A log
entry logged at the specified level with the same message is also
written
//look for exceptionClass ctors of the form Exception() and Exception(String)
Constructor oneArg = null;
Constructor zeroArg = null;
Constructor[] ctors = exceptionClass.getConstructors();
for (Constructor ctor : ctors) {
Class[] params = ctor.getParameterTypes();
if (params.length == 0) {
zeroArg = ctor;
} else if (params.length == 1 && params[0].equals(String.class)) {
oneArg = ctor;
}
}
//Construct the exception
T exception = null;
try {
if (oneArg != null) {
//use the 1-arg ctor if possible
exception = (T)oneArg.newInstance(message);
} else if (zeroArg == null) {
exception = (T)zeroArg.newInstance();
}
} catch (Throwable e) {
}
//write the log entry
if (logger.isLoggable(level)) {
if (stackTrace && exception != null) {
logger.log(level, message, exception);
} else {
logger.log(level, message);
}
}
//throw the exception
if (exception != null) {
throw exception;
}
| public void | throwAndLog(java.lang.Class exceptionClass, java.util.logging.Level level, java.lang.String message)Same as throwAndLog(Class, Level, String, boolean) with last argument
set to true.
throwAndLog(exceptionClass, level, message, true);
|
|