java - How to configure the output encoding in log4j 2.x programmatically?

∥☆過路亽.° 提交于 2019-12-24 09:57:35

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!