Log 4 jログファイル出力符号化設定
2256 ワード
Log 4 jログファイル出力符号化設定
----------------------------
1
log4j.properties
2
PatternLayout.java
3.
ログ出力:
debug.log
----------------------------
1
log4j.properties
log4j.rootCategory=INFO, CONSOLE, LOGFILE
#
log4j.logger.org.hibernate=INFO
# CONSOLE settings.
log4j.appender.CONSOLE=org.apache.log4j.ConsoleAppender
log4j.appender.CONSOLE.Threshold=ERROR
log4j.appender.CONSOLE.layout=org.apache.log4j.PatternLayout
log4j.appender.CONSOLE.layout.ConversionPattern=%d{MM-dd HH:mm:ss.SSS} [%-5p] %c - %m%n
# LOG FILE settings.
log4j.appender.LOGFILE=org.apache.log4j.DailyRollingFileAppender
log4j.appender.LOGFILE.Append=true
log4j.appender.LOGFILE.File=log/debug.log
log4j.appender.LOGFILE.File.DatePattern='.'yyyy-MM-dd
#log4j.appender.LOGFILE.layout=org.apache.log4j.PatternLayout
# ㄧ ■
log4j.appender.LOGFILE.layout=cn.bisoft.component.log.log4j.PatternLayout
log4j.appender.LOGFILE.layout.ConversionPattern=[%d{mm:ss.SSS}] ㄧ %p ㄧ %-20C{1}.%-20M(L: %-4L) ■ %-50m ㄧ (%r ms)%n
#
log4j.appender.LOGFILE.encoding=UTF-8
2
PatternLayout.java
package cn.bisoft.component.log.log4j;
import java.io.UnsupportedEncodingException;
import org.apache.log4j.helpers.PatternParser;
public class PatternLayout extends org.apache.log4j.PatternLayout
{
@Override
protected PatternParser createPatternParser(String pattern)
{
try
{
pattern = new String(pattern.getBytes("iso-8859-1"));
}
catch (UnsupportedEncodingException e)
{
e.printStackTrace();
}
return super.createPatternParser((pattern));
}
}
3.
ログ出力:
debug.log
[33:22.437] ㄧ INFO ㄧ NativeApiIllustrationTest.setUp (L: 39 ) ■ ■ ㄧ (1297 ms)
[33:22.734] ㄧ INFO ㄧ SessionFactoryImpl .close (L: 927 ) ■ closing ㄧ (1594 ms)