[slf4j-dev] Design of MessageFormatter

Boris Unckel boris.unckel.mlg at gmx.net
Thu Dec 29 21:06:06 CET 2005


A first DRAFT of a solution in x4juli, solving the symptom not the reason.

    /**
     * Method especially for public slf4j log methods which have an object
or object[]
     * as parameter for the message formatting.
     * @param level is not allowed to be null.
     * @param message to format with args to complete logging.
     * @param args for message format.
     * @since 0.7
     */
    protected void robustLogSlf4j(final Level level, final String message,
Object[] args){
        String mes = null;
        try {
            mes = org.slf4j.impl.MessageFormatter.arrayFormat(message,
args);
        } catch (Exception e) {
            mes = message + " Error in formatting message["+e+"]";
        }
        LogRecord logRecord = new ExtendedLogRecordImpl(level, mes);
        completeLogRecord((ExtendedLogRecord)logRecord);
        super.log(logRecord);
    }



More information about the slf4j-dev mailing list