Add convenient logging methods for logging exceptions quickly
.. Mainly useful for writing tests or ad-hoc debugging
This commit is contained in:
parent
9840de82f0
commit
516795fcfb
@ -29,6 +29,8 @@ public abstract class AbstractInternalLogger implements InternalLogger, Serializ
|
|||||||
|
|
||||||
private static final long serialVersionUID = -6382972526573193470L;
|
private static final long serialVersionUID = -6382972526573193470L;
|
||||||
|
|
||||||
|
private static final String EXCEPTION_MESSAGE = "Unexpected exception:";
|
||||||
|
|
||||||
private final String name;
|
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
|
@Override
|
||||||
public void log(InternalLogLevel level, String msg, Throwable cause) {
|
public void log(InternalLogLevel level, String msg, Throwable cause) {
|
||||||
switch (level) {
|
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
|
@Override
|
||||||
public void log(InternalLogLevel level, String msg) {
|
public void log(InternalLogLevel level, String msg) {
|
||||||
switch (level) {
|
switch (level) {
|
||||||
|
@ -116,6 +116,13 @@ public interface InternalLogger {
|
|||||||
*/
|
*/
|
||||||
void trace(String msg, Throwable t);
|
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?
|
* Is the logger instance enabled for the DEBUG level?
|
||||||
*
|
*
|
||||||
@ -181,6 +188,13 @@ public interface InternalLogger {
|
|||||||
*/
|
*/
|
||||||
void debug(String msg, Throwable t);
|
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?
|
* Is the logger instance enabled for the INFO level?
|
||||||
*
|
*
|
||||||
@ -246,6 +260,13 @@ public interface InternalLogger {
|
|||||||
*/
|
*/
|
||||||
void info(String msg, Throwable t);
|
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?
|
* Is the logger instance enabled for the WARN level?
|
||||||
*
|
*
|
||||||
@ -311,6 +332,13 @@ public interface InternalLogger {
|
|||||||
*/
|
*/
|
||||||
void warn(String msg, Throwable t);
|
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?
|
* Is the logger instance enabled for the ERROR level?
|
||||||
*
|
*
|
||||||
@ -376,6 +404,13 @@ public interface InternalLogger {
|
|||||||
*/
|
*/
|
||||||
void error(String msg, Throwable t);
|
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}?
|
* Is the logger instance enabled for the specified {@code level}?
|
||||||
*
|
*
|
||||||
@ -441,4 +476,11 @@ public interface InternalLogger {
|
|||||||
* @param t the exception (throwable) to log
|
* @param t the exception (throwable) to log
|
||||||
*/
|
*/
|
||||||
void log(InternalLogLevel level, String msg, Throwable t);
|
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);
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user