Search code examples
javalog4jjersey

How to use log4j to see into Jersey


I'm new to log4j and am trying to use it to better understand why my resource is providing a 415 Media Type Not Supported header.

I'm using the following:

log4j.rootCategory=WARN, stdout

log4j.appender.stdout=org.apache.log4j.ConsoleAppender
log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
log4j.appender.stdout.layout.ConversionPattern=%d{ABSOLUTE} %5p %t %c:%L - %m%n

log4j.category.com.sun.jersey=DEBUG,stdout

This seems like it should work but I'm showing nothing in the console about the POST reaching this application. I know it is reaching the application because if I turn the application off, the POSTer throws a "connection refused" when trying to POST.


Solution

  • I couldn't get logging to work, but I was able to determine how to get the ContentType which is what I needed. I had to add this to my class...

    @Context
    UriInfo uriInfo;
    
    @PostConstruct
    public void myfunc() {
        if (uriInfo == null) { //breakpoint on this line, so I can see what uriInfo is
    
        }
    }