Skip to content

io microsphere logging log4j2 layout DelegatingLayout

github-actions[bot] edited this page May 30, 2026 · 5 revisions

DelegatingLayout

Type: Class | Module: microsphere-log4j2 | Package: io.microsphere.logging.log4j2.layout | Since: 1.0.0

Source: microsphere-log4j2/src/main/java/io/microsphere/logging/log4j2/layout/DelegatingLayout.java

Overview

Delegating Layout

Declaration

public class DelegatingLayout<T extends Serializable> implements Layout<T>

Author: Mercy

Version Information

  • Introduced in: 1.0.0
  • Current Project Version: 0.1.14-SNAPSHOT

Version Compatibility

This component is tested and compatible with the following Java versions:

Java Version Status
Java 8 ✅ Compatible
Java 11 ✅ Compatible
Java 17 ✅ Compatible
Java 21 ✅ Compatible
Java 25 ✅ Compatible

Examples

Method Examples

getFooter

Layout<String> patternLayout = PatternLayout.newBuilder().withPattern("%m").build();
  DelegatingLayout<String> layout = new DelegatingLayout<>(patternLayout);
DelegatingLayout<String> layout = new DelegatingLayout<>();
  layout.setDelegate(PatternLayout.newBuilder().withPattern("%m").build());
DelegatingLayout<?> layout = new DelegatingLayout<>(delegate);
  byte[] footer = layout.getFooter();

getHeader

DelegatingLayout<?> layout = new DelegatingLayout<>(delegate);
  byte[] header = layout.getHeader();

toByteArray

DelegatingLayout<?> layout = new DelegatingLayout<>(delegate);
  byte[] bytes = layout.toByteArray(logEvent);

toSerializable

DelegatingLayout<?> layout = new DelegatingLayout<>(delegate);
  Object serialized = layout.toSerializable(logEvent);

getContentType

DelegatingLayout<?> layout = new DelegatingLayout<>(delegate);
  String contentType = layout.getContentType();

encode

DelegatingLayout<?> layout = new DelegatingLayout<>(delegate);
  Map<String, String> format = layout.getContentFormat();
DelegatingLayout<?> layout = new DelegatingLayout<>(delegate);
  layout.encode(logEvent, destination);

getDelegate

DelegatingLayout<String> layout = new DelegatingLayout<>(patternLayout);
  Layout<String> delegate = layout.getDelegate();

setDelegate

DelegatingLayout<String> layout = new DelegatingLayout<>();
  layout.setDelegate(PatternLayout.newBuilder().withPattern("%d %m").build());

Usage

Maven Dependency

Add the following dependency to your pom.xml:

<dependency>
    <groupId>io.github.microsphere-projects</groupId>
    <artifactId>microsphere-log4j2</artifactId>
    <version>${microsphere-logging.version}</version>
</dependency>

Tip: Use the BOM (microsphere-logging-dependencies) for consistent version management. See the Getting Started guide.

Import

import io.microsphere.logging.log4j2.layout.DelegatingLayout;

API Reference

Public Methods

Method Description
getFooter Creates a new DelegatingLayout wrapping the given delegate Layout.
getHeader {@inheritDoc}
toByteArray {@inheritDoc}
toSerializable {@inheritDoc}
getContentType {@inheritDoc}
encode {@inheritDoc}
getDelegate Returns the underlying delegate Layout.
setDelegate Sets a new delegate Layout.

Method Details

getFooter

public byte[] getFooter()

Creates a new DelegatingLayout wrapping the given delegate Layout.

Example Usage

`Layout patternLayout = PatternLayout.newBuilder().withPattern("%m").build();
  DelegatingLayout layout = new DelegatingLayout<>(patternLayout);
`

getHeader

public byte[] getHeader()

{@inheritDoc}

Example Usage

`DelegatingLayout layout = new DelegatingLayout<>(delegate);
  byte[] header = layout.getHeader();
`

toByteArray

public byte[] toByteArray(LogEvent event)

{@inheritDoc}

Example Usage

`DelegatingLayout layout = new DelegatingLayout<>(delegate);
  byte[] bytes = layout.toByteArray(logEvent);
`

toSerializable

public T toSerializable(LogEvent event)

{@inheritDoc}

Example Usage

`DelegatingLayout layout = new DelegatingLayout<>(delegate);
  Object serialized = layout.toSerializable(logEvent);
`

getContentType

public String getContentType()

{@inheritDoc}

Example Usage

`DelegatingLayout layout = new DelegatingLayout<>(delegate);
  String contentType = layout.getContentType();
`

encode

public void encode(LogEvent source, ByteBufferDestination destination)

{@inheritDoc}

Example Usage

`DelegatingLayout layout = new DelegatingLayout<>(delegate);
  Map format = layout.getContentFormat();
`

/

getDelegate

public Layout<T> getDelegate()

Returns the underlying delegate Layout.

Example Usage

`DelegatingLayout layout = new DelegatingLayout<>(patternLayout);
  Layout delegate = layout.getDelegate();
`

setDelegate

public void setDelegate(Layout<T> delegate)

Sets a new delegate Layout.

Example Usage

`DelegatingLayout layout = new DelegatingLayout<>();
  layout.setDelegate(PatternLayout.newBuilder().withPattern("%d %m").build());
`

See Also

  • Layout

This documentation was auto-generated from the source code of microsphere-logging.

Clone this wiki locally