开发者

Logger in a .jar java library

How to disable logger (pri开发者_开发问答nt 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).


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.


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


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.


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,

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜