2

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

Thanks

UPDATE: the library in question uses the built-in logger class in java (java.util.logging.Logger).

Lyther
  • 67
  • 2
  • 6

4 Answers4

1

set the log level for that package to FATAL. This will not actually turn off all the log messages from the jar, but should minimize. Also note that if you have multiple package structures in there, you have to add individual lines

log4j.logger.com.foo=FATAL
Teja Kantamneni
  • 17,402
  • 12
  • 56
  • 86
  • 1
    the library in question uses the built-in logger, and not the java log4j library ... anyway thanks for the idea – Lyther Feb 16 '11 at 21:53
1

See the answer from how can i disable the default console handler, while using the java logging api ?

Alternatively, set the logging level to OFF as presented in the Javadocs for log level. Quote:

In addition there is a level OFF that can be used to turn off logging, and a level ALL that can be used to enable logging of all messages.

Community
  • 1
  • 1
Johan Sjöberg
  • 47,929
  • 21
  • 130
  • 148
0

If you are using log4j, the easiest way is to increase the logging level of that particular library to say, warn or error.

For example, if you don't want all the Apache APIs, Spring APIs and Hibernate APIs to clutter your log files, you can do something like this:-

<logger name="org.apache">
    <level value="warn" />
</logger>

<logger name="org.springframework">
    <level value="warn" />
</logger>

<logger name="org.hibernate">
    <level value="warn" />
</logger>

This way, all the debug and info from these libraries will not be shown at all.

limc
  • 39,366
  • 20
  • 100
  • 145
  • 1
    the library in question uses the built-in logger, and not the java log4j library ... anyway thanks for the idea – Lyther Feb 16 '11 at 21:54
0

Other than increasing the logging level you could tell the library to use a NOP logger - see here. The NOP logger will just default to doing absolutely nothing which would be exactly what you want.

Ok after your edit: If you can tell the library which logger it should use (and if you can't access the logging object I don't think any method will work anyway), just make your own NopLogger, i.e. extend Logger and overwrite all Methods with an empty method,

Voo
  • 29,040
  • 11
  • 82
  • 156