You need to set additivity=false to your package specific logger to override the root threshold level of INFO.
I don't know how to do it using the properties notation.
I know only using the XML configuration form.
I strongly recommend to use XML format.
So let's switch to Log4j, version 1, XML. Your configuration is roughly equivalent to this XML (omitting the FILE appender):
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE log4j:configuration SYSTEM "log4j.dtd">
<log4j:configuration xmlns:log4j="http://jakarta.apache.org/log4j/">
<appender name="console" ...>
<logger name="com.my.package">
<level value="debug"/>
</logger>
<root>
<priority value="info"/>
<appender-ref ref="console"/>
</root>
</log4j:configuration>
Name it as log4j.xml, place it to the root of the class-path, and it will picked up automatically.
If you prefer and outside location, or different name, you have to use -Dlog4j.configuration=..path
, like this example, -Dlog4j.configuration=file:/C:\foo\bar\log4j_local.xml
on Windows.
Now let's set additivity=false to "com.my.package" logger.
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE log4j:configuration SYSTEM "log4j.dtd">
<log4j:configuration xmlns:log4j="http://jakarta.apache.org/log4j/">
<appender name="console" ...>
<logger name="com.my.package" additivity="false">
<level value="debug"/>
<appender-ref ref="console"/>
</logger>
<root>
<priority value="info"/>
<appender-ref ref="console"/>
</root>
</log4j:configuration>
Debug output from "com.my.package" will still get through despite root level is set to INFO.
You also need to add reference to appender to your logger:
<appender-ref ref="console"/>
Otherwise log4j complains about not having any appenders configured when logging from your package.
All other packages, like Hibernate or Spring, will be filtered on at lest INFO level importance level, no more spamming from them; only loggers from your package will get through with DEBUG level.
I found the inspiration on this post comment:
https://mcmap.net/q/142358/-log4j-log-output-of-a-specific-class-to-a-specific-appender
Logger
objects? – Bulgesome_name
, would that be likecom.my.package.some_name
or more likecalculator_logs
? Log4JLogger
s form a hierarchy based on the periods in their names, so it is usually best to name your loggers with the same names as the classes that are doing the logging. – Bulge