Matthias van der Vlies
Matthias van der Vlies

Reputation: 3922

Play! framework and log4j, changing level for specifc package to FATAL

I'm in the process of writing an application that uses the WS object to make HTTP requests. However when making them (deliberately to a service that does not run) , I get a message from the inner Play! code:

15:06:29,613 ERROR ~ java.util.concurrent.ExecutionException: java.net.ConnectException: Connection refused to http://127.0.0.1:9091/

I traced this back to WSAsync.get() (https://github.com/playframework/play/blob/master/framework/src/play/libs/ws/WSAsync.java#L199):

    public HttpResponse get() {
        this.type = "GET";
        sign();
        try {
            return new HttpAsyncResponse(prepare(prepareGet()).execute().get());
        } catch (Exception e) {
            Logger.error(e.toString());
            throw new RuntimeException(e);
        }
    }

As this message is non-informational in my use case, I'd not like to show this error, so I decided to add a directive to my log4j.properties and restart the concerning application (Play! does not automatically reload it):

log4j.rootLogger=ERROR, Rolling
log4j.logger.play=INFO
log4j.logger.play.libs.ws=FATAL
log4j.appender.Rolling=org.apache.log4j.RollingFileAppender
log4j.appender.Rolling.File=logs/play-as.log
log4j.appender.Rolling.MaxFileSize=100KB
log4j.appender.Rolling.MaxBackupIndex=100
log4j.appender.Rolling.layout=org.apache.log4j.PatternLayout
log4j.appender.Rolling.layout.ConversionPattern=%d{ABSOLUTE} %-5p ~ %m%n

However I still receive the messages in my logs. I don't really understand because it should run in the same classpath. Any guesses on this?

Upvotes: 0

Views: 1490

Answers (2)

niels
niels

Reputation: 7309

Play always log under one category "play". They use always Logger..., so your approach can't work. There was some discussion about this issue, but the developer of play prefer only one category for simplicity.

Upvotes: 2

Aaron Digulla
Aaron Digulla

Reputation: 328624

Add

log4j.debug = TRUE

That enables debugging for log4j: You'll see which options are parsed. If you don't see anything, then the properties aren't loaded. Maybe there is a typo or the file is in the wrong place.

Note: You can specify the class name as well to avoid to suppress too much (i.e. log4j.logger.play.libs.ws.WSAsync=FATAL)

Also note: You should really use the XML version to configure; using properties is so error prone...

Upvotes: 0

Related Questions