0
votes

My log.properties contains configuration

java.util.logging.FileHandler.formatter = java.util.logging.SimpleFormatter
java.util.logging.FileHandler.level = INFO
java.util.logging.FileHandler.pattern = logs/startup.%g.log
java.util.logging.FileHandler.limit = 10000000
java.util.logging.FileHandler.count = 3

GtfsOperatorManager.level=INFO
TripUpdate.level=FINER
VehiclePosition.level=INFO
Alert.level=INFO

where the root logger logs to a file called startup and other loggers such as TripUpdate are set up programmatically to log to their own files.

The problem is that as shown log entries only go into TripUpdate at level INFO . However if I comment out the line

#java.util.logging.FileHandler.level = INFO

then TripUpdate logs at FINER as configured but log entries then go into the startup log at FINER too rather than INFO.

What am I doing wrong, how do I get startup logging at INFO and TripUpdate logging at FINER ?

1

1 Answers

0
votes

Try setting the root logger level in your config file by adding the following:

.level=INFO

All child loggers will inherit this level.

However if I comment out the line [snip] then TripUpdate logs at FINER as configured but log entries then go into the startup log at FINER too rather than INFO.

This is because the default java.util.logging.FileHandler.level is ALL.

Since your are doing programmatic configurations too you need to make sure you are keeping your logger from being garbage collected.

No logging is not done directly to startup above, rather it inherits log entries but I want to filter out everything above INFO

You have limited options there. You can use setUseParentHandlers on the loggers that you don't want to see output from. This can be done from the properties file by setting <loggername>.useParentHandlers=false. You can then attach an additional file handler to the logger that is no longer publishing records to the parent handlers.

Otherwise, you have to just write a log filter to check the logger name and level and install it on the file handler.