开发者

How to format the error log with a variable and an exception

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);
        }

The above log.error statement is a variant of log.error, will the above statement work properly. I am not sure since I am passing "status" also. Kindly clarify


If unsure, simply use String#format to create the log message:

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

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜