Answer the question
In order to leave comments, you need to log in
Why is getFormattedMessage() needed?
Can you please tell me what the getFormattedMessage() method does in this case?
private static final MessageFactory MESSAGE_FACTORY = new ReusableMessageFactory();
private static String determineLogMessage(String format, Object... args) {
if (args == null || args.length == 0) {
return forma;
}
return MESSAGE_FACTORY.newMessage(format, args).getFormattedMessage();
}
Answer the question
In order to leave comments, you need to log in
The factory creates a templated message by adding objects, and getFormattedMessage() returns a formatted string.
For example:
String date = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date());
Message message = new ReusableMessageFactory().newMessage("{} Very important message", date);
System.out.println(message.getFormattedMessage());
2021-08-29 16:37:24 Very important message
String date = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date());
Message message = new ReusableMessageFactory().newMessage("{} [{}] Very important message", date, Level.WARN);
System.out.println(message.getFormattedMessage());
as you guessed it will print:2021-08-29 16:43:57 [WARN] Very important message
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question