Skip to content

Latest commit

 

History

History
89 lines (64 loc) · 1.89 KB

README.md

File metadata and controls

89 lines (64 loc) · 1.89 KB

RequestLog

中文文档


Introduction

RequestLog is an HTTP request logging and retry compensation tool based on Spring Boot.
Features: Low intrusion and easy integration.



Quick Start

Taking RestTemplate as an example.

Maven Dependency

<dependency>
    <groupId>io.github.requestlog</groupId>
    <artifactId>request-log-resttemplate-starter</artifactId>
    <version>${latest_stable_version}</version>
</dependency>

Enhance RestTemplate

Enhance the RestTemplate client using annotations.

@RequestLogEnhanced 
@Bean
public RestTemplate restTemplate() {
    return new RestTemplate();
}

Define Repository for Persistence

@Component
public class MyRequestLogRepository implements IRequestLogRepository {
    @Override
    public void saveRequestLog(RequestLog requestLog) {
        // save request log
    }
    @Override
    public void saveRequestLogAndRetryJob(RequestLog requestLog, RequestRetryJob requestRetryJob) {
        // save request log and retry job
    }
}

Wrap Request Code

// Original request code
String result = restTemplate.getForObject("url", String.class);

// Wrap the request using LogContext
String wrappedResult = LogContext.log().execute(() -> {
    return restTemplate.getForObject("url", String.class);
});

For the wrapped request, when an exception occurs or the response status code is not 2xx, the corresponding save method of the custom IRequestLogRepository will be invoked.



Detailed Documentation