Skip to content

Commit

Permalink
Add convenient logging methods for logging exceptions quickly
Browse files Browse the repository at this point in the history
.. Mainly useful for writing tests or ad-hoc debugging
  • Loading branch information
trustin committed Dec 8, 2013
1 parent 26979f8 commit 4802c78
Show file tree
Hide file tree
Showing 2 changed files with 93 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;

/**
Expand Down Expand Up @@ -64,6 +66,32 @@ public boolean isEnabled(InternalLogLevel level) {
}
}

@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) {
Expand All @@ -87,6 +115,29 @@ public void log(InternalLogLevel level, String msg, Throwable cause) {
}
}

@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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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?
*
Expand Down Expand Up @@ -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?
*
Expand Down Expand Up @@ -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?
*
Expand Down Expand Up @@ -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?
*
Expand Down Expand Up @@ -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}?
*
Expand Down Expand Up @@ -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);
}

0 comments on commit 4802c78

Please sign in to comment.