Log4jã®ã¨ã©ã¼ãã³ããªã³ã°
log4jã£ã¦ãã¡ã¤ã«IOç³»ã®ã¨ã©ã¼ãçºçããã¨ãã¯å
é¨ã§ã¨ã©ã¼ãã³ããªã³ã°ãã¦ã¾ãããã
æ¸ãè¾¼ã¿ã失æããå ´åã¨ãã¯ãã®ãã¨ãå¼ã³åºãå´ã«ç¥ããã¦ãããªãã
ã¨ãããã¨ãæè¿ç¥ãã¾ããããã
ããã¯log4jã®ææ³ã¨ãããèãæ¹ããããlog4jã使ã£ã¦ããå´ã«ãããã£ã
ãã¡ã¤ã«I/Oç³»ã®å¿é
ããããªãã¨ããèæ
®ãããã
ã§ããå®éã«ã¯æ¨©éã¨ã容éã®é¢ä¿ã§ãã°ãæ¸ããªãå ´åãçºçããããã
ããããå ´åã¯ã©ããã£ã¦ãã°ã®æ¸ãè¾¼ã¿ãä¿è¨¼ããã°ããã®ãã¨ããåé¡ãåºã¦ããã
ä¸ã¤ã®æ¡ã®ã¨ãã¦ã¯ãå¥éã¹ã¯ãªãããä½ããæ¸ãã¦ãéæ対象ã®ãã°ãã¡ã¤ã«
ã«æ¸ãè¾¼ã¿ãããã¦ãããã確èªããæ¹æ³ããããã©ã
å®ã¯ç¡çããlog4jã«ãã¡ã¤ã«I/Oã失æããå ´åã«ä¾å¤ãçºçããããã«ãã
æ¹æ³ãããã¿ããã
æ¹æ³ã¨ãã¦ã¯ã以ä¸ã®ã¨ã©ã¼ãã³ãã©ã¯ã©ã¹ã¨ããç¨ã®ä¾å¤ãä½æãã¦
log4jã®è¨å®ãã¡ã¤ã«ã«ãã®è¨å®ãæ¸ãã°ããã ãã
ã¡ãªã¿ã«ç¬èªä¾å¤ãããããä½ã£ã¦ããã®ã¯ãimplemntãã¦ããErrorHandlerã
ãã§ãã¯ä¾å¤ãthrowãã¦ããªããããç¡çããRuntimeExceptionãç¶æ¿ãã¦ä¾å¤ã
çºçãããããã
ãã ãå人çã«ã¯ã絶対ã¢ããªå´ã§ãã¡ã¤ã«ã失æãããã¨ãç¥ãããï¼ãã¨ãã以å¤ã¯
ãã£ã±ãæ¬æ¥ã®log4jã®ããã©ã«ãã®ä»æ§ã§å®è£
ãããã¹ãããªã¨æãã
public class Log4jException extends RuntimeException { private static final long serialVersionUID = 1L; private int errorCodeField = -1; private LoggingEvent eventField = null; public Log4jException(String message) { super(message); } public Log4jException(Throwable e) { super(e); } public Log4jException(String message, Throwable e) { super(message, e); } public Log4jException(String message, Throwable e, int errorCode, LoggingEvent event) { super(message, e); errorCodeField = errorCode; eventField = event; } public int getErrorCode() { return errorCodeField; } public LoggingEvent getLoggingEvent() { return eventField; } }
public class Log4jExceptionErrorHandler implements ErrorHandler { @Override public void error(String message) { error(message, null, 0); } @Override public void error(String message, Exception e, int errorCode) { error(message, e, errorCode, null); } @Override public void error(String message, Exception e, int errorCode, LoggingEvent event) { LogLog.error(message, e); throw new Log4jException(message, e, errorCode, event); } @Override public void activateOptions() {} @Override public void setAppender(Appender appender) {} @Override public void setBackupAppender(Appender appender) {} @Override public void setLogger(Logger logger) {} }
<appender name="SAMPLE" class="org.apache.log4j.DailyRollingFileAppender"> <errorHandler class="Log4jExceptionErrorHandler"/> </appender>
åèï¼http://mericleclerin.blogspot.jp/2011/03/log4j.html