查看日志信息
在我們編寫代碼的過程中可能看不懂錯誤提示信息,或者不知道錯出在什么地方的情況,我們可以打印輸出日志信息來檢查
使用lombok提供的日志記錄器,自定義編程查看調試信息
1、引入lombok依賴
2、在application.properties中配置日志輸出等級
logging.level.com.yan=debug
3、在控制器中自定義輸出日志
@Slf4j
public class ConsumerController {
@GetMapping("/{name}")
public String test(@PathVariable String name){
log.error("name:"+name);//輸出error等級的日志信息
String res = providerClient.sayHello(name);
return res;
}
}
控制臺上查看日志信息輸出
查看Feign日志信息
1、添加配置類FeignClientConfiguration
public class FeignClientConfiguration {
@Bean
public Logger.Level feignLevel(){
return Logger.Level.FULL;
}
}
2、在FeignClient注解上引用該配置類
全局配置日志輸出等級
@EnableFeignClients(defaultConfiguration = FeignClientConfiguration.class)
@EnableDiscoveryClient
@SpringBootApplication
public class Consumer3Application {
在控制臺上可以輸出通過feign調用服務提供者的詳細信息文章來源:http://www.zghlxwxcb.cn/news/detail-635757.html
局部配置日志輸出等級文章來源地址http://www.zghlxwxcb.cn/news/detail-635757.html
@FeignClient(value="service-provider",configuration =
FeignClientConfiguration.class)
public interface ProviderClient {
@GetMapping("/users/hello")
public String sayHello(@RequestParam("username") String username);
}
到了這里,關于查看日志信息的文章就介紹完了。如果您還想了解更多內容,請在右上角搜索TOY模板網以前的文章或繼續(xù)瀏覽下面的相關文章,希望大家以后多多支持TOY模板網!