Comprehensive SLF4J implementation providing enterprise-grade logging with flexible configuration, high performance, and extensive appender ecosystem for Java applications.
npx @tessl/cli install tessl/maven-ch-qos-logback--logback-classic@1.5.0Logback Classic is a comprehensive logging library for Java that provides a complete implementation of the SLF4J API. As the successor to Log4j, it offers enterprise-grade logging with flexible configuration, high performance, and extensive features for production environments.
implementation 'ch.qos.logback:logback-classic:1.5.18' (Gradle) or <dependency><groupId>ch.qos.logback</groupId><artifactId>logback-classic</artifactId><version>1.5.18</version></dependency> (Maven)import ch.qos.logback.classic.Logger;
import ch.qos.logback.classic.LoggerContext;
import ch.qos.logback.classic.Level;
import org.slf4j.LoggerFactory;For SLF4J facade usage (recommended):
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
public class Application {
private static final Logger logger = LoggerFactory.getLogger(Application.class);
public static void main(String[] args) {
logger.info("Application starting");
logger.warn("This is a warning message");
logger.error("Error occurred: {}", "sample error", new RuntimeException("test"));
// With structured logging
logger.info("User action: user={}, action={}", "alice", "login");
}
}Logback Classic is built around several key components:
Essential logging functionality including the Logger interface, logging contexts, and level management.
// Main logger interface (via SLF4J)
public interface Logger {
void trace(String msg);
void debug(String msg);
void info(String msg);
void warn(String msg);
void error(String msg);
// Parameterized messages
void info(String format, Object... arguments);
void error(String msg, Throwable t);
}
// Logback-specific Logger class
public final class Logger implements org.slf4j.Logger {
public static final String FQCN = "ch.qos.logback.classic.Logger";
// ROOT_LOGGER_NAME is inherited from org.slf4j.Logger interface
}
// Logger factory and context
public class LoggerContext implements ILoggerFactory {
public Logger getLogger(String name);
public void reset();
public void stop();
}
// Logging levels
public final class Level {
public static final Level OFF;
public static final Level ERROR;
public static final Level WARN;
public static final Level INFO;
public static final Level DEBUG;
public static final Level TRACE;
public static final Level ALL;
}Programmatic and XML-based configuration for loggers, appenders, and overall system behavior.
public class BasicConfigurator {
public static void configure(LoggerContext lc);
}
public interface Configurator {
enum ExecutionStatus { NEUTRAL, INVOKE_NEXT_IF_ANY, DO_NOT_INVOKE_NEXT_IF_ANY }
ExecutionStatus configure(LoggerContext context);
}Output destinations for log events including console, file, network, and specialized appenders.
public class AsyncAppender extends AsyncAppenderBase<ILoggingEvent> {
// High-performance asynchronous logging
}
// Key appender interfaces
public interface Appender<E> {
void doAppend(E event);
String getName();
void setName(String name);
}Message formatting and encoding for different output formats and protocols.
public class PatternLayout extends LayoutBase<ILoggingEvent> {
// Pattern-based message formatting
}
public class PatternLayoutEncoder extends EncoderBase<ILoggingEvent> {
// Encoder using PatternLayout
}
public class JsonEncoder extends EncoderBase<ILoggingEvent> {
// JSON-based structured logging
}Event filtering mechanisms for controlling which log events are processed.
public class LevelFilter extends Filter<ILoggingEvent> {
// Filter based on log level
}
public class ThresholdFilter extends Filter<ILoggingEvent> {
// Filter based on minimum threshold
}
public abstract class TurboFilter extends ContextAwareBase {
// High-performance filtering
}Remote logging capabilities including socket appenders, receivers, and email alerts.
public class SocketAppender extends AppenderBase<ILoggingEvent> {
// TCP socket-based remote logging
}
public class SMTPAppender extends SMTPAppenderBase<ILoggingEvent> {
// Email-based alert system
}
public class SyslogAppender extends AppenderBase<ILoggingEvent> {
// Syslog protocol support
}Web application integration components for servlet containers.
public class LogbackServletContextListener implements ServletContextListener {
// Servlet container lifecycle integration
}
public class LogbackServletContainerInitializer implements ServletContainerInitializer {
// Automatic servlet container setup
}// Core logging event interface
public interface ILoggingEvent {
String getThreadName();
Level getLevel();
String getMessage();
Object[] getArgumentArray();
String getFormattedMessage();
String getLoggerName();
IThrowableProxy getThrowableProxy();
long getTimeStamp();
Map<String, String> getMDCPropertyMap();
Marker getMarker();
}
// Exception handling
public interface IThrowableProxy {
String getMessage();
String getClassName();
StackTraceElementProxy[] getStackTraceElementProxyArray();
IThrowableProxy getCause();
}
// Context information
public class LoggerContextVO {
String getName();
Map<String, String> getPropertyMap();
long getBirthTime();
}