CtrlK
BlogDocsLog inGet started
Tessl Logo

tessl/maven-io-dropwizard--dropwizard-logging

Comprehensive logging framework module for Dropwizard applications providing configurable appenders, formatters, and logback integration

Pending
Overview
Eval results
Files

layout-system.mddocs/

Layout System

Flexible layout system for customizing log message formatting with timezone support and custom pattern converters. The layout system provides both default Dropwizard layouts and extensible factories for creating custom layouts.

Capabilities

LayoutFactory Interface

Base interface for creating Logback layouts with timezone support.

/**
 * Interface for creating Logback layouts
 * @param <E> The type of log event
 */
public interface LayoutFactory<E extends DeferredProcessingAware> {
    /**
     * Creates a {@link PatternLayoutBase} of type E
     * @param context the Logback context
     * @param timeZone the TimeZone
     * @return a new {@link PatternLayoutBase}
     */
    PatternLayoutBase<E> build(LoggerContext context, TimeZone timeZone);
}

DiscoverableLayoutFactory Interface

Jackson-discoverable layout factory interface enabling polymorphic configuration of custom layouts.

/**
 * Jackson-discoverable layout factory for building Logback layouts
 * @param <E> The type of log event
 */
@JsonTypeInfo(use = JsonTypeInfo.Id.NAME, property = "type")
public interface DiscoverableLayoutFactory<E extends DeferredProcessingAware> extends Discoverable {
    /**
     * Creates a {@link LayoutBase} of type E
     * @param context the Logback context
     * @param timeZone the TimeZone
     * @return a new {@link LayoutBase}
     */
    LayoutBase<E> build(LoggerContext context, TimeZone timeZone);
}

DropwizardLayoutFactory

Factory for creating the default Dropwizard layout instances with standard formatting and custom converters.

/**
 * Factory for creating DropwizardLayout instances
 */
public class DropwizardLayoutFactory implements LayoutFactory<ILoggingEvent> {
    /**
     * Build a DropwizardLayout instance
     * @param context the Logback logger context
     * @param timeZone the timezone for timestamp formatting
     * @return configured DropwizardLayout
     */
    @Override
    public PatternLayoutBase<ILoggingEvent> build(LoggerContext context, TimeZone timeZone);
}

DropwizardLayout

Default Dropwizard log layout extending PatternLayout with custom converters and exception formatting.

/**
 * Default Dropwizard log layout with custom converters
 */
public class DropwizardLayout extends PatternLayout {
    /**
     * Default constructor that sets up custom converters and formatting
     */
    public DropwizardLayout();
    
    /**
     * Get the default Dropwizard log pattern
     * @return the default pattern string
     */
    public static String getDefaultPattern();
    
    /**
     * Set up custom throwable converters
     */
    private void setupCustomConverters();
}

Features:

  • Custom Throwable Converters: Registers custom converters for exception formatting
    • dwEx - Prefixed throwable converter
    • dwREx - Prefixed root-cause-first throwable converter
    • dwXEx - Prefixed extended throwable converter
  • Exception Prefixing: Automatically prefixes exception stack traces with ! character
  • ISO8601 Timestamps: Uses ISO8601 format for timestamps by default
  • Pattern Header Disabled: Disables pattern layout headers for cleaner output

Usage Example:

DropwizardLayoutFactory layoutFactory = new DropwizardLayoutFactory();
LoggerContext context = (LoggerContext) LoggerFactory.getILoggerFactory();
TimeZone timeZone = TimeZone.getTimeZone("UTC");
Layout<ILoggingEvent> layout = layoutFactory.build(context, timeZone);

// Or create directly
DropwizardLayout layout = new DropwizardLayout();
layout.setContext(context);
layout.start();

Custom Throwable Converters

Specialized converter classes for formatting exception stack traces with consistent prefixing.

PrefixedThrowableProxyConverter

Base converter that prefixes stack traces with a configurable prefix character.

/**
 * Prefixes stack traces with configurable prefix
 */
public class PrefixedThrowableProxyConverter extends ThrowableProxyConverter {
    public static final String PATTERN = "([\\da-f]{8}-[\\da-f]{4}-[\\da-f]{4}-[\\da-f]{4}-[\\da-f]{12})";
    public static final String PREFIX = "! ";
    
    /**
     * Convert throwable to formatted string with prefix
     * @param event the logging event containing the throwable
     * @return formatted string with prefixed lines
     */
    @Override
    public String convert(ILoggingEvent event);
}

PrefixedExtendedThrowableProxyConverter

Extended throwable converter that includes packaging data and prefixing.

/**
 * Extended throwable converter with packaging data and prefix
 */
public class PrefixedExtendedThrowableProxyConverter extends PrefixedThrowableProxyConverter {
    /**
     * Add extra packaging data to the output
     * @param builder the StringBuilder to append to
     * @param step the stack trace element proxy containing packaging information
     */
    @Override
    protected void extraData(StringBuilder builder, StackTraceElementProxy step);
}

PrefixedRootCauseFirstThrowableProxyConverter

Root-cause-first throwable converter with prefixing for easier debugging.

/**
 * Root-cause-first throwable converter with prefixing
 */
public class PrefixedRootCauseFirstThrowableProxyConverter extends RootCauseFirstThrowableProxyConverter {
    /**
     * Convert throwable proxy to formatted string showing root cause first with prefix
     * @param tp the throwable proxy to convert
     * @return formatted string with root cause first and prefixed lines
     */
    @Override
    protected String throwableProxyToString(IThrowableProxy tp);
}

Usage in Custom Layouts:

// Register custom converters in a custom layout
public class CustomLayout extends PatternLayout {
    @Override
    public void start() {
        // Register the custom converters
        getContext().putProperty("CONVERTER_CLASS_dwEx", 
            PrefixedThrowableProxyConverter.class.getName());
        getContext().putProperty("CONVERTER_CLASS_dwREx", 
            PrefixedRootCauseFirstThrowableProxyConverter.class.getName());
        getContext().putProperty("CONVERTER_CLASS_dwXEx", 
            PrefixedExtendedThrowableProxyConverter.class.getName());
        
        super.start();
    }
}

Pattern Examples

Default Dropwizard Pattern:

%d{yyyy-MM-dd HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n%dwEx

Console Pattern with Colors:

%cyan(%d{HH:mm:ss.SSS}) %gray([%thread]) %highlight(%-5level) %magenta(%logger{36}) - %msg%n%dwEx

JSON Layout Pattern:

{"timestamp":"%d{yyyy-MM-dd'T'HH:mm:ss.SSS'Z'}","thread":"%thread","level":"%-5level","logger":"%logger","message":"%msg","exception":"%dwEx"}%n

Syslog Pattern:

%msg%n%dwEx

File Pattern with Extended Info:

%d{yyyy-MM-dd HH:mm:ss.SSS} [%thread] %-5level %logger{36} [%X{requestId}] - %msg%n%dwXEx

Install with Tessl CLI

npx tessl i tessl/maven-io-dropwizard--dropwizard-logging

docs

appender-factories.md

async-logging.md

filter-system.md

index.md

layout-system.md

logging-factories.md

utility-classes.md

tile.json