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

writers.mddocs/

Writers

Writers in tinylog-impl provide output destinations for log entries, supporting various formats and destinations including console, files, databases, network sockets, and structured data formats.

Capabilities

Base Writer Interface

All writers implement the base Writer interface, which defines the contract for processing log entries.

/**
 * Interface for writers that output log entries
 */
interface Writer {
    /**
     * Get the required log entry values for this writer
     * @return Collection of required LogEntryValue enums
     */
    Collection<LogEntryValue> getRequiredLogEntryValues();
    
    /**
     * Write a log entry
     * @param logEntry The log entry to write
     * @throws Exception if writing fails
     */
    void write(LogEntry logEntry) throws Exception;
    
    /**
     * Flush any buffered data
     * @throws Exception if flushing fails
     */
    void flush() throws Exception;
    
    /**
     * Close the writer and release resources
     * @throws Exception if closing fails
     */
    void close() throws Exception;
}

Console Writer

Outputs log entries to the console (stdout/stderr) with configurable formatting.

/**
 * Writer for console output with format pattern support
 */
class ConsoleWriter extends AbstractFormatPatternWriter {
    // Automatically configured via service provider
    // Configuration: writer=console
    // Optional: writer.format={date: HH:mm:ss.SSS} {level}: {message}
    //          writer.stream=out|err (default: out for INFO and below, err for WARN and above)
}

Configuration Examples:

# Basic console output
writer=console

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

# Console to stderr
writer=console
writer.stream=err

File Writer

Outputs log entries to a specified file with configurable formatting and charset support.

/**
 * Writer for file output with format pattern support
 */
class FileWriter extends AbstractFormatPatternWriter {
    // Configuration: writer=file
    // Required: writer.file=path/to/logfile.log
    // Optional: writer.format=format_pattern
    //          writer.charset=UTF-8
    //          writer.buffered=true|false
    //          writer.writingthread=true|false
}

Configuration Examples:

# Basic file output
writer=file
writer.file=application.log

# File with custom formatting and charset
writer=file
writer.file=/var/log/myapp.log
writer.format={date: yyyy-MM-dd HH:mm:ss.SSS} {level} {class}: {message}
writer.charset=UTF-8
writer.buffered=true

Rolling File Writer

Advanced file writer that supports automatic file rollover based on size, time, or custom policies.

/**
 * Writer for rolling file output with policy-based rollover
 */
class RollingFileWriter extends AbstractFormatPatternWriter {
    // Configuration: writer=rolling file
    // Required: writer.file=path/to/logfile.log
    // Required: writer.policies=policy_specification
    // Optional: writer.converter=converter_type
    //          writer.format=format_pattern
    //          writer.charset=UTF-8
    //          writer.buffered=true|false
}

Configuration Examples:

# Rolling file with size policy
writer=rolling file
writer.file=application.log
writer.policies=size:10MB

# Rolling file with daily policy and compression
writer=rolling file
writer.file=/var/log/myapp.log
writer.policies=daily
writer.converter=gzip

# Rolling file with multiple policies
writer=rolling file
writer.file=application.log
writer.policies=size:50MB,daily
writer.format={date: yyyy-MM-dd HH:mm:ss} [{level}] {message}

Shared File Writer

File writer that supports shared access across multiple processes using file locking.

/**
 * Writer for shared file output with cross-process locking
 */
class SharedFileWriter extends AbstractFormatPatternWriter {
    // Configuration: writer=shared file
    // Required: writer.file=path/to/shared.log
    // Optional: writer.format=format_pattern
    //          writer.charset=UTF-8
}

JDBC Writer

Outputs log entries to a database using JDBC connections with customizable SQL statements.

/**
 * Writer for database output via JDBC
 */
class JdbcWriter extends AbstractWriter {
    // Configuration: writer=jdbc
    // Required: writer.url=jdbc_connection_url
    // Required: writer.table=table_name
    // Optional: writer.username=db_user
    //          writer.password=db_password
    //          writer.columns=column_mapping
    //          writer.batch=batch_size
}

Configuration Examples:

# Basic JDBC writer
writer=jdbc
writer.url=jdbc:h2:mem:testdb
writer.table=logs

# JDBC with custom columns
writer=jdbc
writer.url=jdbc:postgresql://localhost:5432/myapp
writer.username=logger
writer.password=secret
writer.table=application_logs
writer.columns.1=timestamp:timestamp
writer.columns.2=level:level
writer.columns.3=message:message
writer.columns.4=exception:exception

JSON Writer

Outputs log entries in structured JSON format to files.

/**
 * Writer for JSON format output to files
 */
class JsonWriter extends AbstractFileBasedWriter {
    // Configuration: writer=json
    // Required: writer.file=path/to/logs.json
    // Optional: writer.charset=UTF-8
    //          writer.buffered=true|false
    //          writer.field.level=level_field_name
    //          writer.field.message=message_field_name
}

Configuration Examples:

# Basic JSON output
writer=json
writer.file=application.json

# JSON with custom field names
writer=json
writer.file=logs.jsonl
writer.field.timestamp=ts
writer.field.level=severity
writer.field.message=msg
writer.field.exception=error

Logcat Writer

Outputs log entries to Android's Logcat system for mobile applications.

/**
 * Writer for Android Logcat output
 */
class LogcatWriter extends AbstractWriter {
    // Configuration: writer=logcat
    // Optional: writer.tag=application_tag
}

Syslog Writer

Outputs log entries to Syslog servers using UDP or TCP protocols with RFC 3164/5424 support.

/**
 * Writer for Syslog protocol output
 */
class SyslogWriter extends AbstractFormatPatternWriter {
    // Configuration: writer=syslog
    // Required: writer.host=syslog_server_host
    // Optional: writer.port=514
    //          writer.facility=user|mail|daemon|auth|etc (default: user)
    //          writer.protocol=udp|tcp (default: udp)
    //          writer.format=format_pattern
}

Configuration Examples:

# Basic syslog output
writer=syslog
writer.host=syslog.example.com

# Syslog with custom facility and TCP
writer=syslog
writer.host=log-server.internal
writer.port=514
writer.facility=daemon
writer.protocol=tcp
writer.format={level}: {class} - {message}

Abstract Base Classes

AbstractWriter

Base implementation providing common functionality for all writers.

/**
 * Abstract base class for all writers
 */
abstract class AbstractWriter implements Writer {
    /**
     * Create writer from configuration properties
     * @param properties Configuration properties
     */
    protected AbstractWriter(Map<String, String> properties);
    
    /**
     * Parse required log entry values from configuration
     * @param properties Configuration properties
     * @return Set of required LogEntryValue enums
     */
    protected Set<LogEntryValue> getRequiredLogEntryValuesFromConfiguration(Map<String, String> properties);
}

AbstractFileBasedWriter

Base class for file-based writers providing common file handling functionality.

/**
 * Abstract base class for file-based writers
 */
abstract class AbstractFileBasedWriter extends AbstractWriter {
    /**
     * Get the configured file path
     * @return File path string
     */
    protected String getFileName();
    
    /**
     * Get the configured charset
     * @return Charset for file encoding
     */
    protected Charset getCharset();
    
    /**
     * Check if buffered writing is enabled
     * @return true if buffered
     */
    protected boolean isBuffered();
}

AbstractFormatPatternWriter

Base class for writers that support format patterns for log entry formatting.

/**
 * Abstract base class for writers with format pattern support
 */
abstract class AbstractFormatPatternWriter extends AbstractFileBasedWriter {
    /**
     * Render log entry using the configured format pattern
     * @param logEntry The log entry to render
     * @return Rendered string
     */
    protected String render(LogEntry logEntry);
    
    /**
     * Get the configured format pattern
     * @return Format pattern string
     */
    protected String getFormatPattern();
}

Usage Examples

Multiple Writers Configuration:

# Configure multiple writers
writer=console,file,rolling file

# Console writer settings
writer1=console
writer1.format={date: HH:mm:ss} {level}: {message}

# File writer settings  
writer2=file
writer2.file=debug.log
writer2.level=DEBUG

# Rolling file writer settings
writer3=rolling file
writer3.file=application.log
writer3.policies=size:10MB,daily
writer3.converter=gzip
writer3.level=INFO

Tag-Specific Writers:

# Different writers for different tags
writer=console
writer.tag=performance
writer.format=PERF: {message}

writer2=file
writer2.tag=security
writer2.file=security.log
writer2.format={date}: {level} - {message}

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