sitelink1  
sitelink2  
sitelink3  
extra_vars4  
extra_vars5  
extra_vars6  
생성한 클래스는 ContextFileAppender 와 ContextRollingFileAppender 이다.
jar로 추가하기에는 너무나 초라한... ^^;
사용법은 log4j.properties 참조할 것

클라이언트 IP를 Appender에 넘겨주기 위해서 Servlet 시작시에 다음과 같은 코드를 삽입해야 한다.

 

try {   

    Class.forName("org.apache.log4j.MDC");   

    MDC.put("IP", request.getRemoteHost());   

catch (ClassNotFoundException ex) {   

    if (log.isWarnEnabled()) {   

        log.warn("클래스를 찾을 수 없습니다.", ex);   

    }   

}



OR


try {

//-- 요청된 원격 IP를 취한다

String ip = null;

Enumeration headers = request.getHeaders("X-FORWARDED-FOR");

if (headers != null) {

while (headers.hasMoreElements()) {

String[] ips = headers.nextElement().toString().split(",");

int count = ips.length;


for (int i = 0; i < count; i++) {

String proxy = ips[i].trim();


if (!"unknown".equals(proxy)

&& !(proxy == null || "".equals(proxy.trim()))) {

ip = proxy;

}

}

}

}

if (ip == null) {

ip = request.getRemoteAddr();

}

//-- MDC 영역에 IP 를 저장한다

Class[] parameterTypes = { String.class, Object.class };

Object[] args = { "IP", ip };

Class.forName("org.apache.log4j.MDC").getMethod("put", parameterTypes).invoke(null, args);


if (log.isDebugEnabled()) {

log.debug("registerLogContext(): ip=" + ip);

}

} catch (Throwable th) {

if (log.isDebugEnabled()) {

log.debug("Could not initialize Log4j");

}

}



MDC 영역에 클라이언트 IP를 삽입하는 구문이다.
번호 제목 글쓴이 날짜 조회 수
58 셀 크기 조정 (자동 크기 조정) 황제낙엽 2011.05.03 7816
57 Cell 의 wrap 설정 (텍스트 개행) file 황제낙엽 2011.05.09 3121
56 병합된 셀의 스타일( border) 설정하기 황제낙엽 2011.05.03 1761
55 POI HSSF, XSSF, SXSSF 성능 분석 file 황제낙엽 2013.11.05 1662
54 Parsing and Processing Large XML Documents with Digester Rules (해석중) file 황제낙엽 2008.05.13 1571
53 POI 셀 스타일 설정을 위한 예제 소스 file 황제낙엽 2008.05.16 1464
52 엑셀(Excel)문서 처리 패키지 황제낙엽 2007.01.22 1446
51 POI-HSSF and POI-XSSF - Java API To Access Microsoft Excel Format Files 황제낙엽 2013.11.05 1135
50 Comma Separated Values (CSV) - au.com.bytecode.opencsv file 황제낙엽 2007.01.23 901
49 Parsing, indexing, and searching XML with Digester and Lucene 황제낙엽 2008.05.07 543
48 Library & Properties 파일 file 황제낙엽 2011.12.23 496
47 POI HSSF 기능 가이드 -- 퀵·가이드 (한글) 황제낙엽 2008.05.16 436
46 JUnit 3.8에서 JUnit 4, TestNG 활용으로 황제낙엽 2007.09.17 426
45 Junit 을 이용한 효율적인 단위 테스트 전략 황제낙엽 2007.01.30 371
44 XSSF Examples file 황제낙엽 2011.05.04 337
43 POI HSSF 기능 가이드 -- 퀵·가이드 (영문) 황제낙엽 2008.05.15 300
42 사용자 정의 Appender 정의하여 Log4j 확장하기 황제낙엽 2009.05.28 291
41 log4j-1.2.15.jar 와 log4j.properties 예제 file 황제낙엽 2017.08.04 281
40 Apache Log4j 2 Configuration 파일 설정 황제낙엽 2020.04.01 273
39 Comma Separated Values (CSV) - com.Ostermiller.util Java Utilities 황제낙엽 2007.01.23 272