我已经交了一个使用log4j作为记录器应用程序的代码。如何为它生成UTF8日志文件? log4j创建的日志文件目前是ASCII格式。
我试过以下
按照说明
设置日志文件的文件编码vi current
:set bomb
:set fileencoding=utf-8
:wq
事实上,在执行上述操作后,日志文件本身就会停止工作,即由于某些奇怪的原因没有进一步的日志写入文件
我也尝试过更改.properties文件
log4j.rootLogger=TRACE, logfile
log4j.appender.logfile=org.apache.log4j.RollingFileAppender
log4j.appender.logfile.encoding=UTF-8
log4j.appender.logfile.File=/usr/vm/log/webconsole/current
log4j.appender.logfile.Append=true
log4j.appender.logfile.MaxFileSize=5MB
log4j.appender.logfile.MaxBackupIndex=1
log4j.appender.logfile.layout=org.apache.log4j.PatternLayout
log4j.appender.logfile.layout.ConversionPattern=[%5p] %d{ISO8601} (%F:%M:%L)%n%m%n%n
log4j.logger.com.company.npm=ALL
log4j.logger.org.apache.axis=OFF
翻转后的日志文件由于某种原因是ASCII格式
我正在使用log4j 1.2.8
当我启用log4j调试时,我得到了以下输出
@4000000053b16b142afa961c log4j: Parsing for [root] with value=[TRACE, logfile, cdr].
@4000000053b16b142afc630c log4j: Level token is [TRACE].
@4000000053b16b142afe85ec log4j: Category root set to DEBUG
@4000000053b16b142aff510c log4j: Parsing appender named "logfile".
@4000000053b16b142e3ebccc log4j: Parsing layout options for "logfile".
@4000000053b16b143333a0bc log4j: Setting property [conversionPattern] to [[%5p] %d{ISO8601} (%F:%M:%L)%n%m%n%n].
@4000000053b16b1433442f04 log4j: End of parsing for "logfile".
@4000000053b16b14343015a4 log4j: Setting property [file] to [/usr/vm/log/webconsole/current].
@4000000053b16b1434331b14 log4j: Setting property [append] to [true].
@4000000053b16b1434350b2c log4j: Setting property [maxFileSize] to [100KB].
@4000000053b16b14343885cc log4j: Setting property [maxBackupIndex] to [1].
@4000000053b16b14343a79cc log4j: Setting property [encoding] to [UTF-8].
@4000000053b16b14343d311c log4j: setFile called: /usr/vm/log/webconsole/current, true
@4000000053b16b1434937edc log4j: setFile ended
@4000000053b16b143496a774 log4j: Parsed "logfile" options.
@4000000053b16b1434a97fac log4j: Parsing appender named "cdr".
@4000000053b16b150111c014 log4j: Parsed "cdr" options.
@4000000053b16b1501166394 log4j: Parsing for [com.company.npm] with value=[ALL].
@4000000053b16b150118d87c log4j: Level token is [ALL].
@4000000053b16b15011abcdc log4j: Category com.company.npm set to ALL
@4000000053b16b150122003c log4j: Handling log4j.additivity.com.company.npm=[null]
@4000000053b16b150123d4fc log4j: Finished configuring.
@4000000053b16b17086f0114 log4j: rolling over count=102406
@4000000053b16b1708703d7c log4j: maxBackupIndex=1
@4000000053b16b170910fdd4 log4j: Renaming file /usr/vm/log/webconsole/current to /usr/vm/log/webconsole/current.1
@4000000053b16b1709140b14 log4j: setFile called: /usr/vm/log/webconsole/current, false
@4000000053b16b170916494c log4j: setFile ended
答案 0 :(得分:0)
在 log4j 2 中,encoding
属性似乎已被删除。
相反,Layout 中的 charset
属性可用于编码。
答案 1 :(得分:-2)
应该是:
log4j.appender.FILE.encoding=UTF-8