如何在不重新启动Spring启动应用程序的情况下更改运行时的日志级别 [英] how do I change log level in runtime without restarting spring boot application

查看:432
本文介绍了如何在不重新启动Spring启动应用程序的情况下更改运行时的日志级别的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在PCF中部署了springboot应用程序。我想根据环境变量记录消息。我应该怎么做才能在不重新启动应用程序的情况下运行时日志级别更改?

I have deployed springboot application in PCF . I want to log the message based on the environment variable .What should I do so that the run time log level change will work without restarting the application?

推荐答案

可以使用http-endpoint更改Spring Boot 1.5+中的日志级别

Changing the log level in Spring Boot 1.5+ can be done with a http-endpoint

添加

<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-actuator</artifactId>
</dependency>

而且你可以使用

curl -X "POST" "http://localhost:8080/loggers/de.springbootbuch" \
     -H "Content-Type: application/json; charset=utf-8" \
     -d $'{
  "configuredLevel": "WARN"
}'  

除了/ loggers /之外的所有内容都是记录器的名称。

Where everything beyond /loggers/ is the name of the logger.

如果你在PCF中运行它,那就更好了:这是从他们的后端直接支持。

If you running this in PCF it get's even better: This is directly supported from their backend.

这篇关于如何在不重新启动Spring启动应用程序的情况下更改运行时的日志级别的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆