0

How to disable logger (print output) of a java library (jar) used in a java program ?

For example i use the jar joda-time-2.8.2.jar

What should I put in my logback.xml file to disable the console output of the jar

logback.xml:

<?xml version="1.0" encoding="UTF-8"?>
<configuration>
    <appender name="stdout" class="ch.qos.logback.core.ConsoleAppender">
        <Target>System.out</Target>
        <encoder>
            <pattern>%d{yyyy-MM-dd HH:mm:ss} %-5p %c{1}:%L - %m%n</pattern>
        </encoder>
    </appender>
    <logger name="com.paper.white" additivity="false" level="TRACE">
        <appender-ref ref="stdout" />
    </logger>
    <root level="WARN">
        <appender-ref ref="stdout" />
    </root>
</configuration>
Mercer
  • 9,736
  • 30
  • 105
  • 170

1 Answers1

1

Just create a logger for org.joda.time and set the level to OFF.

<logger name="org.joda.time" level="OFF" >
    <appender-ref ref="stdout"/>
</logger>
nyname00
  • 2,496
  • 2
  • 22
  • 25
  • not work i have the log. When i decompile my jar i saw a `System.out.println(...);` it's possible to desactivate ? – Mercer Mar 16 '16 at 14:53
  • you can only 'redirect' **all** console output. see here http://stackoverflow.com/questions/9882487/disable-system-out-for-speed-in-java – nyname00 Mar 16 '16 at 15:08
  • where i define this ? i create a new class – Mercer Mar 16 '16 at 15:35
  • You should call `System.setOut(...)` as early as possible in your code. But beware, all your *logback* configuration will be moot, since you only have a *stdout* appender (which will be redirected as well).' So, if this is just a cosmetic thing and the additional log lines do not have a performance impact or clutter your logs, I wouldn't go down this road. – nyname00 Mar 16 '16 at 15:43