用log4j输入日志,在linux系统下输出的日志里的中文字符都变成了??等乱码,这是因为在没有显式指明编码的情况下,它会按操作系统的编码进行输出。因此,只要加上一句,
log4j.appender.logfile.encoding=UTF-8就可以了!log4j的完整配置如下:
java 代码
- log4j.configuration=log4j.properties
- log4j.rootCategory=ERROR,logfile
-
- #log4j.appender.CONSOLE=org.apache.log4j.ConsoleAppender
-
- #log4j.appender.CONSOLE.layout=org.apache.log4j.PatternLayout
-
- #log4j.appender.CONSOLE.layout.ConversionPattern=%d [%t] %-5p %c - %m%n
-
- #log4j.appender.FILE=org.apache.log4j.DailyRollingFileAppender
-
- #log4j.appender.FILE.file= E:\dzsport\debug_logs\log4j.log
-
- #log4j.appender.FILE.layout=org.apache.log4j.PatternLayout
-
- #log4j.appender.FILE.layout.ConversionPattern=%d [%t:%l] %-5p %c - %m%n
-
- log4j.appender.logfile=org.apache.log4j.RollingFileAppender
-
- #log4j.appender.logfile.File=E:/dzsport/debug_logs/log4j.log
-
- log4j.appender.logfile.encoding=UTF-8
-
- log4j.appender.logfile.File=/www/tomcat6/logs/SongJiang_Community_Debug.log
-
- log4j.appender.logfile.MaxFileSize=2048KB
-
- log4j.appender.logfile.MaxBackupIndex=10
-
- log4j.appender.logfile.layout=org.apache.log4j.PatternLayout
-
- log4j.appender.logfile.layout.ConversionPattern=%d %p [%c] - <%m>%n
-
- # Print only messages of level WARN or above in the package com.foo.
-
- # log4j.logger.com.foo=WARN
-
- #log4j.logger.au.gov.sa.health.oacis=DEBUG
-
- #log4j.logger.com.opensymphony.webwork=DEBUG
-
- #log4j.logger.org.apache=INFO
-
- log4j.logger.org.hibernate=INFO
-
- log4j.logger.org.springframework=ERROR
-
- #log4j.logger.ca.uhn=INFO