Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Re-add slf4j logging #2154

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -22,18 +22,18 @@
import java.util.List;
import java.util.stream.Collectors;

import org.apache.commons.logging.LogFactory;
import org.apache.pdfbox.pdfparser.PDFParser;
import org.apache.pdfbox.pdmodel.PDDocument;
import org.apache.pdfbox.pdmodel.PDPage;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import org.springframework.ai.document.Document;
import org.springframework.ai.document.DocumentReader;
import org.springframework.ai.reader.pdf.config.PdfDocumentReaderConfig;
import org.springframework.ai.reader.pdf.layout.PDFLayoutTextStripperByArea;
import org.springframework.core.io.DefaultResourceLoader;
import org.springframework.core.io.Resource;
import org.springframework.core.log.LogAccessor;
import org.springframework.util.CollectionUtils;
import org.springframework.util.StringUtils;

Expand All @@ -55,10 +55,10 @@ public class PagePdfDocumentReader implements DocumentReader {

private static final String PDF_PAGE_REGION = "pdfPageRegion";

private static final LogAccessor logger = new LogAccessor(LogFactory.getLog(PagePdfDocumentReader.class));

protected final PDDocument document;

private final Logger logger = LoggerFactory.getLogger(getClass());

protected String resourceFileName;

private PdfDocumentReaderConfig config;
Expand Down Expand Up @@ -112,7 +112,7 @@ public List<Document> get() {
for (PDPage page : this.document.getDocumentCatalog().getPages()) {
lastPage = page;
if (counter % logFrequency == 0 && counter / logFrequency < 10) {
logger.info("Processing PDF page: " + (counter + 1));
logger.info("Processing PDF page: {}", (counter + 1));
}
counter++;

Expand Down Expand Up @@ -154,7 +154,7 @@ public List<Document> get() {
readDocuments.add(toDocument(lastPage, pageTextGroupList.stream().collect(Collectors.joining()),
startPageNumber, pageNumber));
}
logger.info("Processing " + totalPages + " pages");
logger.info("Processing {} pages", totalPages);
return readDocuments;

}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@

import org.apache.pdfbox.pdfparser.PDFParser;
import org.apache.pdfbox.pdmodel.PDDocument;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import org.springframework.ai.document.Document;
import org.springframework.ai.document.DocumentReader;
Expand All @@ -32,7 +34,6 @@
import org.springframework.ai.reader.pdf.layout.PDFLayoutTextStripperByArea;
import org.springframework.core.io.DefaultResourceLoader;
import org.springframework.core.io.Resource;
import org.springframework.core.log.LogAccessor;
import org.springframework.util.CollectionUtils;
import org.springframework.util.StringUtils;

Expand Down Expand Up @@ -61,7 +62,7 @@ public class ParagraphPdfDocumentReader implements DocumentReader {

protected final PDDocument document;

private static final LogAccessor logger = new LogAccessor(ParagraphPdfDocumentReader.class);
private final Logger logger = LoggerFactory.getLogger(getClass());

private final ParagraphManager paragraphTextExtractor;

Expand Down
4 changes: 4 additions & 0 deletions models/spring-ai-anthropic/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,10 @@
<groupId>org.springframework</groupId>
<artifactId>spring-context-support</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-logging</artifactId>
</dependency>

<!-- test dependencies -->
<dependency>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@
import io.micrometer.observation.Observation;
import io.micrometer.observation.ObservationRegistry;
import io.micrometer.observation.contextpropagation.ObservationThreadLocalAccessor;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import reactor.core.publisher.Flux;
import reactor.core.publisher.Mono;

Expand Down Expand Up @@ -65,7 +67,6 @@
import org.springframework.ai.model.function.FunctionCallbackResolver;
import org.springframework.ai.model.function.FunctionCallingOptions;
import org.springframework.ai.retry.RetryUtils;
import org.springframework.core.log.LogAccessor;
import org.springframework.http.ResponseEntity;
import org.springframework.retry.support.RetryTemplate;
import org.springframework.util.Assert;
Expand All @@ -91,7 +92,7 @@ public class AnthropicChatModel extends AbstractToolCallSupport implements ChatM

public static final Double DEFAULT_TEMPERATURE = 0.8;

private static final LogAccessor logger = new LogAccessor(AnthropicChatModel.class);
private static final Logger logger = LoggerFactory.getLogger(AnthropicChatModel.class);

private static final ChatModelObservationConvention DEFAULT_OBSERVATION_CONVENTION = new DefaultChatModelObservationConvention();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@
import org.junit.jupiter.api.condition.EnabledIfEnvironmentVariable;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.ValueSource;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import reactor.core.publisher.Flux;

import org.springframework.ai.anthropic.api.AnthropicApi;
Expand Down Expand Up @@ -57,7 +59,6 @@
import org.springframework.core.convert.support.DefaultConversionService;
import org.springframework.core.io.ClassPathResource;
import org.springframework.core.io.Resource;
import org.springframework.core.log.LogAccessor;
import org.springframework.util.MimeType;
import org.springframework.util.MimeTypeUtils;
import org.springframework.util.StringUtils;
Expand All @@ -68,7 +69,7 @@
@EnabledIfEnvironmentVariable(named = "ANTHROPIC_API_KEY", matches = ".+")
class AnthropicChatModelIT {

private static final LogAccessor logger = new LogAccessor(AnthropicChatModelIT.class);
private static final Logger logger = LoggerFactory.getLogger(AnthropicChatModelIT.class);

@Autowired
protected ChatModel chatModel;
Expand Down Expand Up @@ -282,7 +283,7 @@ void functionCallTest() {

ChatResponse response = this.chatModel.call(new Prompt(messages, promptOptions));

logger.info("Response: " + response);
logger.info("Response: {}", response);

Generation generation = response.getResult();
assertThat(generation).isNotNull();
Expand Down Expand Up @@ -321,7 +322,7 @@ void streamFunctionCallTest() {
.map(cr -> cr.getResult().getOutput().getText())
.collect(Collectors.joining());

logger.info("Response: " + content);
logger.info("Response: {}", content);
assertThat(content).contains("30", "10", "15");
}

Expand All @@ -346,7 +347,7 @@ void streamFunctionCallUsageTest() {

ChatResponse chatResponse = responseFlux.last().block();

logger.info("Response: " + chatResponse);
logger.info("Response: {}", chatResponse);
Usage usage = chatResponse.getMetadata().getUsage();

assertThat(usage).isNotNull();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,11 @@
import com.fasterxml.jackson.core.type.TypeReference;
import com.fasterxml.jackson.databind.ObjectMapper;
import org.junit.jupiter.api.Test;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import org.springframework.ai.anthropic.api.AnthropicApi.StreamEvent;
import org.springframework.core.io.DefaultResourceLoader;
import org.springframework.core.log.LogAccessor;

import static org.assertj.core.api.Assertions.assertThat;

Expand All @@ -36,7 +37,7 @@
*/
public class EventParsingTests {

private static final LogAccessor logger = new LogAccessor(EventParsingTests.class);
private static final Logger logger = LoggerFactory.getLogger(EventParsingTests.class);

@Test
public void readEvents() throws IOException {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@

import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.condition.EnabledIfEnvironmentVariable;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import org.springframework.ai.anthropic.api.AnthropicApi;
import org.springframework.ai.anthropic.api.AnthropicApi.AnthropicMessage;
Expand All @@ -34,7 +36,6 @@
import org.springframework.ai.anthropic.api.tool.XmlHelper.Tools.ToolDescription;
import org.springframework.ai.anthropic.api.tool.XmlHelper.Tools.ToolDescription.Parameter;
import org.springframework.ai.model.ModelOptionsUtils;
import org.springframework.core.log.LogAccessor;
import org.springframework.http.ResponseEntity;

import static org.assertj.core.api.Assertions.assertThat;
Expand Down Expand Up @@ -80,7 +81,7 @@ public class AnthropicApiLegacyToolIT {

public static final ConcurrentHashMap<String, Function> FUNCTIONS = new ConcurrentHashMap<>();

private static final LogAccessor logger = new LogAccessor(AnthropicApiLegacyToolIT.class);
private static final Logger logger = LoggerFactory.getLogger(AnthropicApiLegacyToolIT.class);

AnthropicApi anthropicApi = new AnthropicApi(System.getenv("ANTHROPIC_API_KEY"));

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@

import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.condition.EnabledIfEnvironmentVariable;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import org.springframework.ai.anthropic.api.AnthropicApi;
import org.springframework.ai.anthropic.api.AnthropicApi.AnthropicMessage;
Expand All @@ -33,7 +35,6 @@
import org.springframework.ai.anthropic.api.AnthropicApi.Role;
import org.springframework.ai.anthropic.api.AnthropicApi.Tool;
import org.springframework.ai.model.ModelOptionsUtils;
import org.springframework.core.log.LogAccessor;
import org.springframework.http.ResponseEntity;
import org.springframework.util.CollectionUtils;

Expand All @@ -55,7 +56,7 @@ public class AnthropicApiToolIT {

public static final ConcurrentHashMap<String, Function> FUNCTIONS = new ConcurrentHashMap<>();

private static final LogAccessor logger = new LogAccessor(AnthropicApiToolIT.class);
private static final Logger logger = LoggerFactory.getLogger(AnthropicApiToolIT.class);

AnthropicApi anthropicApi = new AnthropicApi(System.getenv("ANTHROPIC_API_KEY"));

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@
import org.junit.jupiter.api.condition.EnabledIfEnvironmentVariable;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.ValueSource;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import reactor.core.publisher.Flux;

import org.springframework.ai.anthropic.AnthropicChatOptions;
Expand All @@ -48,7 +50,6 @@
import org.springframework.core.convert.support.DefaultConversionService;
import org.springframework.core.io.ClassPathResource;
import org.springframework.core.io.Resource;
import org.springframework.core.log.LogAccessor;
import org.springframework.test.context.ActiveProfiles;
import org.springframework.util.MimeTypeUtils;

Expand All @@ -59,7 +60,7 @@
@ActiveProfiles("logging-test")
class AnthropicChatClientIT {

private static final LogAccessor logger = new LogAccessor(AnthropicChatClientIT.class);
private static final Logger logger = LoggerFactory.getLogger(AnthropicChatClientIT.class);

@Autowired
ChatModel chatModel;
Expand Down Expand Up @@ -218,7 +219,7 @@ void functionCallTest() {
.content();
// @formatter:on

logger.info("Response: " + response);
logger.info("Response: {}", response);

assertThat(response).contains("30", "10", "15");
}
Expand All @@ -236,7 +237,7 @@ void functionCallWithGeneratedDescription() {
.content();
// @formatter:on

logger.info("Response: " + response);
logger.info("Response: {}", response);

assertThat(response).contains("30", "10", "15");
}
Expand All @@ -257,7 +258,7 @@ void defaultFunctionCallTest() {
.content();
// @formatter:on

logger.info("Response: " + response);
logger.info("Response: {}", response);

assertThat(response).contains("30", "10", "15");
}
Expand All @@ -277,7 +278,7 @@ void streamFunctionCallTest() {
// @formatter:on

String content = response.collectList().block().stream().collect(Collectors.joining());
logger.info("Response: " + content);
logger.info("Response: {}", content);

assertThat(content).contains("30", "10", "15");
}
Expand Down Expand Up @@ -339,7 +340,7 @@ void streamingMultiModality() throws IOException {

String content = response.collectList().block().stream().collect(Collectors.joining());

logger.info("Response: " + content);
logger.info("Response: {}", content);
assertThat(content).contains("bananas", "apple");
assertThat(content).containsAnyOf("bowl", "basket");
}
Expand Down
Loading