I am currently working on an application that is using Log4j2 for logging.
Below is the Log4j2.xml file
<?xml version="1.0" encoding="UTF-8"?>
<Configuration status="debug" packages="myappsystem">
<Appenders>
<MyDockerAppender name="STDOUT" />
</Appenders>
<Loggers>
<logger name="org.springframework" level="ERROR"/>
<logger name="myappsystem" level="INFO"/>
<Root level="ERROR" additivity="true" includeLocation="true">
<AppenderRef ref="STDOUT"/>
</Root>
</Loggers>
Now the challenge that I am facing here is the logger seems to be logging only when I do something like below
private static final Logger LOGGER = LogManager.getLogger("myappsystem");
LOGGER.info("Entering method");
The problem here is, It is not giving me the details of the class files from which this particular line is being logged.
So, I tried to do something like below:
private static final Logger LOGGER = LogManager.getLogger(MyServiceImpl.class);
This doesn't seem to be working. Any ideas on where I am going wrong?
Your logger is configured for
<logger name="myappsystem" level="INFO"/>
and therefore
LogManager.getLogger("myappsystem");
works.
If you use
LogManager.getLogger(MyServiceImpl.class);
you have to configure a Logger starting with the fully qualified Classname (with packages) like you use in <logger name="org.springframework" level="ERROR"/>
So ie
<logger name="my.project.package.structure" level="INFO"/>
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.