In my output I have JUL logging messages from Jersey like this
03.12.2010 14:14:55 com.sun.jersey.api.core.PackagesResourceConfig init
INFO: Scanning for root resource and provider classes in the packages:
Programmatically I wanted to swich them off so I tried
Logger.getLogger("com.sun.jersey.api.core.PackagesResourceConfig").setLevel( Level.SEVERE );
or
Logger.getLogger("com.sun.jersey").setLevel( Level.SEVERE );
but this don't work.
Funny enough this global configuration works:
Logger.getLogger( "com" ).setLevel( Level.SEVERE );
or
Logger.getLogger( "" ).setLevel( Level.SEVERE );
WHY?
I had some problems with this so I thought I'd put code in with imports to avoid confusion. I tested this and it works in my mini webserver configuration. Again, I included the whole server implementation for completeness.
import java.io.IOException;
import java.net.URI;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.ws.rs.core.UriBuilder;
import com.sun.jersey.api.container.httpserver.HttpServerFactory;
import com.sun.jersey.api.core.PackagesResourceConfig;
import com.sun.jersey.api.core.ResourceConfig;
import com.sun.net.httpserver.HttpServer;
public class WebServer {
private HttpServer webServer;
private final static Logger COM_SUN_JERSEY_LOGGER = Logger.getLogger( "com.sun.jersey" );
static {
COM_SUN_JERSEY_LOGGER.setLevel( Level.SEVERE );
}
public void start() throws IOException {
System.out.println("Starting WebServer\n");
webServer = createHttpServer();
webServer.start();
System.out.println(String.format("\nWeb Server started:" + "%sapplication.wadl\n", getURI()));
}
public void stop() {
webServer.stop(0);
}
public static HttpServer createHttpServer() throws IOException {
ResourceConfig rc = new PackagesResourceConfig("com.daford");
return HttpServerFactory.create(getURI(), rc);
}
private static URI getURI() {
return UriBuilder.fromUri("http://localhost/").port(4444).build();
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With