「Java」SLF4J(Simple Logging Facade For Java)でログを出力する設定サンプル
1.log4j.propertiesの定義サンプル
log4j.rootLogger=debug, C
log4j.appender.A=org.apache.log4j.ConsoleAppender
log4j.appender.A.layout=org.apache.log4j.PatternLayout
log4j.appender.A.layout.ConversionPattern=%d{yyyy-MM-dd HH:mm:ss} [%c]-[%p] %m%n
log4j.appender.B=org.apache.log4j.FileAppender
log4j.appender.B.File=D:\\cft.log
log4j.appender.B.layout=org.apache.log4j.SimpleLayout
log4j.appender.C=org.apache.log4j.RollingFileAppender
log4j.appender.C.File=D:\\cftlog.html
log4j.appender.C.MaxFileSize=1000KB
log4j.appender.C.MaxBackupIndex=10
log4j.appender.C.layout=org.apache.log4j.HTMLLayout
log4j.appender.C.encoding=gbk
log4j.appender.D=org.apache.log4j.DailyRollingFileAppender
log4j.appender.D.File=D:\\cft.log
log4j.appender.D.layout=org.apache.log4j.TTCCLayout
2.Javaコード
package com.arkgame.study.slf4jdemo; import java.io.IOException; import org.slf4j.Logger; import org.slf4j.LoggerFactory; public class Slf4jDemo { private static final Logger LOGGER = LoggerFactory.getLogger(Slf4jDemo.class); public static void main(String[] args) throws IOException, InterruptedException { LOGGER.debug("start thread"); Thread.sleep(1 * 2000); methodAa(); } public static void methodAa() { LOGGER.debug("called methodAa method"); } }