도급사에 파견생활을 하다보니 참으로 별의 별 환경도 많다.
DB나 권한문제 등등 여러가지 상황으로 로컬에서 돌려보지 못해보는 것쯤은 기본일테고..
(게을러 세팅하기 싫어서는..ㅎㅎ)
지금은 그럭저럭 나쁘지않은 곳이지만..
현재 개발중인 곳은 운영과 개발서버가 한군데 들어있어 접근 계정이 동일하다.(누가 설계했는지..)
그래서 외주에겐 계정 공개가 되어있지 않아, System.out.println 으로 웹서버에서 로그조차 찍어 볼수 없다.
뭐.. 다양한 로그 프로그램이 있긴하지만.. 불편하기도 하고 나만이 사용하는 방법과도 거리가 멀고..
습관이란 버리기가 힘든 법이니까...
그래서 뚝딱 만든 로그 출력 프로그램이다.
디렉터리 권한이 '777'인 곳을 찾아서 파일을 출력시키면 된다.
실행명령 한 사이클이 동작할 때 사용되는 모든 JSP, JAVA 등을 파일별로 저장할 수 있어 로그 확인 할때 유용하다.
아래는 클래스 파일로 만들어져 있지만.. jsp 상에서 가장 많이 include 되는 파일에 넣어줘도 좋다.(더 나을거다..)
- class
package xxx.xxx;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.PrintStream;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.GregorianCalendar;
import java.util.Random;
public class AccessOut {
public void aoc(String aoc) {
GregorianCalendar gcA = new GregorianCalendar();
SimpleDateFormat sf = new SimpleDateFormat("yyyyMMdd-HHmmss");
Date dy = gcA.getTime(); // Date -> util 패키지
String strT = sf.format(dy);
Random rand = new Random();
int rand0 = rand.nextInt(10);
int rand1 = rand.nextInt(10);
File file = new File("/xxx/WebApp/xxx/xxx/WEB-INF/log/[" + strT + "_" + rand0 + rand1 + "]" + aoc + ".log");
PrintStream printStream;
try {
printStream = new PrintStream(new FileOutputStream(file));
System.setOut(printStream);
System.setErr(printStream);
} catch (FileNotFoundException e) {
e.printStackTrace();
}
}
}
- jsp : 실행할 JSP 파일명.jsp
<%@ page import="xxx.xxx.AccessOut "%>
<%
AccessOut aos = new AccessOut();
aos.aoc("실행할 JSP 파일명");
System.out.println("--------------------------------");
System.out.println("문서 출력");
System.out.println("--------------------------------");
%>
- 결과 : 파일생성
[20140101-121212_34]실행할 JSP 파일명.log
--------------------------------
문서 출력
--------------------------------
// 로그문서 쌓아두지 말고 확인 했으면 매너있게 그때그때 빨리빨리 지워주자~
'course > 자바' 카테고리의 다른 글
간단한 문자열 파인더(Finder) (0) | 2016.07.26 |
---|---|
걍 심심풀이 땅콩~ (0) | 2015.07.14 |
객체생성 (0) | 2012.03.13 |