How to set up logging.properties for HTTPBuilder in Java

故事扮演 提交于 2020-02-08 09:42:22

问题


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:

  1. Go to the MBeans tab.
  2. Expand nodes java.util.logging->Logging->Attributes->Operations.
  3. Select getLoggerLevel and clear the value of p0 field. This is the root logger.
  4. Click the getLoggerLevel button and see if the level matches what you put in the logging.properties file.
  5. Go to java.util.logging->Logging->Attributes->LoggerNames
  6. Double click the java.lang.String[] cell in the value column. If your child logger names from your logging.properties are not present then those values in your logging.properties are 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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!