[slf4j-user] Use same message in log and Exception

Jeff Jensen jjensen at apache.org
Sun Jul 4 05:18:57 CEST 2010


Is there a better way to make one String to log it and use as exception
message than this?

        final String msg =
                "Asdf asdf asdf qwer={} asdf zxcv={}";
        LOG.error(msg, obj1, obj2);
        final FormattingTuple logMsg =
                MessageFormatter.format(msg, obj1, obj2);
        throw new SomeException(logMsg.getMessage());

It would be useful if the log messages (e.g. error, debug, etc.) returned
the String logged message.  The code above creates the message twice.




More information about the slf4j-user mailing list