logging - How to log with format, arguments, and thrown? -


in logger, think can't find method reporting formatted message , throwable.

i found

error(string format, object... arguments)  error(string msg, throwable t)  
try {     dosomething(arg1, arg2); } catch (final someexception se) {     logger.error("failed {} , {}", arg1, arg2);     logger.error("failed something", se); } 

is there way this?

logger.error("failed {} , {}", new object[]{arg1, arg2}, se); 

don't afraid, it! slf4j smart enough. if provide more arguments placeholders, logger attempt cast last argument throwable. if succeeds, nice stack trace in log. feature introduced in slf4j version 1.6.0 -- see http://www.slf4j.org/news.html , http://www.slf4j.org/faq.html#paramexception.

usage following works fine:

logger.error("one {} 2 {} error", new object[] { 1, 2, new runtimeexception("stack trace") }); 

starting version 1.7.0 there new varargs overloads, can use

logger.error("one {} 2 {} error", 1, 2, new runtimeexception("stack trace")); 

Comments

Popular posts from this blog

java - Oracle EBS .ClassNotFoundException: oracle.apps.fnd.formsClient.FormsLauncher.class ERROR -

c# - how to use buttonedit in devexpress gridcontrol -

nvd3.js - angularjs-nvd3-directives setting color in legend as well as in chart elements -