You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@logging.apache.org by rp...@apache.org on 2016/04/20 12:18:20 UTC
logging-log4j2 git commit: LOG4J2-1274 improved #encode method javadoc
Repository: logging-log4j2
Updated Branches:
refs/heads/master 76d046947 -> ddb2ca9e8
LOG4J2-1274 improved #encode method javadoc
Project: http://git-wip-us.apache.org/repos/asf/logging-log4j2/repo
Commit: http://git-wip-us.apache.org/repos/asf/logging-log4j2/commit/ddb2ca9e
Tree: http://git-wip-us.apache.org/repos/asf/logging-log4j2/tree/ddb2ca9e
Diff: http://git-wip-us.apache.org/repos/asf/logging-log4j2/diff/ddb2ca9e
Branch: refs/heads/master
Commit: ddb2ca9e864ed987fd3e56252ef4791003e3ff1a
Parents: 76d0469
Author: rpopma <rp...@apache.org>
Authored: Wed Apr 20 19:15:43 2016 +0900
Committer: rpopma <rp...@apache.org>
Committed: Wed Apr 20 19:15:43 2016 +0900
----------------------------------------------------------------------
.../log4j/core/layout/AbstractLayout.java | 23 ++++++++++++++++++--
1 file changed, 21 insertions(+), 2 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/ddb2ca9e/log4j-core/src/main/java/org/apache/logging/log4j/core/layout/AbstractLayout.java
----------------------------------------------------------------------
diff --git a/log4j-core/src/main/java/org/apache/logging/log4j/core/layout/AbstractLayout.java b/log4j-core/src/main/java/org/apache/logging/log4j/core/layout/AbstractLayout.java
index a3ad348..b083db9 100644
--- a/log4j-core/src/main/java/org/apache/logging/log4j/core/layout/AbstractLayout.java
+++ b/log4j-core/src/main/java/org/apache/logging/log4j/core/layout/AbstractLayout.java
@@ -128,12 +128,31 @@ public abstract class AbstractLayout<T extends Serializable> implements Layout<T
* Encodes the specified source LogEvent to some binary representation and writes the result to the specified
* destination.
* <p>
- * Subclasses can override this method to provide a garbage-free implementation. The default implementation
- * delegates to the {@link #toByteArray(LogEvent)} method which allocates temporary objects.
+ * The default implementation of this method delegates to the {@link #toByteArray(LogEvent)} method which allocates
+ * temporary objects.
+ * </p><p>
+ * Subclasses can override this method to provide a garbage-free implementation. For text-based layouts,
+ * {@code AbstractStringLayout} provides various convenience methods to help with this:
* </p>
+ * <pre>@Plugin(name = "MyLayout", category = Node.CATEGORY, elementType = Layout.ELEMENT_TYPE, printObject = true)
+ * public final class MyLayout extends AbstractStringLayout {
+ * @Override
+ * public void encode(LogEvent event, ByteBufferDestination destination) {
+ * StringBuilder text = getStringBuilder();
+ * convertLogEventToText(event, text);
+ * getStringBuilderEncoder().encode(text, destination);
+ * }
+ *
+ * private void convertLogEventToText(LogEvent event, StringBuilder destination) {
+ * ... // append a text representation of the log event to the StringBuilder
+ * }
+ * }
+ * </pre>
*
* @param event the LogEvent to encode.
* @param destination holds the ByteBuffer to write into.
+ * @see AbstractStringLayout#getStringBuilder()
+ * @see AbstractStringLayout#getStringBuilderEncoder()
*/
@Override
public void encode(final LogEvent event, final ByteBufferDestination destination) {