调用log.info()时,log4j记录器未记录任何内容

时间:2019-01-28 03:39:23

标签: log4j2 vert.x

我在这里:

  

main / resources / log4j.properties

# Define the root logger with appender file
log4j.rootLogger = INFO

log4j.appender.stdout=org.apache.log4j.ConsoleAppender
log4j.appender.stdout.Target=System.out
log4j.appender.stdout.layout=org.apache.log4j.PatternLayout

我用它来称呼它

package huru.middleware;

import huru.MainVerticle;
import io.vertx.core.Handler;
import io.vertx.core.http.HttpHeaders;
import io.vertx.core.http.HttpServerRequest;
import io.vertx.ext.web.RoutingContext;
import io.vertx.ext.web.handler.impl.BodyHandlerImpl;
import org.apache.log4j.Logger;

public class JWTHandler implements Handler<RoutingContext> {

  private final Logger log = Logger.getLogger(MainVerticle.class);

  public void handle(RoutingContext ctx) {
    HttpServerRequest request = ctx.request();
    log.info("in the jwt middleware");
    System.out.println("DOOOOF");
    System.out.println(ctx.request().method());
    ctx.next();
  }
}

System.out.println调用将被记录,但是log.info()不记录任何内容。有人知道我的配置可能出什么问题吗?

1 个答案:

答案 0 :(得分:1)

一个快速解决方案是对log4j.properties进行一些更改:

log4j.rootLogger = INFO, stdout

log4j.appender.stdout=org.apache.log4j.ConsoleAppender 
log4j.appender.stdout.Target=System.out 
log4j.appender.stdout.layout=org.apache.log4j.PatternLayout