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

logging-factories.mddocs/

Logging Factories

Core logging system configuration and lifecycle management providing the main entry points for setting up logging in Dropwizard applications. The LoggingFactory interface serves as the primary SPI for implementing custom logging configurations.

Capabilities

LoggingFactory Interface

Main SPI interface for configuring logging systems with pluggable implementations supporting Jackson-based polymorphic deserialization.

/**
 * Main SPI interface for configuring logging systems
 */
@JsonTypeInfo(use = JsonTypeInfo.Id.NAME, property = "type", defaultImpl = DefaultLoggingFactory.class)
public interface LoggingFactory extends Discoverable {
    /**
     * Configure the logging system with metrics integration
     * @param metricRegistry the metrics registry for logging metrics collection
     * @param name the application name for logging context
     */
    void configure(MetricRegistry metricRegistry, String name);
    
    /**
     * Flush all log messages without disabling logging
     */
    void stop();
    
    /**
     * Reset logging to sane defaults, useful for testing
     */
    void reset();
}

DefaultLoggingFactory

Default implementation of LoggingFactory that handles standard Dropwizard logging configuration with full YAML configuration support.

/**
 * Default implementation handling standard Dropwizard logging configuration
 */
@JsonTypeName("default")
public class DefaultLoggingFactory implements LoggingFactory {
    private String level = "INFO";
    private Map<String, JsonNode> loggers = new LinkedHashMap<>();
    private List<AppenderFactory<ILoggingEvent>> appenders = new ArrayList<>();
    
    /**
     * Set the root logging level
     * @param level the logging level (TRACE, DEBUG, INFO, WARN, ERROR, OFF)
     */
    public void setLevel(String level);
    
    /**
     * Get the root logging level
     * @return the current logging level
     */
    public String getLevel();
    
    /**
     * Set logger-specific configurations
     * @param loggers map of logger names to their configurations
     */
    public void setLoggers(Map<String, JsonNode> loggers);
    
    /**
     * Get logger-specific configurations
     * @return map of logger configurations
     */
    public Map<String, JsonNode> getLoggers();
    
    /**
     * Set the list of appenders
     * @param appenders list of appender factories
     */
    public void setAppenders(List<AppenderFactory<ILoggingEvent>> appenders);
    
    /**
     * Get the list of appenders
     * @return list of configured appender factories
     */
    public List<AppenderFactory<ILoggingEvent>> getAppenders();
    
    /**
     * Convert string to Logback Level with error handling
     * @param text the level name
     * @return the corresponding Logback Level
     * @throws IllegalArgumentException if level is invalid
     */
    public static Level toLevel(String text);
    
    @Override
    public void configure(MetricRegistry metricRegistry, String name);
    
    @Override
    public void stop();
    
    @Override
    public void reset();
}

Usage Example:

DefaultLoggingFactory loggingFactory = new DefaultLoggingFactory();
loggingFactory.setLevel("INFO");

// Configure specific loggers
Map<String, JsonNode> loggers = new HashMap<>();
ObjectNode dbLogger = JsonNodeFactory.instance.objectNode();
dbLogger.put("level", "DEBUG");
loggers.put("org.hibernate.SQL", dbLogger);
loggingFactory.setLoggers(loggers);

// Add appenders
List<AppenderFactory<ILoggingEvent>> appenders = new ArrayList<>();
ConsoleAppenderFactory<ILoggingEvent> consoleAppender = new ConsoleAppenderFactory<>();
appenders.add(consoleAppender);
loggingFactory.setAppenders(appenders);

// Configure the system
MetricRegistry metrics = new MetricRegistry();
loggingFactory.configure(metrics, "MyApp");

ExternalLoggingFactory

No-op logging factory implementation for scenarios where logging is configured externally (e.g., via logback.xml).

/**
 * No-op logging factory for external logging configuration
 */
@JsonTypeName("external")
public class ExternalLoggingFactory implements LoggingFactory {
    @Override
    public void configure(MetricRegistry metricRegistry, String name) {
        // No-op - logging configured externally
    }
    
    @Override
    public void stop() {
        // No-op
    }
    
    @Override
    public void reset() {
        // No-op
    }
}

Usage Example:

// Used when logging is configured via logback.xml or similar
ExternalLoggingFactory loggingFactory = new ExternalLoggingFactory();
MetricRegistry metrics = new MetricRegistry();
loggingFactory.configure(metrics, "MyApp"); // Does nothing

LoggerConfiguration

Configuration class for individual logger settings allowing fine-grained control over specific loggers.

/**
 * Configuration for individual loggers
 */
public class LoggerConfiguration {
    private String level = "INFO";
    private List<AppenderFactory<ILoggingEvent>> appenders = new ArrayList<>();
    private boolean additive = true;
    
    /**
     * Set the logging level for this logger
     * @param level the logging level
     */
    public void setLevel(String level);
    
    /**
     * Get the logging level
     * @return the current logging level
     */
    public String getLevel();
    
    /**
     * Set specific appenders for this logger
     * @param appenders list of appender factories
     */
    public void setAppenders(List<AppenderFactory<ILoggingEvent>> appenders);
    
    /**
     * Get the appenders for this logger
     * @return list of appender factories
     */
    public List<AppenderFactory<ILoggingEvent>> getAppenders();
    
    /**
     * Set whether this logger inherits appenders from parent loggers
     * @param additive true to inherit parent appenders, false otherwise
     */
    public void setAdditive(boolean additive);
    
    /**
     * Check if this logger inherits appenders from parent loggers
     * @return true if additive, false otherwise
     */
    public boolean isAdditive();
}

Usage Example:

LoggerConfiguration dbLoggerConfig = new LoggerConfiguration();
dbLoggerConfig.setLevel("DEBUG");
dbLoggerConfig.setAdditive(false);

// Add specific appenders for database logging
FileAppenderFactory<ILoggingEvent> dbFileAppender = new FileAppenderFactory<>();
dbFileAppender.setCurrentLogFilename("./logs/database.log");
dbLoggerConfig.setAppenders(Arrays.asList(dbFileAppender));

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