sitelink1 | |
---|---|
sitelink2 | |
sitelink3 | |
extra_vars4 | |
extra_vars5 | |
extra_vars6 |
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를 삽입하는 구문이다.
댓글 0
번호 | 제목 | 글쓴이 | 날짜 | 조회 수 |
---|---|---|---|---|
14 | Apache Log4j™ 2 사용하기 | 황제낙엽 | 2023.04.28 | 3 |
13 | Migrating from Log4j 1.x to 2.x | 황제낙엽 | 2023.04.28 | 0 |
12 | SLF4J 를 사용해야 하는 이유 | 황제낙엽 | 2022.09.17 | 0 |
11 | Apache Log4j 2 Configuration 파일 설정 | 황제낙엽 | 2020.04.01 | 150 |
10 | 각 레벨별 출력파일 설정 예제 | 황제낙엽 | 2018.09.18 | 147 |
9 | log4j-1.2.15.jar 와 log4j.properties 예제 | 황제낙엽 | 2017.08.04 | 187 |
8 | Commons Logging과 Log4J | 황제낙엽 | 2013.03.07 | 102 |
7 | Library & Properties 파일 | 황제낙엽 | 2011.12.23 | 313 |
6 | WebSphere 에서 Log4j 사용하기 | 황제낙엽 | 2011.04.15 | 52 |
» | 접속 클라이언트의 아이피별로 로그 화일 기록하기 | 황제낙엽 | 2009.06.01 | 183 |
4 | 영문 메뉴얼 (PDF) | 황제낙엽 | 2009.05.29 | 19 |
3 | 사용자 정의 Appender 정의하여 Log4j 확장하기 | 황제낙엽 | 2009.05.28 | 220 |
2 | log4j에서 여러파일에 로그남기기 | 황제낙엽 | 2007.09.04 | 16 |
1 | Log4j 웹에서 사용하기 | 황제낙엽 | 2007.05.13 | 43 |