1

I am using Geotools (version 19.2) to fetch some features. To deactivate the Geotools logging (< SEVERE) I tried 2 things:

  1. As I understood the logging documentation (documentation page):

Logging.getLogger("org.geotools").setLevel(Level.SEVERE);

  1. Loading a custom logging.properties configuration

The configuration (logging.properties) looks like this:

# standard log level
.level = WARNING

handlers = java.util.logging.ConsoleHandler

## limit the messages that are printed on the console to >= WARNING!
java.util.logging.ConsoleHandler.level = WARNING
java.util.logging.ConsoleHandler.formatter = java.util.logging.SimpleFormatter
java.util.logging.ConsoleHandler.encoding = Cp850

# do not use logging files!
java.util.logging.FileHandler.level = OFF

## just output geotools logs with level SEVERE!
org.geotools.level = SEVERE

Then I am loading the configuration using this code:

LogManager.getLogManager().readConfiguration(MyMainClass.class.getClassLoader().getResourceAsStream("logging.properties"));

Using both approaches I get NO logging output if I run my program in Eclipse. If I run my program as a JAR-file I get the following unwanted logging output:

Nov. 08, 2018 9:48:13 VORM. org.geotools.jdbc.JDBCDataStore getAggregateExpression INFO: Visitor class org.geotools.feature.visitor.CountVisitor has no aggregate attribute.

The INFO log resides from private Expression getAggregateExpression(FeatureVisitor visitor) in JDBCDataStore (see GitHub)

Any ideas why the logging configuration does not work for the generated JAR?

Lars
  • 2,315
  • 2
  • 24
  • 29
  • 1
    can you check which jvm is used when running in eclipse vs the command line - it is possible that the cli has a properties file in the jre/lib that over rides yours? – Ian Turton Nov 08 '18 at 18:34

1 Answers1

0

Using the JConsole (following answer on Suppress java util logging from 3rd party jar) I figured out that my logging configuration was overwritten by my Java installation's logging.properties file.

I tried to change the logging configuration in my main method which was wrong.

Initializing my custom logging.properties in a separate class and specifying the needed system property solves the problem!

  1. Custom initialization class

    public class CustomLoggingPropertiesLoader {

    // Initialize the global LogManager
    public CustomLoggingPropertiesLoader() {
        try {
            LogManager.getLogManager().readConfiguration(CustomLoggingPropertiesLoader.class.getClassLoader().getResourceAsStream("logging.properties"));
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
    

    }

  2. Use system property ("java.util.logging.config.class")

java -Djava.util.logging.config.class=de.example.logging.CustomLoggingPropertiesLoader -classpath [myclasspath]

Lars
  • 2,315
  • 2
  • 24
  • 29