Your problem is more than likely not with the registration framework, but with the layout.
Specific example
so35592962/App.java
package so35592962; import org.apache.logging.log4j.*; import so35592962.sub.OtherClass; public class App { public static final Logger logger = LogManager.getLogger(); public static void main(String[] args) { logger.error("in App.main"); OtherClass.act(); } }
so35592962/sub/OtherClass.java
package so35592962.sub; import static so35592962.App.logger; public class OtherClass { public static void act() { logger.error("OtherClass.act"); } }
So you can see that this is absolutely what you want: classes that use the same registrar. You can use Log4J2 for this.
Now I am adding the magic log4j2.xml file
<?xml version="1.0" encoding="UTF-8"?> <Configuration status="WARN"> <Appenders> <Console name="Console" target="SYSTEM_OUT"> <PatternLayout pattern="%d{HH:mm:ss.SSS} [%t] %-5level %C{36} - %msg%n"/> </Console> </Appenders> <Loggers> <Root level="error"> <AppenderRef ref="Console"/> </Root> </Loggers> </Configuration>
The launch of this will be printed:
12:05:28.834 [main] ERROR so35592962.App - in App.main 12:05:28.836 [main] ERROR so35592962.sub.OtherClass - OtherClass.act
Look, there are different class names here! However, I used Log4J2.
What happened here?
Pay attention to the pattern used in the PatternLayout tag:
%d{HH:mm:ss.SSS} [%t] %-5level %C{36} - %msg%n
Standard examples and what you usually see on the Internet use the %L pattern. This template should display the name of the registrar. But you said you didn’t want this. Fortunately, other templates exist. %C will display the class name instead of the log name. This is the template used here.
According to the PatternLayout documentation , the %C pattern does the following:
Displays the fully qualified class name of the caller issuing the logging request.
Important note also mentioned in the documentation:
Creating a caller class name (location information) is an expensive operation and can affect performance. Use with caution.