CtrlK
BlogDocsLog inGet started
Tessl Logo

tessl/maven-org-tinylog--tinylog-impl

tinylog native logging implementation providing writers, policies, converters, and core logging functionality

Overview
Eval results
Files

exception-handling.mddocs/

Exception Handling

The exception handling system in tinylog-impl provides flexible transformation and filtering of exceptions and stack traces, allowing customization of how errors are logged and displayed.

Capabilities

Throwable Filter Interface

Base interface for all throwable transformation filters.

/**
 * Interface for filters that transform throwable data
 */
interface ThrowableFilter {
    /**
     * Transform throwable data according to filter logic
     * @param origin Original throwable data
     * @return Transformed throwable data
     */
    ThrowableData filter(ThrowableData origin);
}

Throwable Data Interface

Interface representing throwable information that can be processed by filters.

/**
 * Interface for accessing throwable data
 */
interface ThrowableData {
    /**
     * Get the throwable class name
     * @return Fully qualified class name
     */
    String getClassName();
    
    /**
     * Get the throwable message
     * @return Exception message or null
     */
    String getMessage();
    
    /**
     * Get the stack trace elements
     * @return List of stack trace elements
     */
    List<StackTraceElement> getStackTrace();
    
    /**
     * Get the cause of this throwable
     * @return Cause throwable data or null
     */
    ThrowableData getCause();
}

Keep Throwable Filter

Preserves complete throwable information including full stack traces and cause chains.

/**
 * Filter that preserves complete throwable information
 */
class KeepThrowableFilter extends AbstractStackTraceElementsFilter {
    /**
     * Default constructor preserving all throwable data
     */
    public KeepThrowableFilter();
    
    /**
     * Constructor with filter arguments
     * @param arguments Configuration arguments for filtering
     */
    public KeepThrowableFilter(String arguments);
}

Configuration Examples:

# Keep full throwable information (default)
writer=console
writer.exception=keep

# Keep throwable but limit stack trace depth
writer=file
writer.file=app.log
writer.exception=keep
writer.exception.depth=20

Strip Throwable Filter

Removes stack trace elements while preserving exception class and message information.

/**
 * Filter that strips stack trace elements but keeps exception info
 */
class StripThrowableFilter extends AbstractStackTraceElementsFilter {
    /**
     * Default constructor that strips all stack trace elements
     */
    public StripThrowableFilter();
}

Configuration Examples:

# Strip stack traces, keep only exception class and message
writer=console
writer.exception=strip

# Multiple writers with different exception handling
writer=console
writer.exception=strip

writer2=file
writer2.file=detailed.log
writer2.exception=keep

Drop Cause Throwable Filter

Removes cause chain from exceptions, keeping only the top-level exception information.

/**
 * Filter that drops cause throwables from the chain
 */
class DropCauseThrowableFilter extends AbstractThrowableFilter {
    /**
     * Default constructor that removes all cause information
     */
    public DropCauseThrowableFilter();
}

Configuration Examples:

# Drop cause chain, keep only primary exception
writer=console
writer.exception=drop cause

# Useful for reducing log verbosity
writer=file
writer.file=summary.log
writer.exception=drop cause
writer.format={date} {level}: {message} - {exception}

Unpack Throwable Filter

Unpacks wrapped exceptions to reveal the underlying root cause, useful for handling framework exceptions that wrap application exceptions.

/**
 * Filter that unpacks wrapped exceptions to reveal root causes
 */
class UnpackThrowableFilter extends AbstractThrowableFilter {
    /**
     * Default constructor that unpacks common wrapper exceptions
     */
    public UnpackThrowableFilter();
    
    /**
     * Constructor with custom wrapper class names
     * @param wrapperClasses Class names of exceptions to unwrap
     */
    public UnpackThrowableFilter(String... wrapperClasses);
}

Configuration Examples:

# Unpack common wrapper exceptions
writer=console
writer.exception=unpack

# Unpack specific wrapper types
writer=file
writer.file=app.log
writer.exception=unpack
writer.exception.classes=java.util.concurrent.ExecutionException,javax.servlet.ServletException

Abstract Base Classes

Base classes providing common functionality for throwable filters.

/**
 * Abstract base class for throwable filters
 */
abstract class AbstractThrowableFilter implements ThrowableFilter {
    /**
     * Create filter from configuration properties
     * @param properties Configuration properties
     */
    protected AbstractThrowableFilter(Map<String, String> properties);
    
    /**
     * Apply filter transformation to throwable data
     * @param data Original throwable data
     * @return Transformed throwable data
     */
    protected abstract ThrowableData transform(ThrowableData data);
}

/**
 * Abstract base class for filters that work with stack trace elements
 */
abstract class AbstractStackTraceElementsFilter extends AbstractThrowableFilter {
    /**
     * Filter stack trace elements according to implementation logic
     * @param elements Original stack trace elements
     * @return Filtered stack trace elements
     */
    protected abstract List<StackTraceElement> filterStackTraceElements(List<StackTraceElement> elements);
    
    /**
     * Get maximum number of stack trace elements to process
     * @return Maximum elements or -1 for unlimited
     */
    protected int getMaxStackTraceElements();
}

Throwable Data Implementations

Concrete implementations for handling throwable data.

/**
 * Wrapper implementation for throwable data
 */
class ThrowableWrapper implements ThrowableData {
    /**
     * Create wrapper from actual throwable
     * @param throwable Source throwable
     */
    public ThrowableWrapper(Throwable throwable);
    
    /**
     * Create wrapper with custom data
     * @param className Exception class name
     * @param message Exception message
     * @param stackTrace Stack trace elements
     * @param cause Cause throwable data
     */
    public ThrowableWrapper(String className, String message, 
                           List<StackTraceElement> stackTrace, ThrowableData cause);
}

/**
 * Storage implementation for throwable data
 */
class ThrowableStore implements ThrowableData {
    /**
     * Create store from throwable wrapper
     * @param wrapper Source throwable wrapper
     */
    public ThrowableStore(ThrowableWrapper wrapper);
    
    /**
     * Create store with explicit data
     * @param className Exception class name
     * @param message Exception message
     * @param stackTrace Stack trace elements
     * @param cause Cause throwable data
     */
    public ThrowableStore(String className, String message,
                         List<StackTraceElement> stackTrace, ThrowableData cause);
}

Filter Combinations

Multiple exception filters can be chained together to create sophisticated exception processing pipelines.

Common Filter Chains

Unpack then Strip:

# First unpack wrapped exceptions, then strip stack traces
writer=console
writer.exception=unpack,strip

Keep with Depth Limit:

# Keep exceptions but limit stack trace depth
writer=file
writer.file=app.log
writer.exception=keep
writer.exception.depth=15

Unpack then Drop Cause:

# Unpack wrappers, then remove cause chain
writer=console
writer.exception=unpack,drop cause

Usage Examples

Basic Exception Configuration:

# Simple console output with full exception details
writer=console
writer.format={date: HH:mm:ss} {level}: {message}
writer.exception=keep

# File output with stripped stack traces for cleaner logs
writer2=file
writer2.file=summary.log
writer2.format={message}
writer2.exception=strip

Advanced Exception Filtering:

# Console: stripped for readability
writer=console
writer.exception=strip
writer.format={level}: {message} [{exception}]

# File: full details for debugging
writer2=file
writer2.file=debug.log
writer2.exception=keep
writer2.exception.depth=50

# Error file: unpacked exceptions only
writer3=file
writer3.file=errors.log
writer3.level=ERROR
writer3.exception=unpack
writer3.format={date} ERROR: {message}{newline}{exception}

Environment-Specific Configuration:

# Development: full exception details
writer=console
writer.exception=keep
writer.format={date: HH:mm:ss.SSS} [{level}] {class}.{method}(): {message}{newline}{exception}

# Production: minimal exception info for performance
writer=file
writer.file=/var/log/app.log  
writer.exception=strip
writer.format={date} {level}: {message} - {exception}

Exception Filter Chaining:

# Complex filter chain: unpack wrappers, then limit depth, then drop causes
writer=file
writer.file=processed.log
writer.exception=unpack,keep,drop cause
writer.exception.depth=10
writer.exception.classes=java.lang.reflect.InvocationTargetException

# Alternative: different processing for different levels
writer=console
writer.level=INFO
writer.exception=strip

writer2=file
writer2.file=errors.log
writer2.level=ERROR
writer2.exception=keep
writer2.exception.depth=25

Custom Wrapper Classes:

# Unpack specific application wrapper exceptions
writer=file
writer.file=app.log
writer.exception=unpack
writer.exception.classes=com.myapp.ServiceException,com.myapp.BusinessException,java.util.concurrent.ExecutionException

Performance-Optimized Exception Handling:

# High-performance logging with minimal exception overhead
writer=file
writer.file=perf.log
writer.exception=drop cause
writer.format={date} {level}: {message}
writer.buffered=true
writer.writingthread=true

Install with Tessl CLI

npx tessl i tessl/maven-org-tinylog--tinylog-impl

docs

converters.md

core.md

exception-handling.md

index.md

pattern.md

policies.md

raw-writers.md

writers.md

tile.json