Multiple java.util exceptions while logging message that contains "%" with Log.log() function

Multiple java.util exceptions while logging message that contains "%" with Log.log() function

book

Article ID: KB0089455

calendar_today

Updated On:

Products Versions
TIBCO BusinessEvents Enterprise Edition -
Not Applicable -

Description

Description:
We are facing a problem in our production environment while logging the incoming message with Log.log() function. The code we used to do the logging follows:

Log.log(loggerName, "Info", loggingMessage);

While the loggingMessage contains "%", we are seeing the following java.util exceptions in the Inference engines:

java.util.UnknownFormatConversionException
java.util.FormatFlagsConversionMismatchException
java.util.MissingFormatArgumentException

Issue/Introduction

Multiple java.util exceptions while logging message that contains "%" with Log.log() function

Resolution

The message argument to Log.log() is a "format" string. In a format string, the character "%" is the beginning of a "format specifier". If  the message you are going to log has "%" in the content, and you want to do the log line as is, instead of passing the logging message with the message parameter you will need to pass the logging message with the argument parameter.

For example, instead of:

Log.log(loggerName, logLevel, "something with % inside");

Use:

String formatString = "%1$s";
Log.log(loggerName, logLevel, formatString, "something with % inside");

Here, the format string "%1$s" is a simple format and means log is the first argument.

See http://docs.oracle.com/javase/7/docs/api/java/util/Formatter.html#syntax for details.

Additional Information

http://docs.oracle.com/javase/7/docs/api/java/util/Formatter.html#syntax