In microservices, sometimes we need to look at previous calls to the service, as follows, we want to look at consumer calls to the provider, browser-to-consumer calls we can look at through the browser.

Let’s look at an example to see how the consumer calls the provider

1. Create projects

2. Add the logback. XML file

Log information is persisted through logback

<? The XML version = "1.0" encoding = "utf-8"? > <configuration> <! <property name="LOG_HOME" value="${catalina.base}/logs/" /> <! - the console output - > < appender name = "Stdout" class = "ch. Qos. Logback. Core. ConsoleAppender" > <! - log output coding - > < layout class = "ch. Qos. Logback. Classic. PatternLayout" > <! Format output: %d indicates the date, %thread indicates the thread name, %-5level indicates the level from the left 5 character width % MSG: Log messages, SSS} [%thread] %-5level % Logger {50} - % MSG %n </pattern> </layout> </appender> <! Generated according to the daily log file - > < appender name = "RollingFile" class = "ch. Qos. Logback. Core. Rolling. RollingFileAppender" > < rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy"> <! ${LOG_HOME}/server.%d{YYYY-MM-DD}. Log </FileNamePattern> <MaxHistory>30</MaxHistory> </rollingPolicy> <layout class="ch.qos.logback.classic.PatternLayout"> <! Format output: %d indicates the date, %thread indicates the thread name, %-5level indicates the level from the left 5 character width % MSG: -> <pattern>%d{YYYY-MM-DD HH: MM :ss.SSS} [%thread] %-5level % Logger {50} - % MSG %n </pattern> </layout> <! -- the largest size in the log file -- > < triggeringPolicy class = "ch. Qos. Logback. Core. Rolling. SizeBasedTriggeringPolicy" > <MaxFileSize>10MB</MaxFileSize> </triggeringPolicy> </appender> <! <root level="DEBUG"> <appender-ref ref="Stdout" /> <appender-ref ref="RollingFile" /> </root> <! -- Log asynchrony to database --> <! - < appender name = "DB" class = "ch. Qos. Logback. Classic. DB. DBAppender" > asynchronous to the database log < connectionSource Class = "ch. Qos. Logback. Core. The DriverManagerConnectionSource" < > connection pool dataSource class="com.mchange.v2.c3p0.ComboPooledDataSource"> <driverClass>com.mysql.jdbc.Driver</driverClass> < url > JDBC: mysql: / / 127.0.0.1:3306 / databaseName < / url > < user > root < / user > < password > root < / password > < / a dataSource > </connectionSource> </appender> --> </configuration>Copy the code

3. Set the log output level

Logback Output log level Debug level when required

4. Add a method to the startup class

Add a method to get the log level in the startup class.

@EnableFeignClients @EnableDiscoveryClient @SpringBootApplication public class SpringcloudFeignProdcutConsumerApplication {/ * * * NONE: do not record any information, Default * BASIC: Records the request method, request URL, status code, and time HEADERS: Records some common information based on BASIC * FULL: records the request and all corresponding information * @return */ @bean public Logger.Level getLogger(){ return Logger.Level.FULL; } public static void main(String[] args) { SpringApplication.run(SpringcloudFeignProdcutConsumerApplication.class, args); }}Copy the code

5. Start the program test

Enable provider and Consumer access respectively