【开发技巧】-- SpringBoot使用LogBook打印http请求、响应信息

1. 什么是logbook?

logbook是一个用于打印http请求信息的一个开源组件。

2. 如何使用logbook? 【这里以SpringBoot项目为例】

  • 导入logbook相关maven依赖:

<dependency>
	<groupId>org.zalandogroupId>
	<artifactId>logbook-coreartifactId>
	<version>${logbook.version}version>
dependency>
<dependency>
	<groupId>org.zalandogroupId>
	<artifactId>logbook-httpclientartifactId>
	<version>${logbook.version}version>
dependency>
<dependency>
	<groupId>org.zalandogroupId>
	<artifactId>logbook-jaxrsartifactId>
	<version>${logbook.version}version>
dependency>
<dependency>
	<groupId>org.zalandogroupId>
	<artifactId>logbook-okhttpartifactId>
	<version>${logbook.version}version>
dependency>
<dependency>
	<groupId>org.zalandogroupId>
	<artifactId>logbook-okhttp2artifactId>
	<version>${logbook.version}version>
dependency>
<dependency>
	<groupId>org.zalandogroupId>
	<artifactId>logbook-servletartifactId>
	<version>${logbook.version}version>
dependency>
<dependency>
	<groupId>org.zalandogroupId>
	<artifactId>logbook-spring-boot-starterartifactId>
	<version>${logbook.version}version>
dependency>
  • 在springboot配置文件中,配置logbook的有关配置:
#logbook配置
logbook:
  write:
    level: info #logbook日志输入级别
  format:
    style: curl #这个值还可以是 http、json等
  • 配置好以上配置之后就能够使用了。

你可能感兴趣的:(开发技巧)