Package de.galan.commons.logging
Class PayloadContextMessage
- java.lang.Object
-
- de.galan.commons.logging.PayloadContextMessage
-
- All Implemented Interfaces:
Serializable,org.apache.logging.log4j.message.Message
public class PayloadContextMessage extends Object implements org.apache.logging.log4j.message.Message
Log4j2 Message for Logger that support parameterized messages, using {} as placeholder, eg.:
info("Hello {}", "world"); // => "Hello {world}"
info("Hello {} {}", "beautiful", "world"); // => "Hello {beautiful} {world}"
error("Something failed: {}", ex, "do'h"); // => "Hello {beautiful} {world}"
If the parameters should be available as json-encoded metadata for eg. logstash, you can provide names to the parameters. Example:
info("Hello {location}", "world"); // ThreadContext will provide the json in a field called "payload"
- See Also:
- Serialized Form
-
-
Constructor Summary
Constructors Constructor Description PayloadContextMessage(String messagePattern, Object[] argumentsObject)PayloadContextMessage(String messagePattern, Object[] argumentsObject, Throwable throwable)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected String[]argumentsToStrings(Object[] argumentsObject)protected StringconvertToString(Object object)StringgetFormat()StringgetFormattedMessage()Object[]getParameters()protected intgetPatternAmountArguments()ThrowablegetThrowable()protected voidparseMessage(String messagePattern)
-
-
-
Method Detail
-
parseMessage
protected void parseMessage(String messagePattern)
-
getPatternAmountArguments
protected int getPatternAmountArguments()
-
getFormattedMessage
public String getFormattedMessage()
- Specified by:
getFormattedMessagein interfaceorg.apache.logging.log4j.message.Message
-
getFormat
public String getFormat()
- Specified by:
getFormatin interfaceorg.apache.logging.log4j.message.Message
-
getParameters
public Object[] getParameters()
- Specified by:
getParametersin interfaceorg.apache.logging.log4j.message.Message
-
getThrowable
public Throwable getThrowable()
- Specified by:
getThrowablein interfaceorg.apache.logging.log4j.message.Message
-
-