Dev#7
Conversation
Introduce the microsphere-logging-log4j2 module to provide Log4j2 integration. Adds Log4j2Logger (adapter wrapping org.apache.logging.log4j.Logger), Log4j2LoggerFactory (registered via META-INF/services), and unit tests for the factory and logger behavior. Also updates README to list the new module. The factory sets its priority to NORMAL_PRIORITY - 5.
Add a lightweight TestingLogging implementation for tests and update test-suite to use it. Tests modified: LoggingMXBeanAdapterTest now initializes TestingLogging with sample logger levels and iterates over its supported logging levels; LoggingMXBeanRegistrarTest expectation updated to reflect the TestingLogging MBean name. Also update the service loader resource to register io.microsphere.logging.TestingLogging instead of the previous StandardLogging.
Introduce a new microsphere-logging-jdk module (pom, SPI registration, and tests) and move StandardLogging -> JDKLogging. Resolve logging levels via DefaultLoggingLevelsResolver.INSTANCE and add PRIORITY/ALL_LEVELS constants for JDK, Log4j2 and Logback; implement getPriority() to return those constants. Update parent pom and dependency management to include the new module, remove the old core test, and adjust README module list and small docs cleanup. Also update Log4j2/Logback factories and tests to use the new PRIORITY/ALL_LEVELS constants.
Replace dynamic resolution of logging levels with the ALL_LEVELS constant in getSupportedLoggingLevels. Update tests to import ALL_LEVELS, add a test for constant values (PRIORITY and ALL_LEVELS/LOGBACK_LEVELS), and remove redundant assertions from testGetPriority. This simplifies level retrieval and centralizes level definitions for consistency.
Move the assertEquals(10, PRIORITY) check from testGetPriority() to testConstants() to centralize constant verification. Removes the duplicate assertion from testGetPriority(), keeping the test focused on instance behavior.
Add unit tests in Log4j2LoggingTest to verify PRIORITY and ALL_LEVELS: assert PRIORITY equals -5 and ALL_LEVELS equals LOG4J2_LEVELS. Also add a test confirming logging.getPriority() returns PRIORITY. Added static imports for PRIORITY and ALL_LEVELS.
Change test setup to obtain the Logging implementation via ServiceLoader (loadFirstService(Logging.class)) instead of instantiating Log4j2Logging directly. Added imports for Logging and the service loader util, and cast the result to Log4j2Logging in setUp(). Removed the test resources META-INF/services/io.microsphere.logging.Logging file so the SPI resolution uses the real available provider(s) rather than the test-local registration.
🤖 Augment PR SummarySummary: This PR modularizes JDK logging support and expands logging framework integrations while improving test isolation. Changes:
Technical Notes: ServiceLoader-based discovery is now used in more tests to validate SPI wiring, and JMX registration tests are isolated via a dedicated testing implementation. 🤖 Was this summary useful? React with 👍 or 👎 |
| } | ||
|
|
||
| @Override | ||
| public String getParentLoggerName(String loggerName) { |
There was a problem hiding this comment.
TestingLogging#getParentLoggerName() always returns an empty string, which doesn’t match the Logging contract for non-root/non-existent loggers and can hide hierarchy-related bugs in tests that rely on parent resolution.
Severity: low
🤖 Was this useful? React with 👍 or 👎, or 🚀 if it prevented an incident/outage.
| */ | ||
| public class Log4j2LoggerFactory extends LoggerFactory { | ||
|
|
||
| public static final String LOG4J2_LOGGER_CLASS_NAME = "org.apache.logging.log4j.Logger"; |
There was a problem hiding this comment.
If LoggerFactory uses getDelegateLoggerClassName() as an availability check, using org.apache.logging.log4j.Logger can succeed with only log4j-api present, but Log4j2Logger/LoggerUtils depend on log4j-core and would then fail at runtime.
Severity: medium
🤖 Was this useful? React with 👍 or 👎, or 🚀 if it prevented an incident/outage.
This pull request introduces a new
microsphere-logging-jdkmodule for JDK logging support, updates the project structure and documentation, and improves test coverage and modularity. It also replaces direct usage of the JDK logging implementation in tests with a newTestingLoggingmock class, and updates service loader configurations accordingly.New JDK Logging Module:
microsphere-logging-jdkmodule, including its ownpom.xml, service loader configuration, and implementation classJDKLogging, which replaces the previousStandardLoggingclass. The new module provides JDK logging integration in a more modular fashion. (microsphere-logging-jdk/pom.xml[1]microsphere-logging-jdk/src/main/java/io/microsphere/logging/jdk/JDKLogging.java[2]microsphere-logging-jdk/src/main/resources/META-INF/services/io.microsphere.logging.Logging[3]JDKLoggingto ensure its correctness. (microsphere-logging-jdk/src/test/java/io/microsphere/logging/jdk/JDKLoggingTest.javamicrosphere-logging-jdk/src/test/java/io/microsphere/logging/jdk/JDKLoggingTest.javaR1-R112)Project Structure and Dependency Updates:
README.md) to list the newmicrosphere-logging-jdkandmicrosphere-logging-log4j2modules and removed the empty "Quick Examples" section. [1] [2]microsphere-logging-jdkas a dependency in themicrosphere-logging-dependenciesmodule. (microsphere-logging-dependencies/pom.xmlmicrosphere-logging-dependencies/pom.xmlR30-R35)Testing Improvements and Refactoring:
TestingLoggingclass to be used as a mock implementation in tests, replacing direct usage of the JDK logging implementation. Updated relevant tests and service loader configuration to use this class. (microsphere-logging-core/src/test/java/io/microsphere/logging/TestingLogging.java[1]microsphere-logging-core/src/test/resources/META-INF/services/io.microsphere.logging.Logging[2]microsphere-logging-core/src/test/java/io/microsphere/logging/jmx/LoggingMXBeanAdapterTest.java[3] [4] [5]microsphere-logging-core/src/test/java/io/microsphere/logging/jmx/LoggingMXBeanRegistrarTest.java[6]Log4j2 Integration:
Log4j2Loggeradapter class to support logging via Log4j2. (microsphere-logging-log4j2/src/main/java/io/microsphere/logging/log4j2/Log4j2Logger.javamicrosphere-logging-log4j2/src/main/java/io/microsphere/logging/log4j2/Log4j2Logger.javaR1-R123)Class and File Renaming:
StandardLoggingtoJDKLoggingand moved it from the core module to the new JDK module, updating constants, priorities, and documentation for clarity and consistency. (microsphere-logging-jdk/src/main/java/io/microsphere/logging/jdk/JDKLogging.java[1] [2]These changes modularize JDK logging support, improve testability, and extend the framework's extensibility for other logging systems.