I want to see trace logs of HTTPURLConnection class to debug an issue I have while calling a remote service.
I tried to configure tracing in server.xml, like below.
<logging logDirectory="logs" copySystemStreams="true" consoleLogLevel="INFO" traceFileName="trace.log" traceSpecification="sun.net.www.protocol.http.HttpURLConnection=finest" maxFileSize="50" maxFiles="50"/>
When the server starts, it does show my configuration in trace.specification.
********************************************************************************
product = WebSphere Application Server 20.0.0.9 (wlp-1.0.44.cl200920200820-0913)
wlp.install.dir = /Users/ilam/liberty20.9/wlp/
java.home = /Library/Java/JavaVirtualMachines/jdk1.8.0_261.jdk/Contents/Home/jre
java.version = 1.8.0_261
java.runtime = Java(TM) SE Runtime Environment (1.8.0_261-b12)
os = Mac OS X (10.15.7; x86_64) (en_GB)
process = 54509@MYMACHINE
trace.specification = *=info:sun.net.www.protocol.http.HttpURLConnection=finest
********************************************************************************
But I see
The configured trace state included the following specifications that do not match any loggers currently registered in the server: sun.net.www.protocol.http.HttpURLConnection=all Ignore this message if the trace specifications sun.net.www.protocol.http.HttpURLConnection=all are valid.
And there are no logs from the HttpURLConnection class, in trace.log file. So how do I configure this
Per https://openliberty.io/docs/20.0.0.11/log-trace-configuration.html , Liberty does aggregate the content you write to java.util.logging into its log files (messages.log and trace.log).
If something that you think has JUL trace instrumentation isn't showing up in the Liberty trace despite setting the appropriate traceSpecification
, you might want to double check to make sure the JUL Logger is actually getting registered. The log message you cut/pasted shows that, at least at the time the trace specification was processed, the specified logger had not been registered with the LogManager.
One way you can check to see which Loggers are registered is to use the LoggingMXBean (https://docs.oracle.com/javase/8/docs/api/java/util/logging/LoggingMXBean.html) to get the logger names to see if the logger they are trying to enable actually exists when the server is running.
You can access the LoggingMXBean from jconsole from your jre/bin directory.
If the Logger you are looking for is not in the list, it may be because the class uses a different Logger name (the use of the package and class name as the Logger name is just a convention), or it may be that the class that uses the Logger hasn't yet reached the point in the code that registers its Logger (although it's quite common for JUL loggers to be registered when the class is initialized).