java - How to configure the output encoding in log

2019-08-26 05:50发布

There are other questions about configuring programmatically log4j2, but I coun't find a way to configure the log output encoding?

2条回答
Evening l夕情丶
2楼-- · 2019-08-26 06:11

In log4j one would do the following, so I assume too for log4j2:

  Logger hlogger = Logger.getLogger("org.hibernate.stat");
  SimpleLayout layout = new SimpleLayout();
  ConsoleAppender consoleAppender = new ConsoleAppender(layout);
  consoleAppender.setEncoding("UTF-8");
  hlogger.addAppender(consoleAppender);
  hlogger.setLevel(Level.DEBUG);
查看更多
爷、活的狠高调
3楼-- · 2019-08-26 06:13

I didn't solve it programatically. My solution was to execute the java interpreter with this option:

java -Dfile.encoding=utf-8
查看更多
登录 后发表回答