Add convenient logging methods for logging exceptions quickly

.. Mainly useful for writing tests or ad-hoc debugging
This commit is contained in:
Trustin Lee 2013-12-08 13:20:52 +09:00
parent 9840de82f0
commit 516795fcfb
2 changed files with 93 additions and 0 deletions

View File

@ -29,6 +29,8 @@ public abstract class AbstractInternalLogger implements InternalLogger, Serializ
private static final long serialVersionUID = -6382972526573193470L;
private static final String EXCEPTION_MESSAGE = "Unexpected exception:";
private final String name;
/**
@ -64,6 +66,32 @@ public abstract class AbstractInternalLogger implements InternalLogger, Serializ
}
}
@Override
public void trace(Throwable t) {
trace(EXCEPTION_MESSAGE, t);
}
@Override
public void debug(Throwable t) {
debug(EXCEPTION_MESSAGE, t);
}
@Override
public void info(Throwable t) {
info(EXCEPTION_MESSAGE, t);
}
@Override
public void warn(Throwable t) {
warn(EXCEPTION_MESSAGE, t);
}
@Override
public void error(Throwable t) {
error(EXCEPTION_MESSAGE, t);
}
@Override
public void log(InternalLogLevel level, String msg, Throwable cause) {
switch (level) {
@ -87,6 +115,29 @@ public abstract class AbstractInternalLogger implements InternalLogger, Serializ
}
}
@Override
public void log(InternalLogLevel level, Throwable cause) {
switch (level) {
case TRACE:
trace(cause);
break;
case DEBUG:
debug(cause);
break;
case INFO:
info(cause);
break;
case WARN:
warn(cause);
break;
case ERROR:
error(cause);
break;
default:
throw new Error();
}
}
@Override
public void log(InternalLogLevel level, String msg) {
switch (level) {

View File

@ -116,6 +116,13 @@ public interface InternalLogger {
*/
void trace(String msg, Throwable t);
/**
* Log an exception (throwable) at the TRACE level.
*
* @param t the exception (throwable) to log
*/
void trace(Throwable t);
/**
* Is the logger instance enabled for the DEBUG level?
*
@ -181,6 +188,13 @@ public interface InternalLogger {
*/
void debug(String msg, Throwable t);
/**
* Log an exception (throwable) at the DEBUG level.
*
* @param t the exception (throwable) to log
*/
void debug(Throwable t);
/**
* Is the logger instance enabled for the INFO level?
*
@ -246,6 +260,13 @@ public interface InternalLogger {
*/
void info(String msg, Throwable t);
/**
* Log an exception (throwable) at the INFO level.
*
* @param t the exception (throwable) to log
*/
void info(Throwable t);
/**
* Is the logger instance enabled for the WARN level?
*
@ -311,6 +332,13 @@ public interface InternalLogger {
*/
void warn(String msg, Throwable t);
/**
* Log an exception (throwable) at the WARN level.
*
* @param t the exception (throwable) to log
*/
void warn(Throwable t);
/**
* Is the logger instance enabled for the ERROR level?
*
@ -376,6 +404,13 @@ public interface InternalLogger {
*/
void error(String msg, Throwable t);
/**
* Log an exception (throwable) at the ERROR level.
*
* @param t the exception (throwable) to log
*/
void error(Throwable t);
/**
* Is the logger instance enabled for the specified {@code level}?
*
@ -441,4 +476,11 @@ public interface InternalLogger {
* @param t the exception (throwable) to log
*/
void log(InternalLogLevel level, String msg, Throwable t);
/**
* Log an exception (throwable) at the specified {@code level}.
*
* @param t the exception (throwable) to log
*/
void log(InternalLogLevel level, Throwable t);
}