2011-08-31 55 views
2
import org.slf4j.Logger; 
import org.slf4j.LoggerFactory; 

    private static final Logger log = LoggerFactory.getLogger(Twitter.class); 

     } catch (TwitterException e) { 
      // It prints the message as well as the exception 
      // log.error("Unable to show status", e); 

      // I would like to pass a status as well as an exception 
      // Is this an appropriate log statement 
      String status = "failed"; 
      log.error("Unable to show status {}", status, e); 
     } 

上述log.error語句是log.error的變體,上述語句是否正常工作。我也不確定,因爲我也通過了「地位」。請澄清如何格式化錯誤日誌中的變量和異常

回答

5

如果不確定,只需使用String#format創建日誌消息:

log.error(String.format("Unable to show status %s", status), e);