[英]In Spring Boot, how can I enable logging only for certain users?
To give you some context, we have various microservices and a config server where we store store all the application.yml
files.为了给你一些上下文,我们有各种微服务和一个配置服务器,我们在其中存储所有application.yml
文件。
The problem is when some issue happens, we have to temporarily enable logs for every application so that we can trace the activities done by the user.问题是当某些问题发生时,我们必须临时为每个应用程序启用日志,以便我们可以跟踪用户所做的活动。 But this creates a hassle as we have to change the log configs.但这会造成麻烦,因为我们必须更改日志配置。
So we want to enable logging for only certain users (say, when some issue happens and we want to debug) via changing the yml files so we don't have to touch the code or redeploy the application.因此,我们希望通过更改 yml 文件为特定用户启用日志记录(例如,当某些问题发生并且我们想要调试时),这样我们就不必修改代码或重新部署应用程序。 Basically we are thinking of creating a application-logging.yml
file for all the microservices and in this when we mention基本上我们正在考虑为所有微服务创建一个application-logging.yml
文件,当我们提到
logging:
users:
id: 123
level: warn
all the microservices will pick it up and start generating logs only for this user.所有微服务都将接收它并开始仅为该用户生成日志。
How can I implement this in Spring Boot, if its possible?如果可能的话,我如何在 Spring Boot 中实现它?
Put user ID into the thread context then use a MutableThreadContextMapFilter .将用户 ID 放入线程上下文,然后使用MutableThreadContextMapFilter 。
You can specify values via a JSON file, which log4j polls periodically to pick up changes.您可以通过 JSON 文件指定值,该文件 log4j 会定期轮询以获取更改。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.