로깅

로깅 (Logging)

LLM에 주고받는 요청·응답을 보고 싶을 때가 있어요. 디버깅이나 비용 확인에서 꽤 유용하죠. LangChain4j는 로깅에 SLF4J를 쓰기 때문에, Logback이나 Log4j 같은 어떤 로깅 백엔드든 취향대로 끼워 쓸 수 있어요.

출처: 공식문서 - Logging

순수 자바 (Pure Java)

모델 인스턴스를 만들 때 .logRequests(true).logResponses(true)를 설정하면 LLM에 보내고 받은 각 요청·응답의 로깅을 켤 수 있어요.

OpenAiChatModel.builder()
    ...
    .logRequests(true)
    .logResponses(true)
    .build();

의존성에 SLF4J 로깅 백엔드가 반드시 있어야 해요. 예를 들어 Logback은 이렇게 추가해요.

<dependency>
    <groupId>ch.qos.logback</groupId>
    <artifactId>logback-classic</artifactId>
    <version>1.5.8</version>
</dependency>

Quarkus

Quarkus 통합을 쓸 때는 application.properties 파일에서 로깅을 설정해요.

...
quarkus.langchain4j.openai.chat-model.log-requests = true
quarkus.langchain4j.openai.chat-model.log-responses = true
quarkus.log.console.enable = true
quarkus.log.file.enable = false

이 속성들은 개발 모드(mvn quarkus:dev)로 앱을 실행 중일 때 Quarkus Dev UI에서도 설정하고 변경할 수 있어요. Dev UI는 http://localhost:8080/q/dev-ui에서 접근할 수 있어요.

Spring Boot

Spring Boot 통합을 쓸 때는 application.properties 파일에서 로깅을 설정해요.

...
langchain4j.open-ai.chat-model.log-requests = true
langchain4j.open-ai.chat-model.log-responses = true
logging.level.dev.langchain4j = DEBUG

더 알아보기