How to use log4j to view in jersey

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

I am 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 one seems as if it should work, but I am not showing anything in the console about the POST reaching this application. I know that it reaches the application, because if I turn off the application, POSTer gives a "connection failure" when trying to POST.

+5
source share
4 answers

I couldn't get logging to work, but I was able to determine how to get the ContentType that I need. I should have added 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

    }
}
-4
source

, , Log4J. Log4J ; Java-.

Log4J, Java SLF4JBridgeHandler .

JVM , :

  • -Djava.util.logging.config.file=/path/to/logging.properties

  • SLF4JBridgeHandler logging.properties

    handlers=org.slf4j.bridge.SLF4JBridgeHandler

SLF4J Log4J, log4j.properties, , .

, - - :

  • ( , );

  • Java-. Java , logging.properties , -

    com.sun.jersey.level=DEBUG
    com.sun.jersey.handlers=java.util.logging.FileHandler
    java.util.logging.FileHandler.pattern=/path/to/debugging.log
    java.util.logging.FileHandler.formatter=java.util.logging.SimpleFormatter
+8

JUL to SLF4J Bridge , , . , maven:

<dependency>
    <groupId>org.slf4j</groupId>
    <artifactId>jul-to-slf4j</artifactId>
    <version>1.7.5</version>
</dependency>

:

LogManager.getLogManager().reset();
SLF4JBridgeHandler.install();

log4j.properties:

log4j.category.org.glassfish.jersey=WARN,stdout
+2

  • web.xml
  • log4j.properties
  • Log4JInitServlet.java
  • Log4JTestServlet.java
0
source

All Articles