如上图,输出乱码,原因是log4j.propertites 中缺少指定字符集
# Define the root logger with appender X log = D:/logs log4j.rootLogger = info, console,file # \u8F93\u51FA\u5230\u63A7\u5236\u53F0 log4j.appender.console=org.apache.log4j.ConsoleAppender log4j.appender.console.layout=org.apache.log4j.PatternLayout log4j.appender.console.layout.conversionPattern=[%-20d{yyyy-MM-dd HH:mm:ss}] [%-5p] [%l] - %m%n #\u8F93\u51FA\u5230\u6587\u4EF6 log4j.appender.file=org.apache.log4j.RollingFileAppender log4j.appender.file.File=${log}/sydsunew2/error2.log log4j.appender.file.ImmediateFlush=true log4j.appender.file.Threshold = info log4j.appender.file.layout=org.apache.log4j.PatternLayout log4j.appender.file.layout.conversionPattern=[%-20d{yyyy-MM-dd HH:mm:ss}] [%-5p] [%l] - %m%n
解决办法:在log4j.propertites 文件里加上:
log4j.appender.file.Encoding=UTF-8
即可解决!