问题
I'm trying to get the logs of my connection with HTTP Builder. I read a lot and heard to set up a configuration file. I'm executing my jar from the terminal with this command
java -jar -Djava.util.logging.config.file=logging.properties Console-0.1.jar
And my logging.properties looks like this
handlers=java.util.logging.ConsoleHandler
java.util.logging.ConsoleHandler.level=ALL
.level=FINEST
httpclient.wire.header.level=FINEST
org.apache.commons.httpclient.level=FINEST
I don't get why it's not working. Has anyone an idea ?
回答1:
You are using a relative path to load the logging.properties. Change that to an absolute path and try it again.
Next, attach JConsole to your running process:
- Go to the MBeans tab.
- Expand nodes
java.util.logging->Logging->Attributes->Operations. - Select
getLoggerLeveland clear the value ofp0field. This is the root logger. - Click the
getLoggerLevelbutton and see if the level matches what you put in thelogging.propertiesfile. - Go to
java.util.logging->Logging->Attributes->LoggerNames - Double click the
java.lang.String[]cell in the value column. If your child logger names from yourlogging.propertiesare not present then those values in yourlogging.propertiesare not doing anything. Correct the child logger names in your `logging.properties.
If none of that works then print your log tree.
回答2:
I found a good and pretty easy solution. Just get the root Logger and set the level before the http builder gets called
ch.qos.logback.classic.Logger rootLogger = (ch.qos.logback.classic.Logger)LoggerFactory.getLogger(ch.qos.logback.classic.Logger.ROOT_LOGGER_NAME)
rootLogger.setLevel(level)
来源:https://stackoverflow.com/questions/45102453/how-to-set-up-logging-properties-for-httpbuilder-in-java