Java

logback 직접 추가해보기

k0o9 2021. 1. 5. 22:21

그럼 이제 전에 만든 hello에 logback을 추가하여 보도록 하겠습니다.

전에 만든 hello.java를 inteliJ를 통하여 열어서 수정하겠습니다.

package com.choi;
import org.slf4j.Logger;
import org.slf4j.LogerFactory;
class hello {
	private static Logger logger = LoggerFactory.getLogger(hello.class);
	public static void main(String args[]) {

		logger.info("Hello");

	}
}

slf4j를 추가하여 소스를 수정하였습니다. 이제 이 소스를 이전에 방식으로 javac를 통하여 컴파일 하겠습니다.

javac가 slf4j와 관련된 모듈들을 인식하지 못해서 에러가 났습니다. 

java 명령어

자 이제 slf4j를 직접 추가해서 컴파일 해줍시다.

성공적으로 Hello가 출력되는걸 볼수 있습니다. 이 자료를 다시 .jar로 묶겠습니다.

manifest에 class-path를 추가해주시고 jar -cmf명령어로 test2.jar로 묶어줍니다. 묶어둔 jar로 java명령어를 실행하니 정상적으로 출력이 됩니다. 

 

logback.qos.ch/manual/configuration.html

 

Chapter 3: Configuration

Chapter 3: Logback configuration 和訳 (Japanese translation) In symbols one observes an advantage in discovery which is greatest when they express the exact nature of a thing briefly and, as it were, picture it; then indeed the labor of thought is wonder

logback.qos.ch

위의 페이지를 살펴보면 이때동안 한 것들과 비슷한 내용이 있습니다. 자 이제 저기서 configuration을 가져옵니다. 

logback.xml

이제 이 파일을 logback.xml로 만들어줍니다. 위의 소스에서 root level="debug"를 보면 level별로 찍히는 로그를 설정할 수 있는 부분인데 자세한 내용은 logback.qos.ch/manual/architecture.html를 참조하면 어떻게 되는지 알 수 있다.

 

Chapter 2: Architecture

Chapter 2: Architecture 和訳 (Japanese translation) All true classification is genealogical. —CHARLES DARWIN, The Origin of Species It is difficult, if not impossible, for anyone to learn a subject purely by reading about it, without applying the infor

logback.qos.ch