This one usually gets me every time I touch this library, so I’m posting my notes for future reference.
Logging can be enabled by creating a custom HttpRequestInitializer and HttpResponseInterceptor, but that will consume the InputStream and you’ll likely see getContent() return null, or IOException “Stream closed” errors.
However, the client library uses Java’s standard java.util.logging platform, which can be enabled to write to the console / stderr with these steps.
- Create a file, called say ‘logging.properties’ and store it somewhere accessible to your project (I just dump it in the project root for debugging).
- Paste these lines into the file:
handlers=java.util.logging.ConsoleHandler java.util.logging.ConsoleHandler.level=CONFIG java.util.logging.ConsoleHandler.formatter=java.util.logging.SimpleFormatter
- Run your app with this extra VM argument, by either adding it to your command line when you run java -cp … -Djava.util.logging… MyClass, or to the “VM options” field in your IDE.
Et voila, logs!