全局或局部配置feign的日志级别

局部配置

说明:全局和局部配置就差一个@Configuration和在不在@FeignClient的configuration中引用,局部需要在@FeignClient的configuration中引用,全局则不需要引用。
日志层级从低到高依次为:NONE,BASIC,HEADERS,FULL。级别越高理论上打印的日志应该越全

声明日志级别
import feign.Logger;
import org.springframework.context.annotation.Bean;

public class FeignLoggerLevelConfiguration {
    @Bean
    Logger.Level feignLoggerLevel() {
        return Logger.Level.FULL;
    }
}
使用声明的日志级别
@FeignClient(name = "stockFeign", url = "http://stock-center.net", configuration = {FeignLoggerLevelConfiguration.class})
public interface StockFeign {

    @PostMapping("/api/v1/transferorder/queryBatchImportTransferOrder")
    FeignResultDto<Page<TransferImportListOutDto>> queryBatchTransferOrder(@RequestBody PageQueryDto<TransferImportListInDto> pageQueryDto);

}

全局配置

声明日志级别
import feign.Logger;
import org.springframework.context.annotation.Bean;

@Configuration
public class FeignLoggerLevelConfiguration {
    @Bean
    Logger.Level feignLoggerLevel() {
        return Logger.Level.HEADERS;
    }
}

全局和局部同时配置时,局部生效

posted @ 2024-03-15 16:36  品书读茶  阅读(165)  评论(0编辑  收藏  举报