CtrlK
BlogDocsLog inGet started
Tessl Logo

tessl/maven-org-apache-logging-log4j--log4j-slf4j2-impl

SLF4J 2 provider that bridges SLF4J 2 logging calls to the Apache Log4j API

Pending
Overview
Eval results
Files

marker-logging.mddocs/

Marker-Based Logging

Enhanced logging with markers for categorization, filtering, and contextual organization of log events. Markers provide a way to tag log events with additional metadata for advanced filtering and routing.

Capabilities

Marker Creation and Management

Create and manage markers using the MarkerFactory.

/**
 * Get or create a marker with the given name
 * @param name The marker name
 * @return Marker instance
 * @throws IllegalArgumentException if name is null
 */
Marker getMarker(String name);

/**
 * Check if a marker with the given name exists
 * @param name The marker name
 * @return true if marker exists
 */
boolean exists(String name);

/**
 * Detach marker (not supported - always returns false)
 * @param name The marker name
 * @return false (Log4j does not support detached markers)
 */
boolean detachMarker(String name);

/**
 * Get detached marker (returns attached marker with warning)
 * @param name The marker name
 * @return The marker (attached, not detached)
 */
Marker getDetachedMarker(String name);

Usage Examples:

import org.slf4j.Marker;
import org.slf4j.MarkerFactory;

// Create/get markers
Marker securityMarker = MarkerFactory.getMarker("SECURITY");
Marker auditMarker = MarkerFactory.getMarker("AUDIT");
Marker performanceMarker = MarkerFactory.getMarker("PERFORMANCE");

// Check if marker exists
if (MarkerFactory.exists("SECURITY")) {
    // marker already exists
}

Marker Properties and Hierarchy

Work with marker properties and hierarchical relationships.

/**
 * Get the marker name
 * @return The marker name
 */
String getName();

/**
 * Add a child marker (creates parent-child relationship)
 * @param reference The child marker to add
 * @throws IllegalArgumentException if reference is null
 */
void add(Marker reference);

/**
 * Remove a child marker
 * @param reference The child marker to remove
 * @return true if the marker was removed
 */
boolean remove(Marker reference);

/**
 * Check if this marker has child markers
 * @return true if marker has children
 */
boolean hasChildren();

/**
 * Check if this marker has parent references
 * @return true if marker has references
 */
boolean hasReferences();

/**
 * Get iterator over child markers
 * @return Iterator over child markers
 */
Iterator<Marker> iterator();

/**
 * Check if this marker contains another marker (hierarchically)
 * @param other The marker to check for
 * @return true if this marker contains the other marker
 */
boolean contains(Marker other);

/**
 * Check if this marker contains a marker with the given name
 * @param name The marker name to check for
 * @return true if this marker contains a marker with the given name
 */
boolean contains(String name);

Usage Examples:

// Create hierarchical markers
Marker securityMarker = MarkerFactory.getMarker("SECURITY");
Marker authMarker = MarkerFactory.getMarker("AUTH");
Marker authFailureMarker = MarkerFactory.getMarker("AUTH_FAILURE");

// Build hierarchy
securityMarker.add(authMarker);
authMarker.add(authFailureMarker);

// Check hierarchy
if (securityMarker.contains("AUTH_FAILURE")) {
    // AUTH_FAILURE is contained within SECURITY hierarchy
}

// Iterate over children
for (Iterator<Marker> it = securityMarker.iterator(); it.hasNext(); ) {
    Marker child = it.next();
    logger.debug("Child marker: {}", child.getName());
}

Trace Level with Markers

Trace-level logging with marker support.

void trace(Marker marker, String msg);
void trace(Marker marker, String format, Object arg);
void trace(Marker marker, String format, Object arg1, Object arg2);
void trace(Marker marker, String format, Object... arguments);
void trace(Marker marker, String msg, Throwable t);
boolean isTraceEnabled(Marker marker);

Usage Examples:

Marker performanceMarker = MarkerFactory.getMarker("PERFORMANCE");

logger.trace(performanceMarker, "Method execution started");
logger.trace(performanceMarker, "Processing {} items", itemCount);

if (logger.isTraceEnabled(performanceMarker)) {
    logger.trace(performanceMarker, "Detailed timing: {}", getDetailedTiming());
}

Debug Level with Markers

Debug-level logging with marker support.

void debug(Marker marker, String msg);
void debug(Marker marker, String format, Object arg);
void debug(Marker marker, String format, Object arg1, Object arg2);
void debug(Marker marker, String format, Object... arguments);
void debug(Marker marker, String msg, Throwable t);
boolean isDebugEnabled(Marker marker);

Usage Examples:

Marker databaseMarker = MarkerFactory.getMarker("DATABASE");

logger.debug(databaseMarker, "Executing query");
logger.debug(databaseMarker, "Query executed in {} ms", executionTime);
logger.debug(databaseMarker, "Connection pool stats: active={}, idle={}", active, idle);

Info Level with Markers

Info-level logging with marker support.

void info(Marker marker, String msg);
void info(Marker marker, String format, Object arg);
void info(Marker marker, String format, Object arg1, Object arg2);
void info(Marker marker, String format, Object... arguments);
void info(Marker marker, String msg, Throwable t);
boolean isInfoEnabled(Marker marker);

Usage Examples:

Marker auditMarker = MarkerFactory.getMarker("AUDIT");

logger.info(auditMarker, "User action recorded");
logger.info(auditMarker, "User {} performed action {}", userId, action);
logger.info(auditMarker, "Resource {} accessed by {} at {}", resource, user, timestamp);

Warn Level with Markers

Warning-level logging with marker support.

void warn(Marker marker, String msg);
void warn(Marker marker, String format, Object arg);
void warn(Marker marker, String format, Object arg1, Object arg2);
void warn(Marker marker, String format, Object... arguments);
void warn(Marker marker, String msg, Throwable t);
boolean isWarnEnabled(Marker marker);

Usage Examples:

Marker securityMarker = MarkerFactory.getMarker("SECURITY");

logger.warn(securityMarker, "Suspicious activity detected");
logger.warn(securityMarker, "Failed login attempt from {}", ipAddress);
logger.warn(securityMarker, "Rate limit exceeded for user {} from {}", userId, ipAddress);

Error Level with Markers

Error-level logging with marker support.

void error(Marker marker, String msg);
void error(Marker marker, String format, Object arg);
void error(Marker marker, String format, Object arg1, Object arg2);
void error(Marker marker, String format, Object... arguments);
void error(Marker marker, String msg, Throwable t);
boolean isErrorEnabled(Marker marker);

Usage Examples:

Marker systemMarker = MarkerFactory.getMarker("SYSTEM");

logger.error(systemMarker, "Critical system failure");
logger.error(systemMarker, "Service {} is unavailable", serviceName);
logger.error(systemMarker, "Payment processing failed for transaction {}", transactionId, exception);

Common Marker Patterns

Security and Audit Markers

// Security-related markers
Marker SECURITY = MarkerFactory.getMarker("SECURITY");
Marker AUTH = MarkerFactory.getMarker("AUTH");
Marker AUTHORIZATION = MarkerFactory.getMarker("AUTHORIZATION");
Marker AUDIT = MarkerFactory.getMarker("AUDIT");

// Build security hierarchy
SECURITY.add(AUTH);
SECURITY.add(AUTHORIZATION);

// Usage
logger.warn(AUTH, "Invalid login attempt for user {}", username);
logger.info(AUDIT, "User {} accessed resource {}", userId, resourceId);

Performance Monitoring Markers

Marker PERFORMANCE = MarkerFactory.getMarker("PERFORMANCE");
Marker SLOW_QUERY = MarkerFactory.getMarker("SLOW_QUERY");
Marker MEMORY_WARNING = MarkerFactory.getMarker("MEMORY_WARNING");

PERFORMANCE.add(SLOW_QUERY);
PERFORMANCE.add(MEMORY_WARNING);

// Usage
logger.warn(SLOW_QUERY, "Query took {} ms: {}", duration, query);
logger.warn(MEMORY_WARNING, "Memory usage at {}%", memoryPercent);

Business Domain Markers

Marker ORDER_PROCESSING = MarkerFactory.getMarker("ORDER_PROCESSING");
Marker PAYMENT = MarkerFactory.getMarker("PAYMENT");
Marker INVENTORY = MarkerFactory.getMarker("INVENTORY");

// Usage in business logic
logger.info(ORDER_PROCESSING, "Order {} created for customer {}", orderId, customerId);
logger.error(PAYMENT, "Payment failed for order {}", orderId, paymentException);
logger.warn(INVENTORY, "Low stock alert for product {}", productId);

Advanced Marker Usage

Converting External Markers

The implementation can convert markers from other SLF4J implementations.

/**
 * Convert an existing SLF4J marker to Log4j-compatible marker
 * @param marker The SLF4J marker to convert
 * @return Log4j-compatible marker
 */
Marker getMarker(Marker marker);

Marker Lifecycle Management

// Marker creation is thread-safe and cached
Marker marker1 = MarkerFactory.getMarker("TEST");
Marker marker2 = MarkerFactory.getMarker("TEST");
// marker1 == marker2 (same instance)

// Markers persist for the lifetime of the application
// No explicit cleanup required

Integration with Log4j Configuration

Markers can be used in Log4j configuration for filtering and routing:

<!-- log4j2.xml example -->
<Configuration>
    <Appenders>
        <File name="SecurityLog" fileName="security.log">
            <MarkerFilter marker="SECURITY" onMatch="ACCEPT" onMismatch="DENY"/>
        </File>
        <File name="AuditLog" fileName="audit.log">
            <MarkerFilter marker="AUDIT" onMatch="ACCEPT" onMismatch="DENY"/>
        </File>
    </Appenders>
    <Loggers>
        <Root level="info">
            <AppenderRef ref="SecurityLog"/>
            <AppenderRef ref="AuditLog"/>
        </Root>
    </Loggers>
</Configuration>

Install with Tessl CLI

npx tessl i tessl/maven-org-apache-logging-log4j--log4j-slf4j2-impl

docs

fluent-logging.md

index.md

marker-logging.md

marker-management.md

mdc-support.md

standard-logging.md

tile.json