I have a Logger that is listening to a package's log prints and i want that it will ignore one class from the same package. Is it possible?
-
is it a log4j logger? – Sabir Khan Dec 24 '15 at 14:27
-
http://stackoverflow.com/questions/960099/how-to-set-up-java-logging-using-a-properties-file-java-util-logging – Betlista Dec 24 '15 at 14:32
2 Answers
You have to create a logging configuration file (i.e logging.properties). It is a properties file that has to contain the following lines:
com.package.level = WARN
com.package.Class.level = ERROR
Of course, you have to replace "package" and "Class" by the ones corresponding to your requirement.
Then, you will have to launch your application as follows:
java -Djava.util.logging.config.file=C:\logging.properties ...
For a complete logging configuration file, check this example.

- 2,099
- 11
- 16
-
-
-
OK. it's the standard logger. Do you have a logging configuration file? – Guy Bouallet Dec 24 '15 at 14:37
-
-
Can't i just call readConfiguration of LogManger instead of launching the application as you mentioned? – itzikos Dec 24 '15 at 15:08
If I remember correctly, you can exclude a subpackage as follows. For example, say you want to block com.foo.bar
1) Define logging properties using the mechanisms of your choice. 2) Define a handler at the level of com.foo.bar, and route to something you don't care about (e.g., ConsoleHandler) 3) Set useParentHandlers to false
Because of this, any logging call in com.foo.bar and below will go to the set handler, and will not propagate up to higher levels, so the root logger will not be invoked.

- 88,451
- 51
- 221
- 321