Comprehensive logging framework module for Dropwizard applications providing configurable appenders, formatters, and logback integration
—
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.
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);
}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);
}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);
}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:
dwEx - Prefixed throwable converterdwREx - Prefixed root-cause-first throwable converterdwXEx - Prefixed extended throwable converter! characterUsage 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();Specialized converter classes for formatting exception stack traces with consistent prefixing.
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);
}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);
}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();
}
}Default Dropwizard Pattern:
%d{yyyy-MM-dd HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n%dwExConsole Pattern with Colors:
%cyan(%d{HH:mm:ss.SSS}) %gray([%thread]) %highlight(%-5level) %magenta(%logger{36}) - %msg%n%dwExJSON Layout Pattern:
{"timestamp":"%d{yyyy-MM-dd'T'HH:mm:ss.SSS'Z'}","thread":"%thread","level":"%-5level","logger":"%logger","message":"%msg","exception":"%dwEx"}%nSyslog Pattern:
%msg%n%dwExFile Pattern with Extended Info:
%d{yyyy-MM-dd HH:mm:ss.SSS} [%thread] %-5level %logger{36} [%X{requestId}] - %msg%n%dwXExInstall with Tessl CLI
npx tessl i tessl/maven-io-dropwizard--dropwizard-logging