블로그 이미지
항상웃자 애바른2

카테고리

분류 전체보기 (99)
사진 (4)
비공개 (0)
업무 (1)
자동차 (6)
개발 (23)
가족 (33)
모바일 (13)
Total
Today
Yesterday

달력

« » 2025.12
1 2 3 4 5 6
7 8 9 10 11 12 13
14 15 16 17 18 19 20
21 22 23 24 25 26 27
28 29 30 31

공지사항

최근에 올라온 글

java에서 클래스 명, 라인 번호 찍기.


java에서 php의 __FILE__ __LINE__과 유사한 기능을 구현하는 방법!!!



String a = "hahaha";


System.out.println("===========디버깅 시작했다~================");

System.out.print("file:" + (new Throwable()).getStackTrace()[0].getClassName() + "  line");

System.out.println((new Throwable()).getStackTrace()[0].getLineNumber());

System.out.println(a);

System.out.println("===========디버깅 끝났다~================");




eclipse의 경우 템플릿을 지정해놓으면 더 쉽게 할 수 있다.


도구->환경설정->Java->편집기->템플리트


새로작성


이름: dprt

컨텍스트: java

자동삽입에 체크

설명: 디버깅용 프린트

패턴:

//* debugging~~ ${date} ${time}

System.out.println("===========디버깅 시작했다~================");

System.out.println("time:" + new java.text.SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new java.util.Date()));

System.out.print(new Throwable().getStackTrace()[0].getClassName() +"." + new Throwable().getStackTrace()[0].getMethodName() + "()" );

System.out.println("  line: " + new Throwable().getStackTrace()[0].getLineNumber());

System.out.println(${cursor});

System.out.println("===========디버깅 끝났다~================");

// the end of debuuging.. */


요렇게 넣고 확인하면..


java 코드에서 "dprt"라고 치고 ctrl+space 치면 위의 구문들이 찍힌다. 디버깅용으로 굉장히 편하다.


log4j 써도 된다~


출처:http://iilii.egloos.com/2856745

Posted by 애바른2
, |