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

appender-factories.mddocs/

Appender Factories

Comprehensive set of appender implementations for different output destinations including console, files, syslog, and network sockets with extensive configuration options. All appender factories support Jackson-based configuration and can be used both programmatically and via YAML configuration.

Capabilities

AppenderFactory Interface

Base SPI interface for creating Logback Appender instances with Jackson-based polymorphic configuration support.

/**
 * SPI for creating Logback Appender instances
 */
@JsonTypeInfo(use = JsonTypeInfo.Id.NAME, property = "type")
public interface AppenderFactory<E> extends Discoverable {
    /**
     * Build an appender instance
     * @param context the Logback logger context
     * @param applicationName the application name
     * @param layoutFactory factory for creating layouts
     * @param levelFilterFactory factory for creating level filters
     * @param asyncAppenderFactory factory for creating async wrappers
     * @return configured Appender instance
     */
    Appender<E> build(LoggerContext context, String applicationName, 
                     LayoutFactory<E> layoutFactory, 
                     LevelFilterFactory<E> levelFilterFactory, 
                     AsyncAppenderFactory<E> asyncAppenderFactory);
}

AbstractAppenderFactory

Base implementation providing common appender configuration options including async support, filtering, and formatting.

/**
 * Base implementation with common appender configuration
 */
public abstract class AbstractAppenderFactory<E> implements AppenderFactory<E> {
    protected Level threshold = Level.ALL;
    protected String logFormat = null;
    protected DiscoverableLayoutFactory<E> layout = null;
    protected TimeZone timeZone = TimeZone.getTimeZone("UTC");
    protected int queueSize = 256;
    protected int discardingThreshold = -1;
    protected Duration messageRate = null;
    protected boolean includeCallerData = false;
    protected List<FilterFactory<E>> filterFactories = new ArrayList<>();
    protected boolean neverBlock = false;
    
    /**
     * Get the minimum event level for this appender
     * @return the threshold level as string
     */
    public String getThreshold();
    
    /**
     * Set the minimum event level for this appender
     * @param threshold the minimum level
     */
    public void setThreshold(Level threshold);
    
    /**
     * Get the log format pattern
     * @return the pattern layout format string
     */
    public String getLogFormat();
    
    /**
     * Set the log format pattern
     * @param logFormat the pattern layout format string
     */
    public void setLogFormat(String logFormat);
    
    /**
     * Get the custom layout factory
     * @return the layout factory
     */
    public DiscoverableLayoutFactory<?> getLayout();
    
    /**
     * Set a custom layout factory
     * @param layout the layout factory
     */
    public void setLayout(DiscoverableLayoutFactory<E> layout);
    
    /**
     * Get the timezone for timestamps
     * @return the timezone
     */
    public TimeZone getTimeZone();
    
    /**
     * Set the timezone for timestamps
     * @param timeZone the timezone
     */
    public void setTimeZone(TimeZone timeZone);
    
    /**
     * Get the async queue size
     * @return the queue size for async appenders
     */
    public int getQueueSize();
    
    /**
     * Set the async queue size
     * @param queueSize the queue size for async appenders
     */
    public void setQueueSize(int queueSize);
    
    /**
     * Get the async discarding threshold
     * @return events below this level may be discarded when queue is full
     */
    public int getDiscardingThreshold();
    
    /**
     * Set the async discarding threshold
     * @param discardingThreshold events below this level may be discarded when queue is full
     */
    public void setDiscardingThreshold(int discardingThreshold);
    
    /**
     * Get the message rate limiting duration
     * @return maximum rate for log messages
     */
    public Duration getMessageRate();
    
    /**
     * Set message rate limiting
     * @param messageRate maximum rate for log messages
     */
    public void setMessageRate(Duration messageRate);
    
    /**
     * Check if caller data is included in async logging
     * @return true if caller information is included
     */
    public boolean isIncludeCallerData();
    
    /**
     * Include caller data in async logging
     * @param includeCallerData true to include caller information
     */
    public void setIncludeCallerData(boolean includeCallerData);
    
    /**
     * Get additional filter factories
     * @return list of filter factories
     */
    public List<FilterFactory<E>> getFilterFactories();
    
    /**
     * Set additional filter factories
     * @param filterFactories list of filter factories
     */
    public void setFilterFactories(List<FilterFactory<E>> filterFactories);
    
    /**
     * Set non-blocking behavior for async appenders
     * @param neverBlock true to never block on full queue
     */
    public void setNeverBlock(boolean neverBlock);
    
    /**
     * Wrap appender in async wrapper if needed
     * @param context the logger context
     * @param asyncAppenderFactory factory for async appenders
     * @param appender the appender to wrap
     * @return the wrapped appender
     */
    protected Appender<E> wrapAsync(LoggerContext context, 
                                   AsyncAppenderFactory<E> asyncAppenderFactory, 
                                   Appender<E> appender);
    
    /**
     * Build layout with timezone support
     * @param context the logger context
     * @param layoutFactory the layout factory
     * @return configured layout
     */
    protected Layout<E> buildLayout(LoggerContext context, LayoutFactory<E> layoutFactory);
}

ConsoleAppenderFactory

Factory for creating console output appenders supporting both STDOUT and STDERR targets.

/**
 * Factory for console output appenders
 */
@JsonTypeName("console")
public class ConsoleAppenderFactory<E> extends AbstractOutputStreamAppenderFactory<E> {
    private ConsoleStream target = ConsoleStream.STDOUT;
    
    /**
     * Set the console output target
     * @param target STDOUT or STDERR
     */
    public void setTarget(ConsoleStream target);
    
    /**
     * Get the console output target
     * @return the current target
     */
    public ConsoleStream getTarget();
    
    /**
     * Console output stream options
     */
    public enum ConsoleStream {
        STDOUT, STDERR
    }
}

Usage Example:

ConsoleAppenderFactory<ILoggingEvent> consoleAppender = new ConsoleAppenderFactory<>();
consoleAppender.setTarget(ConsoleAppenderFactory.ConsoleStream.STDOUT);
consoleAppender.setLogFormat("%d{HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n");
consoleAppender.setThreshold(Level.INFO);

FileAppenderFactory

Factory for file-based appenders with comprehensive rotation and archiving capabilities.

/**
 * Factory for file-based appenders with rotation
 */
@JsonTypeName("file")
public class FileAppenderFactory<E> extends AbstractOutputStreamAppenderFactory<E> {
    private String currentLogFilename;
    private boolean archive = true;
    private String archivedLogFilenamePattern;
    private int archivedFileCount = 5;
    private DataSize maxFileSize = DataSize.megabytes(10);
    private DataSize totalSizeCap = DataSize.gigabytes(1);
    private DataSize bufferSize = DataSize.kibibytes(8);
    private boolean immediateFlush = true;
    
    /**
     * Set the current log file name
     * @param currentLogFilename path to the current log file
     */
    public void setCurrentLogFilename(String currentLogFilename);
    
    /**
     * Enable or disable log archiving
     * @param archive true to enable archiving
     */
    public void setArchive(boolean archive);
    
    /**
     * Set the archived log filename pattern
     * @param archivedLogFilenamePattern pattern for archived files
     */
    public void setArchivedLogFilenamePattern(String archivedLogFilenamePattern);
    
    /**
     * Set the number of archived files to keep
     * @param archivedFileCount number of archive files
     */
    public void setArchivedFileCount(int archivedFileCount);
    
    /**
     * Set the maximum file size before rotation
     * @param maxFileSize maximum size per file
     */
    public void setMaxFileSize(DataSize maxFileSize);
    
    /**
     * Set the total size cap for all log files
     * @param totalSizeCap maximum total size
     */
    public void setTotalSizeCap(DataSize totalSizeCap);
    
    /**
     * Set the output buffer size
     * @param bufferSize buffer size for file operations
     */
    public void setBufferSize(DataSize bufferSize);
    
    /**
     * Set immediate flush behavior
     * @param immediateFlush true to flush immediately
     */
    public void setImmediateFlush(boolean immediateFlush);
}

Usage Example:

FileAppenderFactory<ILoggingEvent> fileAppender = new FileAppenderFactory<>();
fileAppender.setCurrentLogFilename("./logs/application.log");
fileAppender.setArchivedLogFilenamePattern("./logs/application-%d{yyyy-MM-dd}-%i.log.gz");
fileAppender.setMaxFileSize(DataSize.megabytes(50));
fileAppender.setArchivedFileCount(10);
fileAppender.setTotalSizeCap(DataSize.gigabytes(2));

SyslogAppenderFactory

Factory for syslog appenders supporting standard syslog facilities and remote syslog servers.

/**
 * Factory for syslog appenders
 */
@JsonTypeName("syslog")
public class SyslogAppenderFactory extends AbstractAppenderFactory<ILoggingEvent> {
    private String host = "localhost";
    private int port = 514;
    private Facility facility = Facility.LOCAL0;
    private String stackTracePrefix = null;
    private boolean includeStackTrace = true;
    
    /**
     * Set the syslog server host
     * @param host hostname or IP address
     */
    public void setHost(String host);
    
    /**
     * Set the syslog server port
     * @param port port number
     */
    public void setPort(int port);
    
    /**
     * Set the syslog facility
     * @param facility the syslog facility
     */
    public void setFacility(Facility facility);
    
    /**
     * Set the stack trace prefix
     * @param stackTracePrefix prefix for stack trace lines
     */
    public void setStackTracePrefix(String stackTracePrefix);
    
    /**
     * Include stack traces in syslog messages
     * @param includeStackTrace true to include stack traces
     */
    public void setIncludeStackTrace(boolean includeStackTrace);
    
    /**
     * Syslog facility options
     */
    public enum Facility {
        KERN, USER, MAIL, DAEMON, AUTH, SYSLOG, LPR, NEWS, UUCP, CRON,
        AUTHPRIV, FTP, LOCAL0, LOCAL1, LOCAL2, LOCAL3, LOCAL4, LOCAL5, LOCAL6, LOCAL7
    }
}

TcpSocketAppenderFactory

Factory for TCP socket appenders enabling log forwarding over TCP connections.

/**
 * Factory for TCP socket appenders
 */
@JsonTypeName("tcp")
public class TcpSocketAppenderFactory<E> extends AbstractAppenderFactory<E> {
    private String host = "localhost";
    private int port = 4560;
    private Duration connectionTimeout = Duration.milliseconds(500);
    private boolean immediateFlush = true;
    private DataSize sendBufferSize = DataSize.kibibytes(8);
    
    /**
     * Set the target host
     * @param host hostname or IP address
     */
    public void setHost(String host);
    
    /**
     * Set the target port
     * @param port port number
     */
    public void setPort(int port);
    
    /**
     * Set the connection timeout
     * @param connectionTimeout timeout for connections
     */
    public void setConnectionTimeout(Duration connectionTimeout);
    
    /**
     * Set immediate flush behavior
     * @param immediateFlush true to flush immediately
     */
    public void setImmediateFlush(boolean immediateFlush);
    
    /**
     * Set the send buffer size
     * @param sendBufferSize buffer size for TCP sends
     */
    public void setSendBufferSize(DataSize sendBufferSize);
    
    /**
     * Get socket factory for connection creation (extensible)
     * @return socket factory instance
     */
    protected SocketFactory socketFactory();
}

UdpSocketAppenderFactory

Factory for UDP socket appenders enabling log forwarding over UDP datagrams.

/**
 * Factory for UDP socket appenders
 */
@JsonTypeName("udp")
public class UdpSocketAppenderFactory<E> extends AbstractAppenderFactory<E> {
    private String host = "localhost";
    private int port = 514;
    
    /**
     * Set the target host
     * @param host hostname or IP address
     */
    public void setHost(String host);
    
    /**
     * Set the target port
     * @param port port number
     */
    public void setPort(int port);
}

TlsSocketAppenderFactory

Factory for TLS-encrypted socket appenders with comprehensive SSL/TLS configuration options.

/**
 * Factory for TLS-encrypted socket appenders
 */
@JsonTypeName("tls")
public class TlsSocketAppenderFactory<E> extends TcpSocketAppenderFactory<E> {
    // Keystore configuration
    private String keyStorePath;
    private String keyStorePassword;
    private String keyStoreType;
    private String keyStoreProvider;
    
    // Truststore configuration  
    private String trustStorePath;
    private String trustStorePassword;
    private String trustStoreType;
    private String trustStoreProvider;
    
    // Security settings
    private String jceProvider;
    private boolean validateCerts = false;
    private boolean validatePeers = false;
    
    // Protocol and cipher configuration
    private List<String> supportedProtocols;
    private List<String> excludedProtocols;
    private List<String> supportedCipherSuites;
    private List<String> excludedCipherSuites;
    
    /**
     * Set the keystore path
     * @param keyStorePath path to keystore file
     */
    public void setKeyStorePath(String keyStorePath);
    
    /**
     * Set the keystore password
     * @param keyStorePassword keystore password
     */
    public void setKeyStorePassword(String keyStorePassword);
    
    /**
     * Set the truststore path
     * @param trustStorePath path to truststore file
     */
    public void setTrustStorePath(String trustStorePath);
    
    /**
     * Set certificate validation
     * @param validateCerts true to validate certificates
     */
    public void setValidateCerts(boolean validateCerts);
    
    /**
     * Set peer validation
     * @param validatePeers true to validate peers
     */
    public void setValidatePeers(boolean validatePeers);
    
    /**
     * Set supported TLS protocols
     * @param supportedProtocols list of protocol names
     */
    public void setSupportedProtocols(List<String> supportedProtocols);
    
    /**
     * Set excluded TLS protocols
     * @param excludedProtocols list of protocol names to exclude
     */
    public void setExcludedProtocols(List<String> excludedProtocols);
    
    // Additional getters and setters for all TLS configuration properties
}

Usage Example:

TlsSocketAppenderFactory<ILoggingEvent> tlsAppender = new TlsSocketAppenderFactory<>();
tlsAppender.setHost("secure-log-server.example.com");
tlsAppender.setPort(6514);
tlsAppender.setKeyStorePath("/etc/ssl/keystore.jks");
tlsAppender.setKeyStorePassword("keystorepass");
tlsAppender.setTrustStorePath("/etc/ssl/truststore.jks");
tlsAppender.setValidateCerts(true);
tlsAppender.setSupportedProtocols(Arrays.asList("TLSv1.2", "TLSv1.3"));

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