Class Log4j2Log

java.lang.Object
com.mcpdbwizard.pub.GenericLog
com.mcpdbwizard.pub.Log4j2Log
All Implemented Interfaces:
LogInterface

public class Log4j2Log extends GenericLog implements LogInterface
An implementation of LogInterface that routes every message to Apache Log4j 2. This lets MCPDBWizard software — and the JDBC code the wizard generates — log through a Log4j 2 configuration the host application already owns, instead of MCPDBWizard's own file/console logs.

The five LogInterface severities map onto Log4j 2 levels as follows. Because Log4j 2 has a dedicated FATAL level, syserror (reserved for "really bad and never supposed to happen") is distinguished from ordinary error:

LogInterface severity to Log4j 2 level mapping
LogInterfaceLog4j 2
debugDEBUG
infoINFO
warningWARN
errorERROR
syserrorFATAL

The isModal and isLogged flags carried by the detailed LogInterface methods are accepted and ignored: Log4j 2 has no modal-dialog concept, and whether a message is actually written is decided by the configured Log4j 2 level filtering, not by this class. Debug messages additionally honour GenericLog.debugOn() / GenericLog.debugOff() (off by default), matching the other LogInterface implementations.

The exception-taking error/syserror methods pass the Throwable straight to Log4j 2, so the backend records the full stack trace rather than just the message text.

This backend depends only on the Log4j 2 API (log4j-api); the host application supplies the Log4j 2 core implementation and its configuration.

See LogInterface

Copyright 2003-2026 ATB Consultancy Services Ltd (formerly Orinda Software Ltd, Dublin, Ireland)

Version:
7
Author:
devteam@mcpdbwizard.com
  • Constructor Details

    • Log4j2Log

      public Log4j2Log()
      Create an instance of Log4j2Log backed by a logger named after this class.
    • Log4j2Log

      public Log4j2Log(String loggerName)
      Create an instance of Log4j2Log backed by a logger with the given name.
      Parameters:
      loggerName - the Log4j 2 logger name to use (for example a fully qualified class name or a functional category).
    • Log4j2Log

      public Log4j2Log(Class<?> clazz)
      Create an instance of Log4j2Log backed by a logger named after the given class.
      Parameters:
      clazz - the class whose name is used as the Log4j 2 logger name.
  • Method Details

    • writeMessage

      protected void writeMessage(String messageType, String messageText, boolean isModal, boolean isLogged)
      Route a formatted message to the Log4j 2 level that corresponds to its severity. Log4j 2 applies its own level filtering, so a message emitted here may still be discarded downstream.
      Specified by:
      writeMessage in class GenericLog
      Parameters:
      messageType - one of the DEBUG, INFO, WARN, ERROR or SYSERR constants defined in LogInterface.
      messageText - the message text.
      isModal - ignored; Log4j 2 has no modal-dialog concept.
      isLogged - ignored; the configured Log4j 2 level filtering decides what is written.
    • error

      public void error(Exception theException, boolean isModal, boolean isLogged)
      Log an error, passing the exception to Log4j 2 so the full stack trace is recorded.
      Specified by:
      error in interface LogInterface
      Overrides:
      error in class GenericLog
      Parameters:
      theException - the exception to log.
      isModal - ignored; Log4j 2 has no modal-dialog concept.
      isLogged - ignored; the configured Log4j 2 level filtering decides what is written.
    • syserror

      public void syserror(Exception theException, boolean isModal, boolean isLogged)
      Log a serious error at FATAL, passing the exception to Log4j 2 so the full stack trace is recorded.
      Specified by:
      syserror in interface LogInterface
      Overrides:
      syserror in class GenericLog
      Parameters:
      theException - the exception to log.
      isModal - ignored; Log4j 2 has no modal-dialog concept.
      isLogged - ignored; the configured Log4j 2 level filtering decides what is written.
    • flush

      public void flush()
      Required by LogInterface but not used: Log4j 2 manages its own buffering and flushing.
      Specified by:
      flush in interface LogInterface
      Specified by:
      flush in class GenericLog
    • getCurrentLog

      public String getCurrentLog()
      Returns the name of the Log4j 2 logger messages are routed through.
      Specified by:
      getCurrentLog in interface LogInterface
      Specified by:
      getCurrentLog in class GenericLog
      Returns:
      the Log4j 2 logger name (not a file path; the actual destination is determined by the Log4j 2 configuration).