Reputation: 97
I am using logback.xml for logging. I want to disable the logs from 3rd party jars/SDKs. For this I used the log level="OFF" for that jar, but still the logs are getting logged. Next I tried using the same log level for one of my files in codebase, I was able to disable the logs for my file.
Below is my logback config :
'''
<appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
<encoder>
<pattern> Some pattern </pattern>
</encoder>
</appender>
<logger name="<sdk file path>" level="OFF"/> !--- This doesn't work ---!
<logger name="<file from my codebase>" level="OFF"/> !--- This works ---!
<root level="INFO">
<appender-ref ref="STDOUT"/>
</root>
'''
Upvotes: 1
Views: 557
Reputation: 27356
A library can use any name
it likes for a logger so the name
will not necessarily match the path of the library.
The %logger
field in the pattern
gives the name
of the logger so you will see the actual name in the logging output. If you see output that you want to suppress, use the name
from the log (or a prefix) in the logger
element.
I would also recommend setting the root
to the lowest level and then increasing the level for the specific libraries that you are interested in.
<logger name="myloggername" level="DEBUG"/>
<root level="ERROR">
<appender-ref ref="STDOUT"/>
</root>
Upvotes: 3