How to send a stacktrace to log4j?

后端 未结 11 996
失恋的感觉
失恋的感觉 2020-11-29 19:29

Say you catch an exception and get the following on the standard output (like, say, the console) if you do a e.printStackTrace() :

java.io.FileNotFo         


        
11条回答
  •  鱼传尺愫
    2020-11-29 20:07

    this would be good log4j error/exception logging - readable by splunk/other logging/monitoring s/w. everything is form of key-value pair. log4j would get the stack trace from Exception obj e

        try {
              ---
              ---
        } catch (Exception e) {
            log.error("api_name={} method={} _message=\"error description.\" msg={}", 
                      new Object[]{"api_name", "method_name", e.getMessage(), e});
        }
    

提交回复
热议问题