or run

npx @tessl/cli init
Log in

Version

Tile

Overview

Evals

Files

docs

appenders.mdconfiguration.mdencoders-layouts.mdfilters-evaluators.mdindex.mdmodel-framework.mdnetwork-logging.mdpatterns.mdrolling-policies.mdutilities.md
tile.json

tessl/maven-ch-qos-logback--logback-core

Core infrastructure and basic components for the Logback logging framework, providing appenders, encoders, layouts, filters, and event processing pipeline

Workspace
tessl
Visibility
Public
Created
Last updated
Describes
mavenpkg:maven/ch.qos.logback/logback-core@1.5.x

To install, run

npx @tessl/cli install tessl/maven-ch-qos-logback--logback-core@1.5.0

index.mddocs/

Logback Core

Logback Core is the foundational module of the Logback logging framework, providing core infrastructure and basic components for logging operations in Java applications. It serves as the base layer for all other Logback modules, implementing essential functionality including appenders (for writing log events to various destinations), encoders and layouts (for formatting log messages), filters (for selective log processing), and the core event processing pipeline.

Package Information

  • Package Name: ch.qos.logback:logback-core
  • Package Type: Maven
  • Language: Java
  • Version: 1.5.18
  • License: EPL-1.0 OR LGPL-2.1
  • Installation:
    <dependency>
      <groupId>ch.qos.logback</groupId>
      <artifactId>logback-core</artifactId>
      <version>1.5.18</version>
    </dependency>

Core Imports

import ch.qos.logback.core.*;
import ch.qos.logback.core.spi.*;

Common specific imports:

import ch.qos.logback.core.AppenderBase;
import ch.qos.logback.core.Context;
import ch.qos.logback.core.FileAppender;
import ch.qos.logback.core.ConsoleAppender;
import ch.qos.logback.core.encoder.LayoutWrappingEncoder;
import ch.qos.logback.core.rolling.RollingFileAppender;
import ch.qos.logback.core.rolling.TimeBasedRollingPolicy;
import ch.qos.logback.core.spi.LifeCycle;
import ch.qos.logback.core.spi.ContextAware;

Basic Usage

import ch.qos.logback.core.*;
import ch.qos.logback.core.encoder.*;
import ch.qos.logback.core.rolling.*;

// Create a context (usually provided by logback-classic)
Context context = new ContextBase();

// Create a console appender
ConsoleAppender<Object> consoleAppender = new ConsoleAppender<>();
consoleAppender.setContext(context);
consoleAppender.setTarget("System.out");

// Create and configure an encoder
LayoutWrappingEncoder<Object> encoder = new LayoutWrappingEncoder<>();
encoder.setContext(context);
// encoder.setLayout(someLayout); // Layout would be set here
encoder.start();

consoleAppender.setEncoder(encoder);
consoleAppender.start();

// Create a file appender with rolling
RollingFileAppender<Object> fileAppender = new RollingFileAppender<>();
fileAppender.setContext(context);
fileAppender.setFile("application.log");

// Configure rolling policy
TimeBasedRollingPolicy<Object> rollingPolicy = new TimeBasedRollingPolicy<>();
rollingPolicy.setContext(context);
rollingPolicy.setParent(fileAppender);
rollingPolicy.setFileNamePattern("application.%d{yyyy-MM-dd}.log");
rollingPolicy.setMaxHistory(30);
rollingPolicy.start();

fileAppender.setRollingPolicy(rollingPolicy);
fileAppender.setTriggeringPolicy(rollingPolicy);
fileAppender.setEncoder(encoder);
fileAppender.start();

// Use the appenders (typically done by logging framework)
// consoleAppender.doAppend(someEvent);
// fileAppender.doAppend(someEvent);

Architecture

Logback Core is built around several key architectural components:

  • Context: Central anchorage point providing shared services, configuration, and lifecycle management
  • Appenders: Write log events to destinations (console, files, network, databases)
  • Encoders/Layouts: Transform log events into formatted output (text, JSON, XML)
  • Filters: Selective processing with accept/deny/neutral decisions on log events
  • SPI Framework: Service Provider Interfaces enabling extensibility and custom implementations
  • Configuration Engine: XML-based configuration processing through the Joran framework
  • Pattern Processing: Flexible pattern-based formatting with conversion chains
  • Lifecycle Management: Consistent start/stop semantics across all components

The framework follows a Template Method pattern where base classes provide structure and subclasses implement specific behavior, enabling extensive customization while maintaining consistent interfaces.

Capabilities

Core Appenders

Foundation appender classes and interfaces for writing log events to various destinations, with built-in support for console, file, and asynchronous output.

public interface Appender<E> extends LifeCycle, ContextAware, FilterAttachable<E> {
    String getName();
    void doAppend(E event) throws LogbackException;
    void setName(String name);
}

public abstract class AppenderBase<E> extends ContextAwareBase 
    implements Appender<E> {
    public synchronized void doAppend(E eventObject);
    protected abstract void append(E eventObject);
}

public class ConsoleAppender<E> extends OutputStreamAppender<E> {
    public void setTarget(String value);
    public String getTarget();
}

public class FileAppender<E> extends OutputStreamAppender<E> {
    public void setFile(String file);
    public String getFile();
    public void setAppend(boolean append);
    public void setPrudent(boolean prudent);
}

Appenders

Encoders and Layouts

Event encoding and transformation system for converting log events into formatted byte arrays or strings, supporting various output formats and character encodings.

public interface Encoder<E> extends ContextAware, LifeCycle {
    byte[] headerBytes();
    byte[] encode(E event);
    byte[] footerBytes();
}

public interface Layout<E> extends ContextAware, LifeCycle {
    String doLayout(E event);
    String getFileHeader();
    String getFileFooter();
    String getContentType();
}

public class LayoutWrappingEncoder<E> extends EncoderBase<E> {
    public void setLayout(Layout<E> layout);
    public Layout<E> getLayout();
    public void setCharset(Charset charset);
}

Encoders and Layouts

Event Filtering

Comprehensive filtering system for selective log processing, supporting filter chains, boolean expression evaluators, and custom filter implementations.

public abstract class Filter<E> extends ContextAwareBase implements LifeCycle {
    public abstract FilterReply decide(E event);
    public void setName(String name);
    public String getName();
}

public enum FilterReply {
    DENY, NEUTRAL, ACCEPT
}

public interface EventEvaluator<E> extends ContextAware, LifeCycle {
    boolean evaluate(E event);
    String getName();
    void setName(String name);
}

public interface FilterAttachable<E> {
    void addFilter(Filter<E> newFilter);
    void clearAllFilters();
    FilterReply getFilterChainDecision(E event);
}

Filters and Evaluators

File Rolling Policies

Advanced file management with time-based and size-based rolling, compression support, and cleanup policies for log file rotation and archival.

public interface RollingPolicy extends LifeCycle {
    void rollover() throws RolloverFailure;
    String getActiveFileName();
    CompressionMode getCompressionMode();
    void setParent(FileAppender<?> appender);
}

public interface TriggeringPolicy<E> extends LifeCycle {
    boolean isTriggeringEvent(File activeFile, E event);
}

public class TimeBasedRollingPolicy<E> extends RollingPolicyBase 
    implements TriggeringPolicy<E> {
    public void setMaxFileSize(FileSize maxFileSize);
    public void setCleanHistoryOnStart(boolean cleanHistoryOnStart);
}

public class RollingFileAppender<E> extends FileAppender<E> {
    public void setRollingPolicy(RollingPolicy policy);
    public void setTriggeringPolicy(TriggeringPolicy<E> policy);
}

Rolling Policies

Network Logging

Network-based logging capabilities including TCP sockets, syslog protocol, email notifications, and SSL/TLS security for remote log transmission.

public class SocketAppender extends AppenderBase<ILoggingEvent> {
    public void setRemoteHost(String host);
    public void setPort(int port);
    public void setReconnectionDelay(Duration delay);
    public void setQueueSize(int queueSize);
}

public class SyslogAppender extends AppenderBase<ILoggingEvent> {
    public void setSyslogHost(String syslogHost);
    public void setFacility(String facilityStr);
    public void setSuffixPattern(String suffixPattern);
}

public class SMTPAppender extends AppenderBase<ILoggingEvent> {
    public void setTo(String to);
    public void setSMTPHost(String smtpHost);
    public void setBufferSize(int bufferSize);
}

Network Logging

Configuration Framework

XML-based configuration processing through the Joran framework, supporting property substitution, conditional configuration, and extensible action handlers.

public abstract class GenericXMLConfigurator extends ContextAwareBase {
    public void doConfigure(URL url) throws JoranException;
    public void doConfigure(File file) throws JoranException;
    public void doConfigure(InputStream inputStream) throws JoranException;
}

public class JoranConfigurator extends GenericXMLConfigurator {
    public void configure(Context context, URL url) throws JoranException;
    public List<SaxEvent> recordEvents(InputStream inputStream);
}

public interface Context extends PropertyContainer {
    StatusManager getStatusManager();
    void putObject(String key, Object value);
    Object getObject(String key);
    ExecutorService getExecutorService();
    ScheduledExecutorService getScheduledExecutorService();
}

Configuration

Model Framework

Configuration model system providing hierarchical representation of logback components with processing, state tracking, and integration with the Joran configuration framework.

public class Model implements Serializable {
    public int getLineNumber();
    public Model getParent();
    public void addSubModel(Model child);
    public List<Model> getSubModels();
    public boolean isProcessed();
    public String getTag();
    public String getBodyText();
}

public class ComponentModel extends Model {
    public String getClassName();
    public Class<?> getClazz();
}

public class NamedComponentModel extends ComponentModel implements INamedModel {
    public String getName();
    public void setName(String name);
}

Model Framework

Pattern Processing

Flexible pattern-based formatting system with conversion chains, color support, and extensible converter framework for custom log formatting.

public abstract class PatternLayoutBase<E> extends LayoutBase<E> {
    public void setPattern(String pattern);
    public String getPattern();
}

public abstract class Converter<E> implements ContextAware {
    public abstract void write(StringBuilder buf, E event);
    public void setNext(Converter<E> next);
    public Converter<E> getNext();
}

public abstract class FormattingConverter<E> extends Converter<E> {
    public abstract String convert(E event);
    public void setFormattingInfo(FormatInfo fi);
}

Pattern Processing

Utilities and Helpers

Comprehensive utility classes for file operations, date formatting, duration handling, size parsing, thread management, and testing support.

public class FileSize {
    public FileSize(long size);
    public void setSize(String str);
    public long getSize();
    public String toString();
    public static long valueOf(String s);
}

public class Duration {
    public long getMilliseconds();
    public void setMilliseconds(long milliseconds);
    public String toString();
    public static Duration valueOf(String s);
}

public class OptionHelper {
    public static String substVars(String val, PropertyContainer pc);
    public static Object instantiateByClassName(String className, 
        Class<?> superClass, Context context);
}

Utilities

Core Constants

public class CoreConstants {
    // Context and Configuration Keys
    public static final String DEFAULT_CONTEXT_NAME = "default";
    public static final String STATUS_LISTENER_CLASS_KEY = "logback.statusListenerClass";
    public static final String DISABLE_SERVLET_CONTAINER_INITIALIZER_KEY = "logbackDisableServletContainerInitializer";
    public static final String PATTERN_RULE_REGISTRY = "PATTERN_RULE_REGISTRY";
    public static final String EVALUATOR_MAP = "EVALUATOR_MAP";
    public static final String HOSTNAME_KEY = "HOSTNAME";
    public static final String CONTEXT_NAME_KEY = "CONTEXT_NAME";
    
    // Thread Pool Configuration
    public static final int CORE_POOL_SIZE = 4;
    public static final int SCHEDULED_EXECUTOR_POOL_SIZE = 4;
    public static final int MAX_POOL_SIZE = 32; // @deprecated
    
    // Size and Count Limits
    public static final int TABLE_ROW_LIMIT = 10000;
    public static final int MAX_ERROR_COUNT = 4;
    public static final int OOS_RESET_FREQUENCY = 70;
    public static final int SECONDS_TO_WAIT_FOR_COMPRESSION_JOBS = 30;
    public static final long UNBOUNDED_TOTAL_SIZE_CAP = 0;
    public static final int UNBOUNDED_HISTORY = 0;
    
    // Character Constants
    public static final char PERCENT_CHAR = '%';
    public static final char ESCAPE_CHAR = '\\';
    public static final char CURLY_LEFT = '{';
    public static final char CURLY_RIGHT = '}';
    public static final char COLON_CHAR = ':';
    public static final char COMMA_CHAR = ',';
    public static final char DOT = '.';
    public static final char DOLLAR = '$';
    
    // String Constants
    public static final String LINE_SEPARATOR = System.getProperty("line.separator");
    public static final String EMPTY_STRING = "";
    public static final String NULL_STR = "null";
    public static final String NA = "?";
    public static final String SYSOUT = "SYSOUT";
    public static final String STDOUT = "STDOUT";
    
    // Time Constants (in milliseconds)
    public static final long MILLIS_IN_ONE_SECOND = 1000;
    public static final long MILLIS_IN_ONE_MINUTE = MILLIS_IN_ONE_SECOND * 60;
    public static final long MILLIS_IN_ONE_HOUR = MILLIS_IN_ONE_MINUTE * 60;
    public static final long MILLIS_IN_ONE_DAY = MILLIS_IN_ONE_HOUR * 24;
    public static final long MILLIS_IN_ONE_WEEK = MILLIS_IN_ONE_DAY * 7;
    
    // Date and Time Patterns
    public static final String ISO8601_STR = "ISO8601";
    public static final String ISO8601_PATTERN = "yyyy-MM-dd HH:mm:ss,SSS";
    public static final String STRICT_ISO8601_PATTERN = "yyyy-MM-dd'T'HH:mm:ss,SSS";
    public static final String DAILY_DATE_PATTERN = "yyyy-MM-dd";
    public static final String CLF_DATE_PATTERN = "dd/MMM/yyyy:HH:mm:ss Z";
    public static final String FILE_TIMESTAMP_PATTERN = "yyyy-MM-dd'T'HHmm";
    
    // URL Patterns
    public static final String CODES_URL = "https://logback.qos.ch/codes.html";
    public static final String MANUAL_URL_PREFIX = "https://logback.qos.ch/manual/";
    
    // Charset and Arrays
    public static final Charset UTF_8_CHARSET = StandardCharsets.UTF_8;
    public static final String[] EMPTY_STRING_ARRAY = new String[] {};
    public static final Class<?>[] EMPTY_CLASS_ARRAY = new Class[] {};
    
    // File Extensions
    public static final String MODEL_CONFIG_FILE_EXTENSION = ".scmo";
    public static final String PROPERTIES_FILE_EXTENSION = ".properties";
    
    // JNDI Constants
    public static final String JNDI_JAVA_NAMESPACE = "java:";
    public static final String JNDI_COMP_PREFIX = "java:comp/env";
}

Core Exceptions

public class LogbackException extends RuntimeException {
    public LogbackException(String msg);
    public LogbackException(String msg, Throwable cause);
}

public class EvaluationException extends Exception {
    public EvaluationException(String msg);
    public EvaluationException(String msg, Throwable cause);
}

Service Provider Interfaces

public interface LifeCycle {
    void start();
    void stop();
    boolean isStarted();
}

public interface ContextAware {
    void setContext(Context context);
    Context getContext();
    void addStatus(Status status);
    void addInfo(String msg);
    void addInfo(String msg, Throwable ex);
    void addWarn(String msg);
    void addWarn(String msg, Throwable ex);
    void addError(String msg);
    void addError(String msg, Throwable ex);
}

public interface PropertyContainer {
    String getProperty(String key);
    void putProperty(String key, String value);
    Map<String, String> getCopyOfPropertyMap();
}