tinylog native logging implementation providing writers, policies, converters, and core logging functionality
Format patterns in tinylog-impl provide a flexible way to define the layout and format of log entries. The pattern system uses tokens to represent different components of log entries, allowing customizable output formatting across all writers.
Base interface for all pattern tokens that render parts of log entries.
/**
* Interface for tokens that render log entry components as text
*/
interface Token {
/**
* Get the required log entry values for this token
* @return Collection of required LogEntryValue enums
*/
Collection<LogEntryValue> getRequiredLogEntryValues();
/**
* Render the token using log entry data
* @param logEntry Log entry to render
* @param builder StringBuilder to append output to
*/
void render(LogEntry logEntry, StringBuilder builder);
/**
* Apply token value to prepared statement for JDBC writer
* @param logEntry Log entry data
* @param statement JDBC PreparedStatement
* @param index Parameter index in statement
* @throws SQLException if database operation fails
*/
void apply(LogEntry logEntry, PreparedStatement statement, int index) throws SQLException;
}Parser that converts format pattern strings into collections of tokens for rendering.
/**
* Parser for format patterns producing collections of tokens
*/
class FormatPatternParser {
/**
* Create parser with throwable filter support
* @param filters Comma-separated list of throwable filters
*/
public FormatPatternParser(String filters);
/**
* Parse format pattern into tokens
* @param pattern Format pattern string
* @return Collection of tokens representing the pattern
*/
public Collection<Token> parse(String pattern);
/**
* Parse format pattern for JDBC usage
* @param pattern Format pattern string
* @return Collection of tokens for JDBC statements
*/
public Collection<Token> parseForJdbc(String pattern);
}Renders timestamps in configurable date/time formats.
/**
* Token for rendering timestamps with customizable format
*/
class DateToken implements Token {
/**
* Create date token with specified format
* @param pattern Date format pattern (SimpleDateFormat syntax)
*/
public DateToken(String pattern);
/**
* Create date token with format and timezone
* @param pattern Date format pattern
* @param timeZone Timezone for rendering
*/
public DateToken(String pattern, TimeZone timeZone);
}Pattern Examples:
{date} - Default format: yyyy-MM-dd HH:mm:ss{date:HH:mm:ss} - Time only: 14:30:25{date:yyyy-MM-dd} - Date only: 2023-12-25{date:yyyy-MM-dd HH:mm:ss.SSS} - With millisecondsRenders application uptime since startup.
/**
* Token for rendering application uptime
*/
class UptimeToken implements Token {
/**
* Create uptime token with default format
*/
public UptimeToken();
/**
* Create uptime token with custom format
* @param pattern Format pattern for uptime display
*/
public UptimeToken(String pattern);
}Renders thread name and ID information.
/**
* Token for rendering thread information
*/
class ThreadToken implements Token {
/**
* Create thread token with default format (thread name)
*/
public ThreadToken();
/**
* Create thread token with custom format
* @param pattern Format for thread info (name, id, or both)
*/
public ThreadToken(String pattern);
}Renders the current process ID.
/**
* Token for rendering process ID
*/
class ProcessIdToken implements Token {
/**
* Create process ID token
*/
public ProcessIdToken();
}Renders the formatted log message.
/**
* Token for rendering formatted log messages
*/
class MessageToken implements Token {
/**
* Create message token
*/
public MessageToken();
}Renders exception information with configurable formatting.
/**
* Token for rendering exception information
*/
class ExceptionToken implements Token {
/**
* Create exception token with default formatting
*/
public ExceptionToken();
/**
* Create exception token with throwable filters
* @param filters Comma-separated list of throwable filters
*/
public ExceptionToken(String filters);
}Renders the class name where logging occurred.
/**
* Token for rendering class names
*/
class ClassNameToken implements Token {
/**
* Create class name token with default format (full class name)
*/
public ClassNameToken();
/**
* Create class name token with custom format
* @param pattern Format pattern (full, simple, package)
*/
public ClassNameToken(String pattern);
}Renders the method name where logging occurred.
/**
* Token for rendering method names
*/
class MethodToken implements Token {
/**
* Create method token
*/
public MethodToken();
}Renders the source file name where logging occurred.
/**
* Token for rendering source file names
*/
class FileToken implements Token {
/**
* Create file token
*/
public FileToken();
}Renders the line number where logging occurred.
/**
* Token for rendering source line numbers
*/
class LineToken implements Token {
/**
* Create line token
*/
public LineToken();
}Renders the log level with configurable formatting.
/**
* Token for rendering log levels
*/
class LevelToken implements Token {
/**
* Create level token with default format
*/
public LevelToken();
/**
* Create level token with custom format
* @param pattern Format pattern (full, short, numeric)
*/
public LevelToken(String pattern);
}Renders log tags for categorized logging.
/**
* Token for rendering log tags
*/
class TagToken implements Token {
/**
* Create tag token
*/
public TagToken();
}Renders thread-local context values.
/**
* Token for rendering context values
*/
class ContextToken implements Token {
/**
* Create context token for specific key
* @param key Context key to render
*/
public ContextToken(String key);
/**
* Create context token with key and default value
* @param key Context key to render
* @param defaultValue Default value if key not found
*/
public ContextToken(String key, String defaultValue);
}Renders literal text strings within patterns.
/**
* Token for rendering literal text
*/
class PlainTextToken implements Token {
/**
* Create plain text token
* @param text Literal text to render
*/
public PlainTextToken(String text);
}Renders platform-appropriate line separators.
/**
* Token for rendering newlines
*/
class NewLineToken implements Token {
/**
* Create newline token
*/
public NewLineToken();
}Basic Pattern Usage:
# Simple console format
writer=console
writer.format={date: HH:mm:ss} {level}: {message}
# Detailed file format
writer=file
writer.file=app.log
writer.format={date: yyyy-MM-dd HH:mm:ss.SSS} [{level}] [{thread}] {class}.{method}(): {message}Advanced Pattern Examples:
# Development format with full source information
writer=console
writer.format={date: HH:mm:ss.SSS} {level} [{thread}] {class}.{method}({file}:{line}): {message}{newline}{exception}
# Production format with minimal information
writer=file
writer.format={date} {level}: {message}
# JSON-like structured format
writer=file
writer.format={"timestamp":"{date:yyyy-MM-dd'T'HH:mm:ss.SSSZ}","level":"{level}","thread":"{thread}","message":"{message}"}Context Integration:
# Include context values in log format
writer=console
writer.format={date: HH:mm:ss} [{level}] [user:{context:userId}] [session:{context:sessionId}] {message}
# Context with defaults
writer=file
writer.format={date} {level} [user:{context:userId:-unknown}] {class}: {message}Exception Formatting:
# Full exception details
writer=file
writer.format={date} {level}: {message}{newline}{exception}
writer.exception=keep
# Minimal exception info
writer=console
writer.format={date: HH:mm:ss} {level}: {message} [{exception}]
writer.exception=stripMulti-line Formats:
# Multi-line detailed format
writer=file
writer.format=== {date: yyyy-MM-dd HH:mm:ss.SSS} ==={newline}Level: {level}{newline}Thread: {thread}{newline}Location: {class}.{method}({file}:{line}){newline}Message: {message}{newline}{exception}{newline}
# Compact single-line format
writer=console
writer.format={date: HH:mm:ss} {level} {class}: {message}Performance-Optimized Patterns:
# Minimal pattern for high-volume logging
writer=file
writer.format={date: HH:mm:ss} {level}: {message}
# No source code information for better performance
writer=console
writer.format={date: HH:mm:ss} {level} [{thread}]: {message}Install with Tessl CLI
npx tessl i tessl/maven-org-tinylog--tinylog-impl