伪装日志不起作用 [英] Feign logging not working
本文介绍了伪装日志不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试让Feign rest客户端的每个请求的日志记录正常工作.但是,虽然标准" Slf4j日志记录确实可以工作,但我无法使日志记录正常工作.
我有以下内容:
public MyClient() {
initConnectionProperties();
this.service = Feign.builder()
.contract(new JAXRSContract())
.decoder(getJacksonDecoder())
.encoder(getJacksonEncoder())
.requestInterceptor(new BasicAuthRequestInterceptor(user, password))
//.client(new OkHttpClient())
.logger(new Slf4jLogger(MyClient.class)) //not working
.logLevel(feign.Logger.Level.BASIC)
.target(MyClient.class, this.url);
logger.info("Connection parameters: url = " + url + ", user = " + user); //Is working
}
解决方案
您需要按以下方式在application.properties中配置日志记录:
logging.level.<package path>.MyClient=DEBUG
如果您使用的是application.yml,则:
logging.level.<package path>.MyClient: DEBUG
可以设置日志级别以告诉Feign要记录多少.
选项是:
- 无,无日志记录(默认)
- BASIC,仅记录请求方法和URL以及响应状态代码和执行时间
- HEADERS,记录基本信息以及请求和响应标头
- 已满,记录请求和响应的标题,正文和元数据
示例:
logLevel(feign.Logger.Level.NONE)
or
logLevel(feign.Logger.Level.BASIC)
or
logLevel(feign.Logger.Level.HEADERS)
or
logLevel(feign.Logger.Level.FULL)
有关更多详细信息,您可以参考此 >
I'm trying to get logging working for each request from a Feign rest client. However I cannot get the logging to work, while 'standard' Slf4j logging does work.
I have the following:
public MyClient() {
initConnectionProperties();
this.service = Feign.builder()
.contract(new JAXRSContract())
.decoder(getJacksonDecoder())
.encoder(getJacksonEncoder())
.requestInterceptor(new BasicAuthRequestInterceptor(user, password))
//.client(new OkHttpClient())
.logger(new Slf4jLogger(MyClient.class)) //not working
.logLevel(feign.Logger.Level.BASIC)
.target(MyClient.class, this.url);
logger.info("Connection parameters: url = " + url + ", user = " + user); //Is working
}
解决方案
You need to configure logging in application.properties as below:
logging.level.<package path>.MyClient=DEBUG
If you're using application.yml then:
logging.level.<package path>.MyClient: DEBUG
The log level can be set to tell Feign how much to log.
Options are:
- NONE, No logging (DEFAULT)
- BASIC, Log only the request method and URL and the response status code and execution time
- HEADERS, Log the basic information along with request and response headers
- FULL, Log the headers, body, and metadata for both requests and responses
Example:
logLevel(feign.Logger.Level.NONE)
or
logLevel(feign.Logger.Level.BASIC)
or
logLevel(feign.Logger.Level.HEADERS)
or
logLevel(feign.Logger.Level.FULL)
For more details, you can refer this
这篇关于伪装日志不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文