CtrlK
BlogDocsLog inGet started
Tessl Logo

tessl/maven-org-apache-logging-log4j--log4j-1-2-api

The Apache Log4j 1.x Compatibility API providing a bridge to Log4j 2.x implementations

Pending
Overview
Eval results
Files

logging.mddocs/

Core Logging

The core logging functionality provides the primary interfaces for application logging through Logger, LogManager, Level, and Category classes.

Primary Classes

Logger

public class Logger extends Category {
    // Static factory methods
    public static Logger getLogger(Class clazz);
    public static Logger getLogger(String name);
    public static Logger getRootLogger();
    
    // Level checking methods
    public boolean isTraceEnabled();
    public boolean isDebugEnabled();
    public boolean isInfoEnabled();
    
    // Trace logging methods
    public void trace(Object message);
    public void trace(Object message, Throwable t);
}

Parameters:

  • clazz - Class object used to determine logger name
  • name - String name of the logger
  • message - Log message object (toString() will be called)
  • t - Throwable for stack trace logging

Returns:

  • Logger instance for the specified class or name
  • boolean indicating if the specified level is enabled

LogManager

public final class LogManager {
    // Logger retrieval
    public static Logger getLogger(Class clazz);
    public static Logger getLogger(String name);
    public static Logger getRootLogger();
    public static Logger exists(String name);
    
    // Logger enumeration
    public static Enumeration getCurrentLoggers();
    
    // Configuration management
    public static void resetConfiguration();
    public static void shutdown();
    
    // Configuration constants
    public static final String DEFAULT_CONFIGURATION_FILE;
    public static final String DEFAULT_CONFIGURATION_KEY;
}

Parameters:

  • clazz - Class object for logger name derivation
  • name - String name of the logger to retrieve or check

Returns:

  • Logger instance or null if not found (exists method)
  • Enumeration of current logger instances

Category (Legacy)

public class Category implements AppenderAttachable {
    // Static factory methods
    public static Category getInstance(String name);
    public static Category getRoot();
    
    // Level methods
    public Level getLevel();
    public void setLevel(Level level);
    public Priority getPriority();
    public void setPriority(Priority priority);
    
    // Logging methods
    public void debug(Object message);
    public void debug(Object message, Throwable t);
    public void info(Object message);
    public void info(Object message, Throwable t);
    public void warn(Object message);
    public void warn(Object message, Throwable t);
    public void error(Object message);
    public void error(Object message, Throwable t);
    public void fatal(Object message);
    public void fatal(Object message, Throwable t);
    public void log(Priority priority, Object message);
    public void log(Priority priority, Object message, Throwable t);
    
    // Level checking
    public boolean isDebugEnabled();
    public boolean isInfoEnabled();
    public boolean isEnabledFor(Priority level);
    
    // Appender management
    public void addAppender(Appender appender);
    public void removeAppender(Appender appender);
    public void removeAllAppenders();
    public Enumeration getAllAppenders();
    public Appender getAppender(String name);
    public boolean isAttached(Appender appender);
}

Parameters:

  • name - String name for the category
  • level - Level object to set
  • priority - Priority object to set
  • message - Log message object
  • t - Throwable for exception logging
  • appender - Appender to add/remove

Returns:

  • Category instance
  • Level or Priority object
  • boolean for level checks and appender operations
  • Enumeration of appenders
  • Appender instance or null

Log Levels

Level

public class Level extends Priority implements Serializable {
    // Standard levels
    public static final Level OFF;
    public static final Level FATAL;
    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;
    
    // Level constants
    public static final int TRACE_INT = 5000;
    
    // Conversion methods
    public static Level toLevel(String sArg);
    public static Level toLevel(int val);
    public static Level toLevel(String sArg, Level defaultLevel);
    public static Level toLevel(int val, Level defaultLevel);
}

Parameters:

  • sArg - String representation of level (e.g., "DEBUG", "INFO")
  • val - Integer value of level
  • defaultLevel - Default level to return if conversion fails

Returns:

  • Level object corresponding to the input
  • Default level if conversion fails

Priority (Legacy)

public class Priority {
    // Priority constants
    public static final int OFF_INT;
    public static final int FATAL_INT;
    public static final int ERROR_INT;
    public static final int WARN_INT;
    public static final int INFO_INT;
    public static final int DEBUG_INT;
    public static final int ALL_INT;
    
    // Legacy priority objects (deprecated)
    public static final Priority FATAL;
    public static final Priority ERROR;
    public static final Priority WARN;
    public static final Priority INFO;
    public static final Priority DEBUG;
    
    // Comparison methods
    public boolean isGreaterOrEqual(Priority r);
    
    // Conversion methods
    public int toInt();
    public String toString();
    
    // Deprecated methods
    @Deprecated
    public static Priority toPriority(String sArg);
    @Deprecated
    public static Priority toPriority(int val);
}

Parameters:

  • r - Priority object to compare against
  • sArg - String representation of priority
  • val - Integer value of priority

Returns:

  • boolean for comparison operations
  • int priority level value
  • String representation of priority
  • Priority object (deprecated methods)

Usage Examples

Basic Logger Usage

import org.apache.log4j.Logger;

public class MyService {
    private static final Logger logger = Logger.getLogger(MyService.class);
    
    public void processData(String data) {
        logger.info("Processing data: " + data);
        
        try {
            // Process the data
            if (logger.isDebugEnabled()) {
                logger.debug("Data processed successfully");
            }
        } catch (Exception e) {
            logger.error("Failed to process data", e);
            throw e;
        }
    }
}

Level Checking and Conditional Logging

import org.apache.log4j.Logger;
import org.apache.log4j.Level;

public class PerformanceService {
    private static final Logger logger = Logger.getLogger(PerformanceService.class);
    
    public void expensiveOperation() {
        if (logger.isDebugEnabled()) {
            String debugInfo = buildExpensiveDebugString();
            logger.debug("Starting operation with: " + debugInfo);
        }
        
        // Check specific levels
        if (logger.isEnabledFor(Level.TRACE)) {
            logger.trace("Detailed trace information");
        }
    }
}

Category Usage (Legacy)

import org.apache.log4j.Category;
import org.apache.log4j.Priority;

public class LegacyService {
    private static final Category cat = Category.getInstance("LegacyService");
    
    public void performTask() {
        cat.log(Priority.INFO, "Task started");
        
        try {
            // Task implementation
            cat.debug("Task in progress");
        } catch (Exception e) {
            cat.error("Task failed", e);
        }
    }
}

Install with Tessl CLI

npx tessl i tessl/maven-org-apache-logging-log4j--log4j-1-2-api

docs

appenders.md

builders.md

configuration.md

context.md

index.md

layouts.md

logging.md

spi.md

tile.json