简体   繁体   English

我可以将 Spring 引导日志记录设置从 application.properties 文件移到未跟踪的文件中吗?

[英]Can I move Spring Boot logging settings out of application.properties file and into an untracked file?

I am working on building a SpringBoot app with my workmates.我正在和我的同事一起构建一个 SpringBoot 应用程序。 We all have different preferred logging levels for the app.对于应用程序,我们都有不同的首选日志记录级别。 We have been battling back and forth with each other's logging changed to application.properties.我们一直在为将彼此的日志更改为 application.properties 进行斗争。 Is there a way to move all of the logging.level.* stuff out of that application.properties file and into a ~logging.properties file or something?有没有办法将所有logging.level.*东西从 application.properties 文件中移出到 ~logging.properties 文件中? That way we can add that file to the.gitignore and not track that file so we can each leave our logging alone.这样我们就可以将该文件添加到 .gitignore 并且不跟踪该文件,这样我们每个人都可以单独留下我们的日志记录。 We are using Java annotations and not xml btw.我们使用的是 Java 注释,而不是 xml 顺便说一句。

I've tried adding @PropertySource("classpath:logging.properties") to the application file, but I read somewhere that the logging gets setup early on in the init process and this won't work.我尝试将@PropertySource("classpath:logging.properties")添加到应用程序文件中,但我在某处读到日志记录在初始化过程的早期设置,这将不起作用。 I tried it anyway and it doesn't work (so confirmed I guess).无论如何我都试过了,但它不起作用(我猜是这样确认的)。

I can't believe there's isn't more info on this out there.. I'd imagine the members of a dev team each want their own custom level of logging and don't want to keep stepping on each other's toes/commits.我不敢相信没有更多关于这方面的信息。我想开发团队的成员每个人都想要自己的自定义日志级别,并且不想继续踩对方的脚趾/提交。

You can just override it using a command line property.您可以使用命令行属性覆盖它。 The fallback strategy will take command line -D args as the highest overriding priority.回退策略将命令行 -D args 作为最高优先级。

https://docs.spring.io/spring-boot/docs/current/reference/html/spring-boot-features.html#boot-features-external-config https://docs.spring.io/spring-boot/docs/current/reference/html/spring-boot-features.html#boot-features-external-config

I would recommend to have logback.xml file inside resources/ with some defaults that works for everyone (more likely to the application in question) and then you can provide --logging.config=/path/to/your/very/custom/logback.xml file whenever you start the application locally .我建议在resources/中使用logback.xml文件,其中一些默认值适用于所有人(更有可能是相关应用程序),然后您可以提供--logging.config=/path/to/your/very/custom/logback.xml每当您在本地启动应用程序时, --logging.config=/path/to/your/very/custom/logback.xml文件。

That should work for everyone.这应该适用于每个人。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Spring 引导无法识别 application.properties 文件 - Spring Boot not recognizing application.properties file 我可以将 application.properties 文件添加到 Spring Boot 项目中吗? - Can I just add an application.properties file to a Spring Boot project? 如何在 Spring Boot 应用程序的 application.properties 文件中设置 MyBatis 配置属性? - How do I set MyBatis configuration properties in an application.properties file in a Spring Boot application? Spring 引导应用程序不使用 Application.Properties 文件 - Spring Boot Application not using Application.Properties file Spring Boot应用程序不拉入外部application.properties文件 - Spring boot application not pulling external application.properties file in 在Spring Boot中使用带有CamelSpringTestSupport的测试application.properties文件 - Using test application.properties file with CamelSpringTestSupport in Spring Boot 使用特定的application.properties文件将Spring Boot应用程序部署到Heroku - Deploy Spring Boot app to Heroku with a particular application.properties file 春季启动:从“ application.properties”读取文件路径 - Spring boot: Read a file PATH from “application.properties” 找不到春季启动测试application.properties文件 - spring boot test application.properties file not found Spring Boot 必须在加载 application.properties 之前创建一个文件 - Spring boot must to create a file before the application.properties are load
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM