On Wed, Jun 25, 2014 at 12:01 PM, Remko Popma <[email protected]> wrote:
> Gary, can you add a note of this public API change in changes.xml? > Done: Committed revision 1605486. Gary > > > On Thu, Jun 26, 2014 at 12:27 AM, <[email protected]> wrote: > >> Author: ggregory >> Date: Wed Jun 25 15:27:32 2014 >> New Revision: 1605450 >> >> URL: http://svn.apache.org/r1605450 >> Log: >> Make org.apache.logging.log4j.core.layout.AbstractLayout immutable. >> >> Modified: >> >> logging/log4j/log4j2/trunk/log4j-core/src/main/java/org/apache/logging/log4j/core/layout/AbstractLayout.java >> >> logging/log4j/log4j2/trunk/log4j-core/src/main/java/org/apache/logging/log4j/core/layout/AbstractStringLayout.java >> >> logging/log4j/log4j2/trunk/log4j-core/src/main/java/org/apache/logging/log4j/core/layout/PatternLayout.java >> >> logging/log4j/log4j2/trunk/log4j-core/src/main/java/org/apache/logging/log4j/core/layout/SerializedLayout.java >> >> Modified: >> logging/log4j/log4j2/trunk/log4j-core/src/main/java/org/apache/logging/log4j/core/layout/AbstractLayout.java >> URL: >> http://svn.apache.org/viewvc/logging/log4j/log4j2/trunk/log4j-core/src/main/java/org/apache/logging/log4j/core/layout/AbstractLayout.java?rev=1605450&r1=1605449&r2=1605450&view=diff >> >> ============================================================================== >> --- >> logging/log4j/log4j2/trunk/log4j-core/src/main/java/org/apache/logging/log4j/core/layout/AbstractLayout.java >> (original) >> +++ >> logging/log4j/log4j2/trunk/log4j-core/src/main/java/org/apache/logging/log4j/core/layout/AbstractLayout.java >> Wed Jun 25 15:27:32 2014 >> @@ -24,24 +24,44 @@ import org.apache.logging.log4j.status.S >> >> /** >> * Abstract base class for Layouts. >> - * @param <T> The Class that the Layout will format the LogEvent into. >> + * >> + * @param <T> >> + * The Class that the Layout will format the LogEvent into. >> */ >> public abstract class AbstractLayout<T extends Serializable> implements >> Layout<T> { >> + >> + /** >> + * Constructs a layout with an optional header and footer. >> + * >> + * @param header >> + * The header to include when the stream is opened. May be >> null. >> + * @param footer >> + * The footer to add when the stream is closed. May be null. >> + */ >> + public AbstractLayout(byte[] header, byte[] footer) { >> + super(); >> + this.header = header; >> + this.footer = footer; >> + } >> + >> /** >> * Allow subclasses access to the status logger without creating >> another instance. >> */ >> protected static final Logger LOGGER = StatusLogger.getLogger(); >> + >> /** >> * The header to include when the stream is opened. May be null. >> */ >> - protected byte[] header; >> + protected final byte[] header; >> + >> /** >> * The footer to add when the stream is closed. May be null. >> */ >> - protected byte[] footer; >> + protected final byte[] footer; >> >> /** >> * Returns the header, if one is available. >> + * >> * @return A byte array containing the header. >> */ >> @Override >> @@ -50,27 +70,12 @@ public abstract class AbstractLayout<T e >> } >> >> /** >> - * Set the header. >> - * @param header The header. >> - */ >> - public void setHeader(final byte[] header) { >> - this.header = header; >> - } >> - >> - /** >> * Returns the footer, if one is available. >> + * >> * @return A byte array containing the footer. >> */ >> @Override >> public byte[] getFooter() { >> return footer; >> } >> - >> - /** >> - * Set the footer. >> - * @param footer The footer. >> - */ >> - public void setFooter(final byte[] footer) { >> - this.footer = footer; >> - } >> } >> >> Modified: >> logging/log4j/log4j2/trunk/log4j-core/src/main/java/org/apache/logging/log4j/core/layout/AbstractStringLayout.java >> URL: >> http://svn.apache.org/viewvc/logging/log4j/log4j2/trunk/log4j-core/src/main/java/org/apache/logging/log4j/core/layout/AbstractStringLayout.java?rev=1605450&r1=1605449&r2=1605450&view=diff >> >> ============================================================================== >> --- >> logging/log4j/log4j2/trunk/log4j-core/src/main/java/org/apache/logging/log4j/core/layout/AbstractStringLayout.java >> (original) >> +++ >> logging/log4j/log4j2/trunk/log4j-core/src/main/java/org/apache/logging/log4j/core/layout/AbstractStringLayout.java >> Wed Jun 25 15:27:32 2014 >> @@ -31,14 +31,20 @@ public abstract class AbstractStringLayo >> */ >> private final Charset charset; >> >> - protected AbstractStringLayout(final Charset charset) { >> + protected AbstractStringLayout(final Charset charset, byte[] header, >> byte[] footer) { >> + super(header, footer); >> this.charset = charset == null ? Charsets.UTF_8 : charset; >> } >> >> + protected AbstractStringLayout(final Charset charset) { >> + this(charset, null, null); >> + } >> + >> /** >> * Formats the Log Event as a byte array. >> * >> - * @param event The Log Event. >> + * @param event >> + * The Log Event. >> * @return The formatted event as a byte array. >> */ >> @Override >> >> Modified: >> logging/log4j/log4j2/trunk/log4j-core/src/main/java/org/apache/logging/log4j/core/layout/PatternLayout.java >> URL: >> http://svn.apache.org/viewvc/logging/log4j/log4j2/trunk/log4j-core/src/main/java/org/apache/logging/log4j/core/layout/PatternLayout.java?rev=1605450&r1=1605449&r2=1605450&view=diff >> >> ============================================================================== >> --- >> logging/log4j/log4j2/trunk/log4j-core/src/main/java/org/apache/logging/log4j/core/layout/PatternLayout.java >> (original) >> +++ >> logging/log4j/log4j2/trunk/log4j-core/src/main/java/org/apache/logging/log4j/core/layout/PatternLayout.java >> Wed Jun 25 15:27:32 2014 >> @@ -114,7 +114,7 @@ public final class PatternLayout extends >> private PatternLayout(final Configuration config, final >> RegexReplacement replace, final String pattern, >> final Charset charset, final boolean >> alwaysWriteExceptions, final boolean noConsoleNoAnsi, >> final String header, final String footer) { >> - super(charset); >> + super(charset, toBytes(header, charset), toBytes(footer, >> charset)); >> this.replace = replace; >> this.conversionPattern = pattern; >> this.config = config; >> @@ -122,21 +122,13 @@ public final class PatternLayout extends >> this.noConsoleNoAnsi = noConsoleNoAnsi; >> final PatternParser parser = createPatternParser(config); >> this.formatters = parser.parse(pattern == null ? >> DEFAULT_CONVERSION_PATTERN : pattern, this.alwaysWriteExceptions, >> this.noConsoleNoAnsi); >> - if (charset != null) { >> - if (header != null) { >> - setHeader(header.getBytes(charset)); >> - } >> - if (footer != null) { >> - setFooter(footer.getBytes(charset)); >> - } >> - } else { >> - if (header != null) { >> - setHeader(header.getBytes()); >> - } >> - if (footer != null) { >> - setFooter(footer.getBytes()); >> - } >> + } >> + >> + private static byte[] toBytes(String str, Charset charset) { >> + if (str != null) { >> + return str.getBytes(charset != null ? charset : >> Charset.defaultCharset()); >> } >> + return null; >> } >> >> private byte[] strSubstitutorReplace(final byte... b) { >> >> Modified: >> logging/log4j/log4j2/trunk/log4j-core/src/main/java/org/apache/logging/log4j/core/layout/SerializedLayout.java >> URL: >> http://svn.apache.org/viewvc/logging/log4j/log4j2/trunk/log4j-core/src/main/java/org/apache/logging/log4j/core/layout/SerializedLayout.java?rev=1605450&r1=1605449&r2=1605450&view=diff >> >> ============================================================================== >> --- >> logging/log4j/log4j2/trunk/log4j-core/src/main/java/org/apache/logging/log4j/core/layout/SerializedLayout.java >> (original) >> +++ >> logging/log4j/log4j2/trunk/log4j-core/src/main/java/org/apache/logging/log4j/core/layout/SerializedLayout.java >> Wed Jun 25 15:27:32 2014 >> @@ -47,6 +47,7 @@ public final class SerializedLayout exte >> } >> >> private SerializedLayout() { >> + super(null, null); >> } >> >> /** >> >> >> > -- E-Mail: [email protected] | [email protected] Java Persistence with Hibernate, Second Edition <http://www.manning.com/bauer3/> JUnit in Action, Second Edition <http://www.manning.com/tahchiev/> Spring Batch in Action <http://www.manning.com/templier/> Blog: http://garygregory.wordpress.com Home: http://garygregory.com/ Tweet! http://twitter.com/GaryGregory
