Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

java.util.logging: how to set level by logger package (or prefix)?

My app uses many libraries and I'm using java.util.logging for logging. I'd like to be able to set different logging levels for each library by doing something like:

org.datanucleus.*.level = WARNING
com.google.apphosting.*.level = WARNING
com.myapp.*.level = FINE

Is is possible?

like image 403
Igor Gatis Avatar asked Oct 13 '10 05:10

Igor Gatis


People also ask

What is Java Util logging level?

java.util.logging. Provides the classes and interfaces of the JavaTM 2 platform's core logging facilities. javax.sql.rowset.spi. The standard classes and interfaces that a third party vendor has to use in its implementation of a synchronization provider.

How do I set logging levels in application properties?

All the supported logging systems can have the logger levels set in the Spring Environment (for example, in application. properties ) by using logging. level. <logger-name>=<level> where level is one of TRACE, DEBUG, INFO, WARN, ERROR, FATAL, or OFF.

How do you insert a logger in Java?

The process of creating a new Logger in Java is quite simple. You have to use Logger. getLogger() method. The getLogger() method identifies the name of the Logger and takes string as a parameter.


1 Answers

You shouldn't use "*". A sample logging.properties could be such as:

handlers=java.util.logging.ConsoleHandler
.level=ALL

java.util.logging.ConsoleHandler.level = ALL
java.util.logging.ConsoleHandler.formatter=java.util.logging.SimpleFormatter

org.datanucleus.level=WARNING
org.datanucleus.handler=java.util.logging.ConsoleHandler

com.myapp.level=FINE
com.myapp.handler=java.util.logging.ConsoleHandler

And if all "org" level should be logged as WARNING then

org.level=WARNING
org.handler=java.util.logging.ConsoleHandler
like image 175
VolkanT Avatar answered Sep 19 '22 22:09

VolkanT