or run

npx @tessl/cli init
Log in

Version

Tile

Overview

Evals

Files

docs

converters.mdcore.mdexception-handling.mdindex.mdpattern.mdpolicies.mdraw-writers.mdwriters.md
tile.json

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

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

Workspace
tessl
Visibility
Public
Created
Last updated
Describes
mavenpkg:maven/org.tinylog/tinylog-impl@2.7.x

To install, run

npx @tessl/cli install tessl/maven-org-tinylog--tinylog-impl@2.7.0

index.mddocs/

tinylog-impl

tinylog-impl is the native implementation of the tinylog logging framework for Java, providing high-performance, lightweight logging with zero dependencies. It serves as an OSGi fragment that provides concrete implementations for all tinylog-api interfaces, including writers for various output destinations, rollover policies, throwable filters, and file converters.

Package Information

  • Package Name: org.tinylog:tinylog-impl
  • Package Type: Maven
  • Language: Java
  • Installation:
    <dependency>
      <groupId>org.tinylog</groupId>
      <artifactId>tinylog-impl</artifactId>
      <version>2.7.0</version>
    </dependency>

Core Imports

The tinylog-impl library provides service implementations that are automatically discovered through Java's ServiceLoader mechanism. Most classes are not directly imported but configured through properties:

// Core logging provider (automatically discovered)
import org.tinylog.core.TinylogLoggingProvider;

// Writers (configured via properties, but can be used directly)
import org.tinylog.writers.ConsoleWriter;
import org.tinylog.writers.FileWriter;
import org.tinylog.writers.RollingFileWriter;

// Policies for rolling files
import org.tinylog.policies.SizePolicy;
import org.tinylog.policies.DailyPolicy;

// Core data structures
import org.tinylog.core.LogEntry;
import org.tinylog.core.LogEntryValue;

Basic Usage

tinylog-impl provides the underlying implementation and is typically configured through properties rather than direct API calls:

// Configuration via tinylog.properties
// writer=console
// writer.format={date: HH:mm:ss.SSS} {level}: {message}

// The implementation provides the actual logging functionality
// when using tinylog-api for logging calls
import org.tinylog.Logger;

Logger.info("This message is handled by tinylog-impl");
Logger.error("Error message with exception", exception);

Architecture

tinylog-impl is built around several key components:

  • Logging Provider: TinylogLoggingProvider serves as the main service provider implementation
  • Writers: Output destinations including console, files, databases, network sockets, and structured formats
  • Policies: Rollover triggers for file-based writers (size, time, startup-based)
  • Converters: File transformation utilities (compression, format conversion)
  • Filters: Exception/throwable transformation and filtering
  • Configuration: Properties-based configuration parsing and management
  • Threading: Asynchronous writing capabilities with background thread management

Capabilities

Writers

Complete set of output destinations for log entries, from simple console output to complex database and network logging.

// Base writer interface
interface Writer {
    Collection<LogEntryValue> getRequiredLogEntryValues();
    void write(LogEntry logEntry) throws Exception;
    void flush() throws Exception;
    void close() throws Exception;
}

// Console writer
class ConsoleWriter extends AbstractFormatPatternWriter {
    // Configured via properties: writer=console
}

// File writer  
class FileWriter extends AbstractFormatPatternWriter {
    // Configured via properties: writer=file, writer.file=application.log
}

// Rolling file writer
class RollingFileWriter extends AbstractFormatPatternWriter {
    // Supports policies and converters for advanced file management
}

Writers

Rollover Policies

Policies for triggering file rollover events in RollingFileWriter, supporting time-based, size-based, and custom rollover conditions.

interface Policy {
    boolean continueExistingFile(String path);
    boolean continueCurrentFile(byte[] entry);
    void reset();
}

// Size-based rollover
class SizePolicy implements Policy {
    // Configured via: writer.policies=size:10MB
}

// Time-based rollover
class DailyPolicy extends AbstractDatePolicy {
    // Configured via: writer.policies=daily
}

Policies

Core Implementation

Core logging provider implementation and fundamental data structures for log processing.

// Main logging provider
class TinylogLoggingProvider implements LoggingProvider {
    // Automatically discovered service provider
    public boolean isEnabled(int depth, String tag, Level level);
    public void log(int depth, String tag, Level level, Throwable exception, 
                   MessageFormatter formatter, Object... arguments);
}

// Log entry data structure
class LogEntry {
    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);
    // Getters for all components
}

// Required log entry values enumeration
enum LogEntryValue {
    DATE, THREAD, CONTEXT, CLASS, METHOD, FILE, LINE, TAG, LEVEL, MESSAGE, EXCEPTION
}

Core Implementation

Exception Handling

Throwable filters for transforming exceptions and stack traces, providing flexible error handling and logging customization.

interface ThrowableFilter {
    ThrowableData filter(ThrowableData origin);
}

// Keep full throwable information
class KeepThrowableFilter extends AbstractStackTraceElementsFilter {
    // Configured via: writer.exception=keep
}

// Strip stack trace elements
class StripThrowableFilter extends AbstractStackTraceElementsFilter {
    // Configured via: writer.exception=strip
}

Exception Handling

File Converters

File converters for transforming completed log files, supporting compression and custom file processing.

interface FileConverter {
    String getBackupSuffix();
    void open(String fileName);
    byte[] write(byte[] data);
    void close();
    void shutdown() throws InterruptedException;
}

// GZIP compression converter
class GzipFileConverter implements FileConverter {
    // Configured via: writer.converter=gzip
}

File Converters

Format Patterns

Pattern system for customizable log entry formatting using tokens to represent different log components.

interface Token {
    Collection<LogEntryValue> getRequiredLogEntryValues();
    void render(LogEntry logEntry, StringBuilder builder);
    void apply(LogEntry logEntry, PreparedStatement statement, int index) throws SQLException;
}

// Format pattern parser
class FormatPatternParser {
    public FormatPatternParser(String filters);
    public Collection<Token> parse(String pattern);
}

// Token implementations for date, message, exception, class, method, etc.
class DateToken implements Token { /* Date/time formatting */ }
class MessageToken implements Token { /* Log message rendering */ }
class ExceptionToken implements Token { /* Exception formatting */ }

Format Patterns

Raw Writers

Low-level byte array writers and decorators for advanced I/O operations and network communication.

interface ByteArrayWriter {
    int readTail(byte[] buffer, int offset, int length) throws IOException;
    void write(byte[] data, int offset, int length) throws IOException;
    void truncate(int size) throws IOException;
    void flush() throws IOException;
    void close() throws IOException;
}

// File-based raw writers
class RandomAccessFileWriter implements ByteArrayWriter { /* Random access file I/O */ }
class LockedRandomAccessFileWriter implements ByteArrayWriter { /* Thread-safe file I/O */ }

// Network writers
class TcpSocketWriter extends AbstractSocketWriter { /* TCP network output */ }
class UdpSocketWriter extends AbstractSocketWriter { /* UDP network output */ }

// Writer decorators
class BufferedWriterDecorator implements ByteArrayWriter { /* Buffering capability */ }
class SynchronizedWriterDecorator implements ByteArrayWriter { /* Thread synchronization */ }

Raw Writers

Types

// Core log entry data
class LogEntry {
    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();
}

// Throwable data interface
interface ThrowableData {
    String getClassName();
    String getMessage();
    List<StackTraceElement> getStackTrace();
    ThrowableData getCause();
}

// Configuration support
class TinylogLoggingConfiguration {
    public Collection<Writer>[][] createWriters(List<String> tags, Level globalLevel, boolean writingThread);
    public Level calculateMinimumLevel(Level globalLevel, Map<String, Level> customLevels);
    public WritingThread createWritingThread(Collection<Writer>[][] writers);
}