Logging
LangChain4j uses SLF4J for logging, allowing you to plug in any logging backend you prefer, such as Logback or Log4j.
Pure Java
You can enable logging of each request and response to the LLM by setting
.logRequests(true) and .logResponses(true) when creating an instance of the model:
OpenAiChatModel.builder()
...
.logRequests(true)
.logResponses(true)
.build();
Make sure you have one of the SLF4J logging backends in your dependencies, for example, Logback:
<dependency>
<groupId>ch.qos.logback</groupId>
<artifactId>logback-classic</artifactId>
<version>1.5.8</version>
</dependency>
Quarkus
When using Quarkus integration,
logging is configured in the application.properties file:
...
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
These properties can also be set and changed in the Quarkus Dev UI,
when running the application in dev mode (mvn quarkus:dev).
The Dev UI is then available at http://localhost:8080/q/dev-ui.
Spring Boot
When using Spring Boot integration,
logging is configured in the application.properties file:
...
langchain4j.open-ai.chat-model.log-requests = true
langchain4j.open-ai.chat-model.log-responses = true
logging.level.dev.langchain4j = DEBUG
Sensitive data in logs
Request and response logs can contain credentials.
When an integration sends its requests through LangChain4j's own HTTP client
(for example OpenAI, Anthropic, Google AI Gemini, Mistral AI and Ollama),
logRequests and logResponses mask the most common ones:
- Headers of requests and responses: the value of every header whose name contains
auth,key,token,secret,password,credential,cookie,signatureorsession(for exampleAuthorizationorx-api-key), ignoring case. A value of 20 or more characters is shown as its first 5 and last 2 characters (sk-pr...Xy), a shorter value is replaced by.... - Request URL: the user info (
https://user:password@hostis logged ashttps://***@host) and the value of every query parameter whose name contains one of the words above, as well assigandcode. - Request body: the values of the JSON string fields and form fields
api_key,apikey,api-key,password,secret,client_secret,token,access_token,refresh_tokenandid_token.
Body field names are matched as a whole and ignoring case,
so apiKey is masked, but max_tokens is not.
Everything else, including your prompts and the model's answers, is logged as is.
The Amazon Bedrock integration masks request and response headers with the same name rule
and logs [REDACTED] instead of their values.
The libraries that some integrations use to talk to remote services have their own logging,
which can print credentials (for example API keys in headers or URLs).
Wherever real keys are used, keep these loggers at INFO or above and leave these settings off:
- Apache HttpClient 4:
org.apache.http.headersandorg.apache.http.wire - Apache HttpClient 5:
org.apache.hc.client5.http.headersandorg.apache.hc.client5.http.wire(the Docker MCP transport uses it and sends Docker registry credentials in a request header) - gRPC with Netty:
io.grpc.netty - JDK
HttpClient: the system property-Djdk.httpclient.HttpClient.log=headers(orall) - google-http-client:
com.google.api.client.http.HttpTransportat thejava.util.logginglevelCONFIGor finer - Spring
WebClient:spring.http.codecs.log-request-details=true(spring.codec.log-request-detailsbefore Spring Boot 3.5), which logs headers atTRACE - AWS SDK for Java: wire logging, that is the Apache HttpClient loggers above,
or
io.netty.handler.loggingandio.netty.handler.codec.http2for its Netty-based client - OpenAI Java SDK: the environment variable
OPENAI_LOG=debug(it hides only the standard authentication headers, not custom ones)