问题
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);
来源:https://stackoverflow.com/questions/48446009/java-how-to-configure-the-output-encoding-in-log4j-2-x-programmatically