java - SLF4J-Logback print root cause message -
i using slf4j logback log error messages. 1 of observations of root cause requires tostring()
instead of getmessage()
. example, if exception wrapped under another, slf4j prints 'null' of root cause instead of exception message indirectly referenced in tostring()
. java util library logs fine. however, have use slf4j-logback. there way overrides default behaviour of slf4j , logback.
class testexception extends exception { private string exceptioncode; private string exceptionmessage; @override public string tostring() { return "testexception [exceptioncode=" + exceptioncode + ", exceptionmessage=" + exceptionmessage + "]"; } } try { testexception testexception = new testexception(); testexception.exceptioncode = "test exception code"; testexception.exceptionmessage = "test exception message"; throw new ioexception("io message", testexception); } catch (exception e) { logger.error("error message ", e); java.util.logging.logger.getanonymouslogger().log(java.util.logging.level.severe, "error message", e); }
output presents with:
// slf4j logging java.io.ioexception: io message @ test.test.testmethod(test.java:224) @ test.test.main(test.java:119) caused by: test.test$1testexception: null @ test.test.testmethod(test.java:221) ... 1 common frames omitted nov 17, 2016 11:52:04 test.test testmethod // java util logging severe: error message java.io.ioexception: io message @ test.test.testmethod(test.java:224) @ test.test.main(test.java:119) caused by: testexception [exceptioncode=test exception code, exceptionmessage=test exception message] @ test.test.testmethod(test.java:221) ... 1 more
Comments
Post a Comment