I am trying to get apache httpclient logs on the console for HTTPBuilder's RESTClient in groovy. I tried various approaches, including the standard instructions and some other suggestions such as this and this, but to no avail.
Finally after much frustration, I got some help from this SO question, and though it's not a clean solution, it gets the job done - I do get the wire logs now.
Here's some sample code:
// test.groovy
import groovyx.net.http.RESTClient
import java.util.logging.ConsoleHandler
import java.util.logging.Level
import java.util.logging.Logger
// Remove default loggers
def logger=Logger.getLogger('')
def handlers=logger.handlers
handlers.each() { handler->logger.removeHandler(handler) }
// Log ALL to Console
logger.setLevel Level.FINE
def consoleHandler=new ConsoleHandler()
consoleHandler.setLevel Level.FINE
logger.addHandler(consoleHandler)
def myclient = new RESTClient( 'https://www.google.com/search' )
def resp = myclient.get( queryString: 'q=httpclient' )
The only problem now is that I want to use logback instead of java.util.Logging for this, because the rest of my application is already using logback.
I am now trying to get the equivalent logback.groovy configuration for the above, but it doesn't work:
// logback.groovy
appender("CONSOLE", ConsoleAppender)
{
encoder(PatternLayoutEncoder)
{
pattern = "%d{HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n"
}
}
root DEBUG, ["CONSOLE"]
logger "groovyx.net.http.HttpURLClient", DEBUG, ["CONSOLE"]
logger "org.apache.http", DEBUG, ["CONSOLE"]
logger "org.apache.http.headers", DEBUG, ["CONSOLE"]
logger "org.apache.http.wire", DEBUG, ["CONSOLE"]
I am not getting any apache headers or apache wire logs. I am very new to logback (and log4j and slf4j and java.util.Logging), so your help would be greatly appreciated.