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的变体,上述语句是否正常工作。我不确定,因为我也传递了“身份”。请澄清
答案 0 :(得分:6)
如果不确定,只需使用String#format
创建日志消息:
log.error(String.format("Unable to show status %s", status), e);