slf4j: how to log formatted message, object array, exception

后端 未结 2 742
小蘑菇
小蘑菇 2020-12-04 05:26

What is the correct approach to log both a populated message and a stack trace of the exception?

logger.error(
    \"\\ncontext info one two three: {} {} {}\         


        
2条回答
  •  余生分开走
    2020-12-04 05:44

    In addition to @Ceki 's answer, If you are using logback and setup a config file in your project (usually logback.xml), you can define the log to plot the stack trace as well using

    
        %date |%-5level| [%thread] [%file:%line] - %msg%n%ex{full} 
    
    

    the %ex in pattern is what makes the difference

提交回复
热议问题