Home > OS >  Prevent imported libraries from using my logging-configuration file
Prevent imported libraries from using my logging-configuration file

Time:06-26

Hostile takeover of my logger !!


TL:DR imported library is using my logger's logging.properties file.

In order to keep track of everything that happens in my project, I implemented a custom logger class using java.utils.logging, with a nice simple configuration file "logging.properties":

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


java.util.logging.FileHandler.pattern = server/java/data/logs/myOwnLog%u.log
java.util.logging.FileHandler.limit = 20000
java.util.logging.FileHandler.count = 10
java.util.logging.FileHandler.formatter = server/java/src/main/java/controller/utils/logs/LineFormat.java

java.util.logging.ConsoleHandler.level = ALL



com.journaldev.files = SEVERE

Now after adding it, for some reason, one of my imported libraries - GraphStream start to use my configuration file.
Which means I get thier logs printed to my console and saved in log files in the location and with the name I defined in the configuration file.

I thought maybe there was a conflict of names with there configuration file but it wasn't it.

Any ideas?



first 3 lines are my logs and the rest are belongs to GraphStream. first 3 lines are my logs and the rest are belongs to GraphStream

CodePudding user response:

This is how logging in Java works: anything can attempt to write logs, and if you have configured the logging framework that it's trying to use, you'll get its messages.

The way to stop seeing messages third-party libraries is to disable them in your logging configuration (or, alternatively, disable everything except your own classes) by changing the level at which they report.

I don't use java.util.logging, but by reading the docs it appears that you could include a configuration line like this to turn off a third-party package:

com.thirdparty.level = OFF

Or alternatively, default everything to OFF and set your packages to DEBUG:

.level = OFF
com.mycompany.level=DEBUG
  • Related