「Log4j設定」の版間の差分
ナビゲーションに移動
検索に移動
(ページの作成:「==log4j 設定== ====log4j.properties 設定例==== ### Stdout ### log4j.appender.stdout=org.apache.log4j.ConsoleAppender log4j.appender.stdout.Target=System.out…」) |
|||
8行目: | 8行目: | ||
log4j.appender.stdout.layout.ConversionPattern=%d{yyyy-MMM-dd HH:mm:ss} %5p - %m%n | log4j.appender.stdout.layout.ConversionPattern=%d{yyyy-MMM-dd HH:mm:ss} %5p - %m%n | ||
− | ### | + | ### Daily[[R]]olling Log ### |
− | log4j.appender.dailyfile=org.apache.log4j. | + | log4j.appender.dailyfile=org.apache.log4j.Daily[[R]]ollingFileAppender |
log4j.appender.dailyfile.File=c:/Program Files/eclipse3.1/workspace/fugitive/log/fugitive.log | log4j.appender.dailyfile.File=c:/Program Files/eclipse3.1/workspace/fugitive/log/fugitive.log | ||
log4j.appender.dailyfile.DatePattern='.'yyyy-MM-dd | log4j.appender.dailyfile.DatePattern='.'yyyy-MM-dd | ||
15行目: | 15行目: | ||
log4j.appender.dailyfile.layout.ConversionPattern=%d{yyyy-MMM-dd HH:mm:ss} %5p - %m%n | log4j.appender.dailyfile.layout.ConversionPattern=%d{yyyy-MMM-dd HH:mm:ss} %5p - %m%n | ||
− | ### | + | ### [[R]]olling Log ### |
− | log4j.appender.rollfile=org.apache.log4j. | + | log4j.appender.rollfile=org.apache.log4j.[[R]]ollingFileAppender |
log4j.appender.rollfile.File=c:/Program Files/eclipse3.1/workspace/fugitive/log/fugitive.log | log4j.appender.rollfile.File=c:/Program Files/eclipse3.1/workspace/fugitive/log/fugitive.log | ||
log4j.appender.rollfile.MaxFileSize=5MB | log4j.appender.rollfile.MaxFileSize=5MB | ||
45行目: | 45行目: | ||
String url = "/" + LogUtil.class.getPackage().getName().replaceAll("\\.", "/") | String url = "/" + LogUtil.class.getPackage().getName().replaceAll("\\.", "/") | ||
+ "/log4j.properties"; | + "/log4j.properties"; | ||
− | prop.load(LogUtil.class. | + | prop.load(LogUtil.class.get[[R]]esourceAsStream(url)); |
PropertyConfigurator.configure(prop); | PropertyConfigurator.configure(prop); | ||
} catch (Exception re) { | } catch (Exception re) { |
2020年2月16日 (日) 04:29時点における最新版
目次
log4j 設定
log4j.properties 設定例
### Stdout ### log4j.appender.stdout=org.apache.log4j.ConsoleAppender log4j.appender.stdout.Target=System.out log4j.appender.stdout.layout=org.apache.log4j.PatternLayout log4j.appender.stdout.layout.ConversionPattern=%d{yyyy-MMM-dd HH:mm:ss} %5p - %m%n ### DailyRolling Log ### log4j.appender.dailyfile=org.apache.log4j.DailyRollingFileAppender log4j.appender.dailyfile.File=c:/Program Files/eclipse3.1/workspace/fugitive/log/fugitive.log log4j.appender.dailyfile.DatePattern='.'yyyy-MM-dd log4j.appender.dailyfile.layout=org.apache.log4j.PatternLayout log4j.appender.dailyfile.layout.ConversionPattern=%d{yyyy-MMM-dd HH:mm:ss} %5p - %m%n ### Rolling Log ### log4j.appender.rollfile=org.apache.log4j.RollingFileAppender log4j.appender.rollfile.File=c:/Program Files/eclipse3.1/workspace/fugitive/log/fugitive.log log4j.appender.rollfile.MaxFileSize=5MB log4j.appender.rollfile.MaxBackupIndex=5 log4j.appender.rollfile.layout=org.apache.log4j.PatternLayout log4j.appender.rollfile.layout.ConversionPattern=%d{yyyy-MMM-dd HH:mm:ss} %5p - %m%n ### Logger Setting (for debugging) ### #log4j.rootLogger=debug,stdout,rollfile #log4j.logger.info.typea.testApp=debug,stdout,rollfile ### Logger Setting ### log4j.logger.info.typea.testApp=info,rollfile
設定ファイルを指定する
http://www.nurs.or.jp/~sug/soft/log4j/log4j3.htm
プログラム上で、明示的にプロパティファイルを指定するためのクラス。
import java.util.Properties; import org.apache.log4j.Logger; import org.apache.log4j.PropertyConfigurator; public class LogUtil { static { try { Properties prop = new Properties(); String url = "/" + LogUtil.class.getPackage().getName().replaceAll("\\.", "/") + "/log4j.properties"; prop.load(LogUtil.class.getResourceAsStream(url)); PropertyConfigurator.configure(prop); } catch (Exception re) { re.printStackTrace(); } } private LogUtil() {} /** * Log4Jロガーを取得する * @param clazz * @return */ public static Logger getLogger(Class clazz) { return Logger.getLogger(clazz); } }
使用法
import org.apache.log4j.Logger; protected Logger log = LogUtil.getLogger(Dao.class);
© 2006 矢木浩人