CtrlK
BlogDocsLog inGet started
Tessl Logo

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

Pending
Overview
Eval results
Files

network-logging.mddocs/

Network Logging

Network-based logging capabilities including TCP sockets, syslog protocol, email notifications, and SSL/TLS security for remote log transmission. Network appenders enable centralized logging and integration with log management systems.

Capabilities

SocketAppender

TCP socket-based appender for streaming log events to remote hosts with automatic reconnection and buffering.

/**
 * TCP socket appender for remote log transmission.
 * Supports automatic reconnection, queuing, and connection management.
 */
public class SocketAppender extends AppenderBase<ILoggingEvent> {
    private String remoteHost;
    private int port;
    private Duration reconnectionDelay = Duration.valueOf("30 seconds");
    private int queueSize = 128;
    private boolean includeCallerData = false;
    
    /**
     * Set the remote host to connect to.
     * @param host hostname or IP address
     */
    public void setRemoteHost(String host);
    
    /**
     * Get the remote host.
     * @return remote host
     */
    public String getRemoteHost();
    
    /**
     * Set the remote port to connect to.
     * @param port TCP port number
     */
    public void setPort(int port);
    
    /**
     * Get the remote port.
     * @return port number
     */
    public int getPort();
    
    /**
     * Set the delay before attempting reconnection after connection failure.
     * @param delay reconnection delay
     */
    public void setReconnectionDelay(Duration delay);
    
    /**
     * Get the reconnection delay.
     * @return reconnection delay
     */
    public Duration getReconnectionDelay();
    
    /**
     * Set the queue size for buffering events during connection issues.
     * @param queueSize maximum number of events to buffer
     */
    public void setQueueSize(int queueSize);
    
    /**
     * Get the queue size.
     * @return queue size
     */
    public int getQueueSize();
    
    /**
     * Enable inclusion of caller data in transmitted events.
     * @param includeCallerData true to include caller information
     */
    public void setIncludeCallerData(boolean includeCallerData);
    
    /**
     * Check if caller data is included.
     * @return true if caller data is included
     */
    public boolean isIncludeCallerData();
    
    @Override
    protected void append(ILoggingEvent event);
    
    @Override
    public void start();
    
    @Override
    public void stop();
}

SyslogAppender

Syslog protocol appender supporting RFC3164 and RFC5424 formats with facility and severity mapping.

/**
 * Syslog protocol appender for integration with syslog daemons.
 * Supports standard syslog facilities and severities.
 */
public class SyslogAppender extends AppenderBase<ILoggingEvent> {
    private String syslogHost = "localhost";
    private int port = 514;
    private String facility = "USER";
    private String suffixPattern;
    private boolean throwExceptionOnWrite = true;
    
    /**
     * Set the syslog server hostname.
     * @param syslogHost hostname of syslog server
     */
    public void setSyslogHost(String syslogHost);
    
    /**
     * Get the syslog server hostname.
     * @return syslog server hostname
     */
    public String getSyslogHost();
    
    /**
     * Set the syslog server port.
     * @param port UDP port (default 514)
     */
    public void setPort(int port);
    
    /**
     * Get the syslog server port.
     * @return port number
     */
    public int getPort();
    
    /**
     * Set the syslog facility.
     * @param facilityStr facility name (e.g., "USER", "LOCAL0", "MAIL")
     */
    public void setFacility(String facilityStr);
    
    /**
     * Get the syslog facility.
     * @return facility name
     */
    public String getFacility();
    
    /**
     * Set the pattern for formatting the message part of syslog entries.
     * @param suffixPattern message format pattern
     */
    public void setSuffixPattern(String suffixPattern);
    
    /**
     * Get the suffix pattern.
     * @return message format pattern
     */
    public String getSuffixPattern();
    
    /**
     * Control whether to throw exceptions on write failures.
     * @param throwExceptionOnWrite true to throw exceptions
     */
    public void setThrowExceptionOnWrite(boolean throwExceptionOnWrite);
    
    /**
     * Check if exceptions are thrown on write failures.
     * @return true if exceptions are thrown
     */
    public boolean isThrowExceptionOnWrite();
    
    @Override
    protected void append(ILoggingEvent event);
    
    @Override
    public void start();
    
    @Override
    public void stop();
}

SMTPAppender

Email-based appender for sending log events via SMTP with buffering and authentication support.

/**
 * SMTP appender for email-based log notifications.
 * Supports authentication, SSL/TLS, and event buffering.
 */
public class SMTPAppender extends AppenderBase<ILoggingEvent> {
    private String to;
    private String from;
    private String subject = "Log4j Log Messages";
    private String smtpHost;
    private int smtpPort = 25;
    private boolean STARTTLS = false;
    private boolean SSL = false;
    private String username;
    private String password;
    private int bufferSize = 512;
    
    /**
     * Set recipient email addresses (comma-separated).
     * @param to recipient addresses
     */
    public void setTo(String to);
    
    /**
     * Get recipient addresses.
     * @return recipient addresses
     */
    public String getTo();
    
    /**
     * Set sender email address.
     * @param from sender address
     */
    public void setFrom(String from);
    
    /**
     * Get sender address.
     * @return sender address
     */
    public String getFrom();
    
    /**
     * Set email subject line.
     * @param subject email subject
     */
    public void setSubject(String subject);
    
    /**
     * Get email subject.
     * @return email subject
     */
    public String getSubject();
    
    /**
     * Set SMTP server hostname.
     * @param smtpHost SMTP server hostname
     */
    public void setSMTPHost(String smtpHost);
    
    /**
     * Get SMTP server hostname.
     * @return SMTP server hostname
     */
    public String getSMTPHost();
    
    /**
     * Set SMTP server port.
     * @param smtpPort SMTP port (default 25)
     */
    public void setSMTPPort(int smtpPort);
    
    /**
     * Get SMTP server port.
     * @return SMTP port
     */
    public int getSMTPPort();
    
    /**
     * Enable STARTTLS for secure connection.
     * @param startTLS true to enable STARTTLS
     */
    public void setSTARTTLS(boolean startTLS);
    
    /**
     * Check if STARTTLS is enabled.
     * @return true if STARTTLS is enabled
     */
    public boolean isSTARTTLS();
    
    /**
     * Enable SSL for secure connection.
     * @param ssl true to enable SSL
     */
    public void setSSL(boolean ssl);
    
    /**
     * Check if SSL is enabled.
     * @return true if SSL is enabled
     */
    public boolean isSSL();
    
    /**
     * Set SMTP authentication username.
     * @param username authentication username
     */
    public void setUsername(String username);
    
    /**
     * Get authentication username.
     * @return username
     */
    public String getUsername();
    
    /**
     * Set SMTP authentication password.
     * @param password authentication password
     */
    public void setPassword(String password);
    
    /**
     * Get authentication password.
     * @return password
     */
    public String getPassword();
    
    /**
     * Set buffer size for batching events before sending email.
     * @param bufferSize number of events to buffer
     */
    public void setBufferSize(int bufferSize);
    
    /**
     * Get buffer size.
     * @return buffer size
     */
    public int getBufferSize();
    
    @Override
    protected void append(ILoggingEvent event);
    
    @Override
    public void start();
    
    @Override
    public void stop();
}

SSL/TLS Support

SSLContextFactoryBean

Factory for creating SSL contexts with keystore and truststore configuration.

/**
 * Factory for creating SSL contexts with custom keystore and truststore.
 */
public class SSLContextFactoryBean extends ContextAwareBase {
    private KeyStoreFactoryBean keyStore;
    private KeyStoreFactoryBean trustStore;
    private String keyManagerPassword;
    private String secureRandom;
    private String protocol = "SSL";
    
    /**
     * Set the keystore factory for client certificates.
     * @param keyStore keystore factory
     */
    public void setKeyStore(KeyStoreFactoryBean keyStore);
    
    /**
     * Get the keystore factory.
     * @return keystore factory
     */
    public KeyStoreFactoryBean getKeyStore();
    
    /**
     * Set the truststore factory for server certificate validation.
     * @param trustStore truststore factory
     */
    public void setTrustStore(KeyStoreFactoryBean trustStore);
    
    /**
     * Get the truststore factory.
     * @return truststore factory
     */
    public KeyStoreFactoryBean getTrustStore();
    
    /**
     * Set the key manager password.
     * @param keyManagerPassword password for key manager
     */
    public void setKeyManagerPassword(String keyManagerPassword);
    
    /**
     * Get the key manager password.
     * @return key manager password
     */
    public String getKeyManagerPassword();
    
    /**
     * Set the secure random algorithm.
     * @param secureRandomName secure random algorithm name
     */
    public void setSecureRandom(String secureRandomName);
    
    /**
     * Get the secure random algorithm.
     * @return secure random algorithm name
     */
    public String getSecureRandom();
    
    /**
     * Set the SSL protocol.
     * @param protocol SSL protocol (e.g., "TLS", "SSL")
     */
    public void setProtocol(String protocol);
    
    /**
     * Get the SSL protocol.
     * @return SSL protocol
     */
    public String getProtocol();
    
    /**
     * Create the SSL context.
     * @return configured SSL context
     * @throws Exception if SSL context creation fails
     */
    public SSLContext createContext() throws Exception;
}

KeyStoreFactoryBean

Factory for creating keystores from various sources.

/**
 * Factory for creating keystores from files, resources, or URLs.
 */
public class KeyStoreFactoryBean extends ContextAwareBase {
    private String location;
    private String password;
    private String provider;
    private String type = "JKS";
    
    /**
     * Set keystore location (file path, classpath resource, or URL).
     * @param location keystore location
     */
    public void setLocation(String location);
    
    /**
     * Get keystore location.
     * @return keystore location
     */
    public String getLocation();
    
    /**
     * Set keystore password.
     * @param password keystore password
     */
    public void setPassword(String password);
    
    /**
     * Get keystore password.
     * @return keystore password
     */
    public String getPassword();
    
    /**
     * Set security provider name.
     * @param provider security provider name
     */
    public void setProvider(String provider);
    
    /**
     * Get security provider name.
     * @return security provider name
     */
    public String getProvider();
    
    /**
     * Set keystore type.
     * @param type keystore type (e.g., "JKS", "PKCS12")
     */
    public void setType(String type);
    
    /**
     * Get keystore type.
     * @return keystore type
     */
    public String getType();
    
    /**
     * Create the keystore.
     * @return loaded keystore
     * @throws Exception if keystore creation fails
     */
    public KeyStore createKeyStore() throws Exception;
}

SSL Configuration Interface

/**
 * Interface for SSL-configurable components.
 */
public interface SSLConfigurable {
    /**
     * Get the SSL context.
     * @return SSL context
     */
    SSLContext getSslContext();
    
    /**
     * Set SSL configuration.
     * @param ssl SSL configuration
     */
    void setSsl(SSL ssl);
    
    /**
     * Get SSL configuration.
     * @return SSL configuration
     */
    SSL getSsl();
}

/**
 * SSL configuration aggregator.
 */
public class SSL implements SSLConfigurable {
    private KeyStoreFactoryBean keyStore;
    private KeyStoreFactoryBean trustStore;
    private SSLContextFactoryBean sslContextFactoryBean;
    
    /**
     * Set keystore configuration.
     * @param keyStore keystore factory
     */
    public void setKeyStore(KeyStoreFactoryBean keyStore);
    
    /**
     * Get keystore configuration.
     * @return keystore factory
     */
    public KeyStoreFactoryBean getKeyStore();
    
    /**
     * Set truststore configuration.
     * @param trustStore truststore factory
     */
    public void setTrustStore(KeyStoreFactoryBean trustStore);
    
    /**
     * Get truststore configuration.
     * @return truststore factory
     */
    public KeyStoreFactoryBean getTrustStore();
    
    @Override
    public SSLContext getSslContext();
    
    @Override
    public void setSsl(SSL ssl);
    
    @Override
    public SSL getSsl();
}

Server Components

ServerSocketAppender

Server-side socket appender for receiving log events from remote clients.

/**
 * Server socket appender for receiving log events from remote clients.
 */
public class ServerSocketAppender<E> extends AppenderBase<E> {
    private int port = 4560;
    private String address;
    private int clientQueueSize = 100;
    private int timeout = 0;
    
    /**
     * Set the port to listen on.
     * @param port listen port
     */
    public void setPort(int port);
    
    /**
     * Get the listen port.
     * @return port number
     */
    public int getPort();
    
    /**
     * Set the address to bind to.
     * @param address bind address (null for all interfaces)
     */
    public void setAddress(String address);
    
    /**
     * Get the bind address.
     * @return bind address
     */
    public String getAddress();
    
    /**
     * Set client queue size.
     * @param clientQueueSize queue size per client
     */
    public void setClientQueueSize(int clientQueueSize);
    
    /**
     * Get client queue size.
     * @return client queue size
     */
    public int getClientQueueSize();
    
    /**
     * Set connection timeout.
     * @param timeout timeout in milliseconds (0 = no timeout)
     */
    public void setTimeout(int timeout);
    
    /**
     * Get connection timeout.
     * @return timeout in milliseconds
     */
    public int getTimeout();
    
    @Override
    protected void append(E eventObject);
    
    @Override
    public void start();
    
    @Override
    public void stop();
}

Utility Classes

SocketConnector Interface

Interface for creating socket connections with custom implementations.

/**
 * Interface for creating socket connections.
 * Allows custom socket creation strategies.
 */
public interface SocketConnector {
    /**
     * Create a new socket connection to the specified address and port.
     * @param address target address
     * @param port target port
     * @return connected socket
     * @throws Exception if connection fails
     */
    Socket newSocket(InetAddress address, int port) throws Exception;
    
    /**
     * Create a new socket connection to the specified host and port.
     * @param host target hostname
     * @param port target port
     * @return connected socket
     * @throws Exception if connection fails
     */
    Socket newSocket(String host, int port) throws Exception;
}

DefaultSocketConnector

Default implementation of SocketConnector.

/**
 * Default socket connector implementation using standard TCP sockets.
 */
public class DefaultSocketConnector implements SocketConnector {
    private int connectionTimeout = 0;
    
    /**
     * Set connection timeout.
     * @param connectionTimeout timeout in milliseconds
     */
    public void setConnectionTimeout(int connectionTimeout);
    
    /**
     * Get connection timeout.
     * @return timeout in milliseconds
     */
    public int getConnectionTimeout();
    
    @Override
    public Socket newSocket(InetAddress address, int port) throws Exception;
    
    @Override
    public Socket newSocket(String host, int port) throws Exception;
}

SyslogConstants

Constants for syslog facilities and severities.

/**
 * Constants for syslog protocol implementation.
 */
public class SyslogConstants {
    // Syslog facilities
    public static final int KERN_FACILITY = 0;
    public static final int USER_FACILITY = 1;
    public static final int MAIL_FACILITY = 2;
    public static final int DAEMON_FACILITY = 3;
    public static final int AUTH_FACILITY = 4;
    public static final int SYSLOG_FACILITY = 5;
    public static final int LPR_FACILITY = 6;
    public static final int NEWS_FACILITY = 7;
    public static final int UUCP_FACILITY = 8;
    public static final int CRON_FACILITY = 9;
    public static final int AUTHPRIV_FACILITY = 10;
    public static final int FTP_FACILITY = 11;
    public static final int LOCAL0_FACILITY = 16;
    public static final int LOCAL1_FACILITY = 17;
    public static final int LOCAL2_FACILITY = 18;
    public static final int LOCAL3_FACILITY = 19;
    public static final int LOCAL4_FACILITY = 20;
    public static final int LOCAL5_FACILITY = 21;
    public static final int LOCAL6_FACILITY = 22;
    public static final int LOCAL7_FACILITY = 23;
    
    // Syslog severities
    public static final int EMERGENCY_SEVERITY = 0;
    public static final int ALERT_SEVERITY = 1;
    public static final int CRITICAL_SEVERITY = 2;
    public static final int ERROR_SEVERITY = 3;
    public static final int WARNING_SEVERITY = 4;
    public static final int NOTICE_SEVERITY = 5;
    public static final int INFO_SEVERITY = 6;
    public static final int DEBUG_SEVERITY = 7;
}

Usage Examples

Basic Socket Appender

import ch.qos.logback.core.net.SocketAppender;
import ch.qos.logback.core.util.Duration;

// Create socket appender for remote logging
SocketAppender socketAppender = new SocketAppender();
socketAppender.setContext(context);
socketAppender.setRemoteHost("log-server.example.com");
socketAppender.setPort(4560);
socketAppender.setReconnectionDelay(Duration.valueOf("10 seconds"));
socketAppender.setQueueSize(256);
socketAppender.setIncludeCallerData(true);
socketAppender.start();

// Use with other appenders
logger.addAppender(socketAppender);

Syslog Appender Configuration

import ch.qos.logback.core.net.SyslogAppender;

// Configure syslog appender
SyslogAppender syslogAppender = new SyslogAppender();
syslogAppender.setContext(context);
syslogAppender.setSyslogHost("syslog.example.com");
syslogAppender.setPort(514);
syslogAppender.setFacility("LOCAL0");
syslogAppender.setSuffixPattern("%logger{20} - %msg");
syslogAppender.start();

SMTP Appender with Authentication

import ch.qos.logback.core.net.SMTPAppender;

// Configure SMTP appender for error notifications
SMTPAppender smtpAppender = new SMTPAppender();
smtpAppender.setContext(context);
smtpAppender.setTo("admin@example.com,ops@example.com");
smtpAppender.setFrom("app@example.com");
smtpAppender.setSubject("Application Error Alert");
smtpAppender.setSMTPHost("smtp.example.com");
smtpAppender.setSMTPPort(587);
smtpAppender.setSTARTTLS(true);
smtpAppender.setUsername("app@example.com");
smtpAppender.setPassword("smtp-password");
smtpAppender.setBufferSize(1); // Send immediately on each event
smtpAppender.start();

// Use with error filter
ErrorFilter errorFilter = new ErrorFilter();
errorFilter.start();
smtpAppender.addFilter(errorFilter);

SSL-Enabled Socket Appender

import ch.qos.logback.core.net.ssl.*;

// Create SSL configuration
KeyStoreFactoryBean keyStore = new KeyStoreFactoryBean();
keyStore.setContext(context);
keyStore.setLocation("client-keystore.jks");
keyStore.setPassword("keystore-password");

KeyStoreFactoryBean trustStore = new KeyStoreFactoryBean();
trustStore.setContext(context);
trustStore.setLocation("client-truststore.jks");
trustStore.setPassword("truststore-password");

SSLContextFactoryBean sslContext = new SSLContextFactoryBean();
sslContext.setContext(context);
sslContext.setKeyStore(keyStore);
sslContext.setTrustStore(trustStore);

SSL ssl = new SSL();
ssl.setKeyStore(keyStore);
ssl.setTrustStore(trustStore);

// Create SSL socket appender (custom implementation)
SSLSocketAppender sslAppender = new SSLSocketAppender();
sslAppender.setContext(context);
sslAppender.setRemoteHost("secure-log-server.example.com");
sslAppender.setPort(6514);
sslAppender.setSsl(ssl);
sslAppender.start();

Server Socket for Log Collection

import ch.qos.logback.core.net.server.ServerSocketAppender;

// Create server socket appender to receive logs
ServerSocketAppender<ILoggingEvent> serverAppender = new ServerSocketAppender<>();
serverAppender.setContext(context);
serverAppender.setPort(4560);
serverAppender.setAddress("0.0.0.0"); // Listen on all interfaces
serverAppender.setClientQueueSize(1000);
serverAppender.setTimeout(30000); // 30 second timeout
serverAppender.start();

// Server will accept connections and forward events to attached appenders
FileAppender<ILoggingEvent> fileAppender = new FileAppender<>();
fileAppender.setContext(context);
fileAppender.setFile("collected-logs.log");
fileAppender.setEncoder(encoder);
fileAppender.start();

serverAppender.addAppender(fileAppender);

Custom Network Appender

import ch.qos.logback.core.AppenderBase;
import java.net.DatagramSocket;
import java.net.DatagramPacket;
import java.net.InetAddress;

public class UDPAppender<E> extends AppenderBase<E> {
    private String host = "localhost";
    private int port = 9999;
    private DatagramSocket socket;
    
    @Override
    protected void append(E eventObject) {
        try {
            String message = eventObject.toString();
            byte[] buffer = message.getBytes("UTF-8");
            
            DatagramPacket packet = new DatagramPacket(
                buffer, buffer.length,
                InetAddress.getByName(host), port
            );
            
            socket.send(packet);
        } catch (Exception e) {
            addError("Failed to send UDP packet", e);
        }
    }
    
    @Override
    public void start() {
        try {
            socket = new DatagramSocket();
            super.start();
        } catch (Exception e) {
            addError("Failed to create UDP socket", e);
        }
    }
    
    @Override
    public void stop() {
        if (socket != null && !socket.isClosed()) {
            socket.close();
        }
        super.stop();
    }
    
    public void setHost(String host) {
        this.host = host;
    }
    
    public void setPort(int port) {
        this.port = port;
    }
}

Security Considerations

  1. SSL/TLS: Use SSL for sensitive log data transmission
  2. Authentication: Configure SMTP authentication for email appenders
  3. Firewall: Ensure appropriate firewall rules for network appenders
  4. Credentials: Store passwords securely, avoid hardcoding
  5. Certificate Validation: Properly configure truststores for SSL
  6. Network Timeouts: Set appropriate timeouts to prevent hanging connections

Performance and Reliability

  1. Buffering: Use queues and buffers to handle network latency
  2. Reconnection: Configure appropriate reconnection delays
  3. Fallback: Consider local fallback appenders for network failures
  4. Monitoring: Monitor network appender connection status
  5. Resource Management: Properly close network connections on shutdown

Install with Tessl CLI

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

docs

appenders.md

configuration.md

encoders-layouts.md

filters-evaluators.md

index.md

model-framework.md

network-logging.md

patterns.md

rolling-policies.md

utilities.md

tile.json