In my custom exception class I've overridden toString()
:
@Override
public String toString() {
final String msg = getLocalizedMessage();
// base
String str = getClass().getName() + ": [" + code + "]";
// message
if (msg != null)
str += " " + msg;
// extra
if (extra != null) {
str += '\n' + extra.toString();
}
return str;
}
(yes, I'm aware I should use StringBuilder
there)
However, when I log such an exception (via org.slf4j.Logger.warn(String msg, Throwable err)
) the output is as for vanilla exceptions:
webersg.util.service.ServiceError: null
at webersg.util.service.ServiceTools.decodeException(ServiceTools.java:39) ~[bin/:na]
at tr.silvercar.rummikub.robot.LobbyConnection.sendRequestTo(LobbyConnection.java:143) ~[bin/:na]
at tr.silvercar.rummikub.robot.LobbyConnection.sendRequest(LobbyConnection.java:98) ~[bin/:na]
at tr.silvercar.rummikub.robot.Robot.<init>(Robot.java:32) ~[bin/:na]
at tr.silvercar.rummikub.robot.RobotController.start(RobotController.java:81) ~[bin/:na]
at tr.silvercar.rummikub.robot.runners.LocalAltinRobot.main(LocalSilverRobot.java:132) [bin/:na]
How can I get my extra data to appear? My log implementation is Logback.