简体   繁体   English

在 Spring Boot 中,如何只为某些用户启用日志记录?

[英]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.

相关问题 我可以只允许用户使用某些路由而无需使用 spring 引导登录吗? - Can i allow a user only to certain routes without logging in with spring boot? 如何在Spring Boot Security OAuth2应用程序中仅对某些类启用OAuth2? - How do I enable OAuth2 for only certain classes in my Spring Boot Security OAuth2 app? 如何在 spring 启动 jar 中启用文件日志记录 - how to enable file logging in spring boot jar 使用log4j进行Spring Boot日志记录-如何启用Spring Boot日志条目? - Spring boot logging with log4j - how do I ENABLE spring boot log entries? 如何替换 spring boot 2.0 中的默认日志系统 - How can I replace the default logging system in spring boot 2.0 如何禁用Spring Boot日志记录配置? - How can I disable Spring Boot logging configuration? 如何在 Spring Boot 应用程序中启用 DynamoDB 查询日志记录? - How to enable logging of DynamoDB queries in the Spring Boot application? 为某些用户启用日志记录Log4j - Enable Logging Log4j for certain users 我如何获得在 spring boot 中具有角色的所有用户的列表? - How can i get the liste of all users with roles in spring boot? 可以配置 Java 日志记录以使用 Spring Boot 日志记录吗? - can I configure Java logging to make use of Spring Boot logging?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM