java - How to configure the output encoding in log

2019-08-26 06:23发布

问题:

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

回答1:

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

java -Dfile.encoding=utf-8


回答2:

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);