Top Description Inners Fields Constructors Methods
org.apache.logging.log4j.message

public final Class ParameterizedNoReferenceMessageFactory

extends AbstractMessageFactory
Class Inheritance
Imports
org.apache.logging.log4j.status.StatusLogger

Creates FormattedMessage instances for MessageFactory2 methods (and MessageFactory by extension.)

Creates SimpleMessage objects that do not retain a reference to the parameter object.

Intended for use by the StatusLogger: this logger retains a queue of recently logged messages in memory, causing memory leaks in web applications. (LOG4J2-1176)

This class is immutable.

Note to implementors:

This class does not implement any MessageFactory2 methods and lets the superclass funnel those calls through newMessage(String, Object...).

Nested and Inner Type Summary

Modifier and TypeClass and Description
pack-priv static class
ParameterizedNoReferenceMessageFactory.StatusMessage

Message implementation that only keeps a reference to the error text and the error (if any), not to the message parameters, in order to avoid memory leaks.

Field Summary

Modifier and TypeField and Description
public static final ParameterizedNoReferenceMessageFactory
INSTANCE

Instance of ParameterizedStatusMessageFactory.

private static final long

Constructor Summary

AccessConstructor and Description
public
ParameterizedNoReferenceMessageFactory()

Constructs a message factory with default flow strings.

Method Summary

Modifier and TypeMethod and Description
public Message

Returns:

The Message.
newMessage
(final String
The message pattern.
message
,
final Object...
The message parameters.
params
)

Implements org.apache.logging.log4j.message.MessageFactory.newMessage.

Creates SimpleMessage instances containing the formatted parameterized message string.

Inherited from org.apache.logging.log4j.message.AbstractMessageFactory:
newMessagenewMessagenewMessagenewMessagenewMessagenewMessagenewMessagenewMessagenewMessagenewMessagenewMessagenewMessagenewMessage

Field Detail

INSTANCEback to summary
public static final ParameterizedNoReferenceMessageFactory INSTANCE

Instance of ParameterizedStatusMessageFactory.

serialVersionUIDback to summary
private static final long serialVersionUID

Hides org.apache.logging.log4j.message.AbstractMessageFactory.serialVersionUID.

Constructor Detail

ParameterizedNoReferenceMessageFactoryback to summary
public ParameterizedNoReferenceMessageFactory()

Constructs a message factory with default flow strings.

Method Detail

newMessageback to summary
public Message newMessage(final String message, final Object... params)

Implements org.apache.logging.log4j.message.MessageFactory.newMessage.

Creates SimpleMessage instances containing the formatted parameterized message string.

Parameters
message:String

The message pattern.

params:Object[]

The message parameters.

Returns:Message

The Message.

Annotations
@Override
See Also
MessageFactory#newMessage(String, Object...)
org.apache.logging.log4j.message back to summary

pack-priv Class ParameterizedNoReferenceMessageFactory.StatusMessage

extends Object
implements Message
Class Inheritance
  • java.lang.Object
  • org.apache.logging.log4j.message.ParameterizedNoReferenceMessageFactory.StatusMessage
All Implemented Interfaces
org.apache.logging.log4j.message.Message, java.io.Serializable

Message implementation that only keeps a reference to the error text and the error (if any), not to the message parameters, in order to avoid memory leaks. This addresses LOG4J2-1368.
Since
2.6

Field Summary

Modifier and TypeField and Description
private final String
private static final long
private final Throwable

Constructor Summary

AccessConstructor and Description
public
StatusMessage(final String formattedMessage, final Throwable throwable)

Method Summary

Modifier and TypeMethod and Description
public String
getFormat()

Implements org.apache.logging.log4j.message.Message.getFormat.

Gets the format portion of the Message.

public String
getFormattedMessage()

Implements org.apache.logging.log4j.message.Message.getFormattedMessage.

Gets the Message formatted as a String.

public Object[]
getParameters()

Implements org.apache.logging.log4j.message.Message.getParameters.

Gets parameter values, if any.

public Throwable
Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

formattedMessageback to summary
private final String formattedMessage
serialVersionUIDback to summary
private static final long serialVersionUID
throwableback to summary
private final Throwable throwable

Constructor Detail

StatusMessageback to summary
public StatusMessage(final String formattedMessage, final Throwable throwable)

Method Detail

getFormatback to summary
public String getFormat()

Implements org.apache.logging.log4j.message.Message.getFormat.

Doc from org.apache.logging.log4j.message.Message.getFormat.

Gets the format portion of the Message.

Returns:String

The message format. Some implementations, such as ParameterizedMessage, will use this as the message "pattern". Other Messages may simply return an empty String. TODO Do all messages have a format? What syntax? Using a Formatter object could be cleaner. (RG) In SimpleMessage the format is identical to the formatted message. In ParameterizedMessage and StructuredDataMessage it is not. It is up to the Message implementer to determine what this method will return. A Formatter is inappropriate as this is very specific to the Message implementation so it isn't clear to me how having a Formatter separate from the Message would be cleaner.

Annotations
@Override
getFormattedMessageback to summary
public String getFormattedMessage()

Implements org.apache.logging.log4j.message.Message.getFormattedMessage.

Doc from org.apache.logging.log4j.message.Message.getFormattedMessage.

Gets the Message formatted as a String. Each Message implementation determines the appropriate way to format the data encapsulated in the Message. Messages that provide more than one way of formatting the Message will implement MultiformatMessage.

When configured to log asynchronously, this method is called before the Message is queued, unless this message implements ReusableMessage or is annotated with AsynchronouslyFormattable. This gives the Message implementation class a chance to create a formatted message String with the current value of any mutable objects. The intention is that the Message implementation caches this formatted message and returns it on subsequent calls. (See LOG4J2-763.)

When logging synchronously, this method will not be called for Messages that implement the StringBuilderFormattable interface: instead, the formatTo(StringBuilder) method will be called so the Message can format its contents without creating intermediate String objects.

Returns:String

The message String.

Annotations
@Override
getParametersback to summary
public Object[] getParameters()

Implements org.apache.logging.log4j.message.Message.getParameters.

Doc from org.apache.logging.log4j.message.Message.getParameters.

Gets parameter values, if any.

Returns:Object[]

An array of parameter values or null.

Annotations
@Override
getThrowableback to summary
public Throwable getThrowable()

Implements org.apache.logging.log4j.message.Message.getThrowable.

Doc from org.apache.logging.log4j.message.Message.getThrowable.

Gets the throwable, if any.

Returns:Throwable

the throwable or null.

Annotations
@Override