简体   繁体   English

Spring Boot:Logback不从application.properties中选择值

[英]Spring Boot :Logback not picking values from application.properties

I am trying to log the properties mentioned in application.properties using logback. 我正在尝试使用logback记录application.properties中提到的属性。

application.properties appName=myservice logging.pattern.console=%d{HH:mm:ss.SSS} [%thread] %appName %-5level - %msg%n %ex application.properties appName = myservice logging.pattern.console =%d {HH:mm:ss.SSS} [%thread]%appName%-5level-%msg%n%ex

tried the above pattern and got the below output : 尝试了上述模式并获得了以下输出:

13:10:52.193 [main] [%PARSER_ERROR[appName]]DEBUG - Execution of method runends : return value -> null 13:10:52.193 [main] [%PARSER_ERROR [appName]]调试-方法runends的执行:返回值-> null

expected out is : 预期是:

13:10:52.193 [main] [myservice]DEBUG - Execution of method runends : return value -> null 13:10:52.193 [main] [myservice] DEBUG-方法runends的执行:返回值-> null

How can this be achieved? 如何做到这一点?

You can use property in the pattern 您可以在模式中使用property

logging.pattern.console=%d{HH:mm:ss.SSS} [%thread] %property{KEY} %-5level - %msg%n %ex logging.pattern.console =%d {HH:mm:ss.SSS} [%thread]%property {KEY}%-5level-%msg%n%ex

For this, you have to add KEY in VM argument like -DKEY=myservice . 为此,您必须在VM参数中添加KEY -DKEY=myservice

11:15:23.474 [main] myservice INFO - Tomcat initialized with port(s): 8080 (http) 11:15:23.474 [main] myservice INFO-Tomcat初始化时使用端口:8080(http)

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

相关问题 如何在Spring Boot项目中将application.properties的环境属性导入logback.groovy? - How to get Environment properties from application.properties into logback.groovy in Spring Boot project? Spring Boot 应用程序:没有选择 application.properties? - Spring Boot app: Not picking up application.properties? 从 application.properties Spring Boot 中读取值 - Reading values from application.properties Spring Boot 无法在Spring Boot服务中从application.properties加载值 - Cannot load values from application.properties in a spring boot service Spring Boot application.properties - Spring Boot application.properties 在Spring Boot REST应用程序中从Application.properties读取属性 - Reading properties from Application.properties in Spring Boot REST application Spring Boot:在测试中从 application.properties 引用 pom 属性 - Spring boot: reference pom properties from application.properties in tests 使用application.properties将Spring Boot中logback.xml的位置外部化 - Externalized the location of logback.xml in Spring Boot using application.properties 在Spring Boot中动态更改application.properties值 - Dynamically change application.properties values in spring boot Spring Boot 2.1.2:如何将值从application.properties传递到log4j2.xml? - Spring Boot 2.1.2 : How to pass values from application.properties to log4j2.xml?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM