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

core.mddocs/

Core Implementation

The core implementation provides the fundamental logging provider, configuration management, data structures, and asynchronous processing capabilities that power the tinylog framework.

Capabilities

Logging Provider

The main service provider implementation that integrates with the tinylog-api to provide actual logging functionality.

/**
 * Main logging provider implementation for tinylog
 */
class TinylogLoggingProvider implements LoggingProvider {
    /**
     * Default constructor using TinylogContextProvider
     */
    public TinylogLoggingProvider();
    
    /**
     * Constructor with custom context provider
     * @param contextProvider Custom context provider implementation
     */
    protected TinylogLoggingProvider(ContextProvider contextProvider);
    
    /**
     * Check if logging is enabled for the given parameters
     * @param depth Stack trace depth for caller identification
     * @param tag Log tag (null for untagged)
     * @param level Log level
     * @return true if logging is enabled
     */
    public boolean isEnabled(int depth, String tag, Level level);
    
    /**
     * Log a message with the specified parameters
     * @param depth Stack trace depth for caller identification
     * @param tag Log tag (null for untagged)
     * @param level Log level
     * @param exception Exception to log (null if none)
     * @param formatter Message formatter
     * @param obj First message object
     * @param arguments Additional format arguments
     */
    public void log(int depth, String tag, Level level, Throwable exception, 
                   MessageFormatter formatter, Object obj, Object... arguments);
    
    /**
     * Log a message with logger class name
     * @param loggerClassName Name of the logger class
     * @param tag Log tag
     * @param level Log level
     * @param exception Exception to log
     * @param formatter Message formatter
     * @param obj First message object
     * @param arguments Additional format arguments
     */
    public void log(String loggerClassName, String tag, Level level, Throwable exception, 
                   MessageFormatter formatter, Object obj, Object... arguments);
    
    /**
     * Get minimum log level for any tag
     * @return Minimum log level
     */
    public Level getMinimumLevel();
    
    /**
     * Get minimum log level for specific tag
     * @param tag Log tag
     * @return Minimum log level for the tag
     */
    public Level getMinimumLevel(String tag);
    
    /**
     * Get all writers for specific tag and level
     * @param tag Log tag
     * @param level Log level
     * @return Collection of writers
     */
    public Collection<Writer> getWriters(String tag, Level level);
    
    /**
     * Get all writers for specific tag
     * @param tag Log tag
     * @return Collection of writers
     */
    public Collection<Writer> getWriters(String tag);
    
    /**
     * Get all writers
     * @return Collection of all writers
     */
    public Collection<Writer> getWriters();
    
    /**
     * Get the context provider used by this logging provider
     * @return Context provider instance
     */
    public ContextProvider getContextProvider();
    
    /**
     * Shutdown the logging provider and release resources
     * @throws InterruptedException if shutdown is interrupted
     */
    public void shutdown() throws InterruptedException;
}

Log Entry

Immutable data structure containing all information for a single log entry.

/**
 * Immutable holder for all log entry data
 */
class LogEntry {
    /**
     * Create a complete log entry
     * @param timestamp Entry timestamp
     * @param thread Thread that created the entry
     * @param context Thread-local context map
     * @param className Class name where logging occurred
     * @param methodName Method name where logging occurred
     * @param fileName Source file name
     * @param lineNumber Source line number
     * @param tag Log tag (null if untagged)
     * @param level Log level
     * @param message Formatted log message
     * @param exception Exception (null if none)
     */
    public LogEntry(Timestamp timestamp, Thread thread, Map<String, String> context,
                   String className, String methodName, String fileName, int lineNumber,
                   String tag, Level level, String message, Throwable exception);
    
    // Getter methods
    public Timestamp getTimestamp();
    public Thread getThread();
    public Map<String, String> getContext();
    public String getClassName();
    public String getMethodName();
    public String getFileName();
    public int getLineNumber();
    public String getTag();
    public Level getLevel();
    public String getMessage();
    public Throwable getException();
}

Log Entry Values

Enumeration of all possible log entry components that writers can request.

/**
 * Enumeration of log entry value types
 */
enum LogEntryValue {
    /**
     * Timestamp when the log entry was created
     */
    DATE,
    
    /**
     * Thread that created the log entry
     */
    THREAD,
    
    /**
     * Thread-local context variables
     */
    CONTEXT,
    
    /**
     * Class name where logging occurred
     */
    CLASS,
    
    /**
     * Method name where logging occurred
     */
    METHOD,
    
    /**
     * Source file name
     */
    FILE,
    
    /**
     * Source line number
     */
    LINE,
    
    /**
     * Log tag for categorization
     */
    TAG,
    
    /**
     * Log level (ERROR, WARN, INFO, DEBUG, TRACE)
     */
    LEVEL,
    
    /**
     * Formatted log message
     */
    MESSAGE,
    
    /**
     * Exception/throwable information
     */
    EXCEPTION
}

Context Provider

Thread-local context management for associating key-value pairs with log entries.

/**
 * Context provider using InheritableThreadLocal for thread-safe context management
 */
class TinylogContextProvider implements ContextProvider {
    /**
     * Default constructor
     */
    public TinylogContextProvider();
    
    /**
     * Get all context mappings for the current thread
     * @return Map of context key-value pairs
     */
    public Map<String, String> getMapping();
    
    /**
     * Get a specific context value
     * @param key Context key
     * @return Context value or null if not found
     */
    public String get(String key);
    
    /**
     * Set a context value for the current thread
     * @param key Context key
     * @param value Context value (converted to string)
     */
    public void put(String key, Object value);
    
    /**
     * Remove a context key from the current thread
     * @param key Context key to remove
     */
    public void remove(String key);
    
    /**
     * Clear all context values from the current thread
     */
    public void clear();
}

Configuration Management

Configuration parsing and management for properties-based setup.

/**
 * Configuration support for the logging provider
 */
class TinylogLoggingConfiguration {
    /**
     * Default constructor
     */
    public TinylogLoggingConfiguration();
    
    /**
     * Create writer configurations from properties
     * @param tags List of configured tags
     * @param globalLevel Global log level
     * @param writingThread Whether to use background writing thread
     * @return 2D array of writers organized by tag and level
     */
    public Collection<Writer>[][] createWriters(List<String> tags, Level globalLevel, boolean writingThread);
    
    /**
     * Calculate minimum log level across all writers
     * @param globalLevel Global log level
     * @param customLevels Tag-specific log levels
     * @return Minimum effective log level
     */
    public Level calculateMinimumLevel(Level globalLevel, Map<String, Level> customLevels);
    
    /**
     * Calculate required log entry values across all writers
     * @param writers 2D array of writers
     * @return 2D array of required LogEntryValue sets
     */
    public Collection<LogEntryValue>[][] calculateRequiredLogEntryValues(Collection<Writer>[][] writers);
    
    /**
     * Calculate stack trace requirements for exception handling
     * @param requiredLogEntryValues Required log entry values by writer
     * @return BitSet indicating which levels require full stack traces
     */
    public BitSet calculateFullStackTraceRequirements(Collection<LogEntryValue>[][] requiredLogEntryValues);
    
    /**
     * Create asynchronous writing thread if enabled
     * @param writers Writer configurations
     * @return WritingThread instance or null if disabled
     */
    public WritingThread createWritingThread(Collection<Writer>[][] writers);
    
    /**
     * Get all writers from the 2D writer array
     * @param writers 2D writer array
     * @return Flattened collection of all writers
     */
    public static Collection<Writer> getAllWriters(Collection<Writer>[][] writers);
    
    /**
     * Create a complete log entry from parameters
     * @param stackTraceElement Stack trace element for source location
     * @param tag Log tag
     * @param level Log level
     * @param exception Exception to log
     * @param formatter Message formatter
     * @param obj First message object
     * @param arguments Additional format arguments
     * @param requiredLogEntryValues Required log entry values by level
     * @param contextProvider Context provider for thread-local values
     * @return Complete LogEntry instance
     */
    public static LogEntry createLogEntry(StackTraceElement stackTraceElement, String tag, 
                                        Level level, Throwable exception, MessageFormatter formatter, Object obj,
                                        Object[] arguments, Collection<LogEntryValue>[] requiredLogEntryValues, 
                                        ContextProvider contextProvider);
}

Configuration Parser

Static utilities for parsing tinylog configuration properties.

/**
 * Parser for properties-based configuration
 */
class ConfigurationParser {
    /**
     * Get the global log level from configuration
     * @return Configured global Level
     */
    public static Level getGlobalLevel();
    
    /**
     * Get tag-specific log levels from configuration
     * @return Map of tag names to Level objects
     */
    public static Map<String, Level> getCustomLevels();
    
    /**
     * Get list of configured tags
     * @return List of tag names
     */
    public static List<String> getTags();
    
    /**
     * Check if asynchronous writing thread is enabled
     * @return true if writing thread should be used
     */
    public static boolean isWritingThreadEnabled();
    
    /**
     * Check if automatic shutdown is enabled
     * @return true if automatic shutdown is enabled
     */
    public static boolean isAutoShutdownEnabled();
}

Asynchronous Writing

Background thread for asynchronous log entry processing to improve performance.

/**
 * Thread for asynchronous log entry writing
 */
class WritingThread extends Thread {
    /**
     * Add a log entry to the writing queue
     * @param writer Target writer for the entry
     * @param logEntry Log entry to write
     */
    public void add(Writer writer, LogEntry logEntry);
    
    /**
     * Shutdown the writing thread and flush all pending entries
     * @throws InterruptedException if shutdown is interrupted
     */
    public void shutdown() throws InterruptedException;
    
    /**
     * Check if the writing thread is still alive and processing
     * @return true if the thread is active
     */
    public boolean isAlive();
}

Usage Examples

Basic Provider Usage (typically automatic):

// The provider is automatically discovered via ServiceLoader
// Configuration is done through tinylog.properties
// Direct usage is rare - normally accessed through tinylog-api

import org.tinylog.core.TinylogLoggingProvider;
import org.tinylog.provider.LoggingProvider;

// Get the logging provider (automatic service discovery)
LoggingProvider provider = new TinylogLoggingProvider();

// Check if logging is enabled
boolean enabled = provider.isEnabled(1, null, Level.INFO);

// Log a message (normally done through Logger API)
provider.log(1, null, Level.INFO, null, "Application started");

Context Usage:

import org.tinylog.core.TinylogContextProvider;

TinylogContextProvider context = new TinylogContextProvider();

// Set context values
context.put("userId", "12345");
context.put("sessionId", "abc-def-ghi");
context.put("operation", "login");

// These values will appear in log entries for the current thread
Logger.info("User login attempt"); // Will include context values

// Clear context when done
context.clear();

Configuration Examples:

# Basic configuration
level=INFO
writer=console

# Advanced configuration with custom levels and writing thread
level=DEBUG
level@tag1=WARN
level@tag2=TRACE

writingthread=true
autoshutdown=true

writer=console
writer.format={date: yyyy-MM-dd HH:mm:ss.SSS} [{level}] [{tag}] {class}.{method}(): {message}

writer2=file
writer2.file=application.log
writer2.level=INFO
writer2.format={date} {level}: {message}

Manual Log Entry Creation:

import org.tinylog.core.LogEntry;
import org.tinylog.core.LogEntryValue;
import org.tinylog.Level;

// Create a complete log entry (rarely done manually)
LogEntry entry = new LogEntry(
    new Timestamp(System.currentTimeMillis()),
    Thread.currentThread(),
    Map.of("user", "admin", "action", "delete"),
    "com.example.UserService",
    "deleteUser",
    "UserService.java",
    42,
    "security",
    Level.WARN,
    "User deletion attempted",
    null
);

// Log entry contains all available information
String className = entry.getClassName();
Level level = entry.getLevel();
Map<String, String> context = entry.getContext();

Asynchronous Writing Setup:

# Enable asynchronous writing for better performance
writingthread=true

# Configure multiple writers that will benefit from async processing
writer=file
writer.file=app.log

writer2=rolling file
writer2.file=rolling.log
writer2.policies=size:100MB

writer3=jdbc
writer3.url=jdbc:h2:mem:logs
writer3.table=log_entries

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