我在spring引导属性中定义spring.application.name, 在logback.xml中写了$ {spring.application.name:-},但显示为spring.application.name_IS_UNDEFINED。 你知道为什么吗?
如何在xml中使用类似“主机名”的字词?
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
<layout class="ch.qos.logback.classic.PatternLayout">
<Pattern>%5p [${spring.zipkin.service.name:${spring.application.name:-}},%X{X-B3-TraceId:-},%X{X-B3-SpanId:-},%X{X-Span-Export:-}] aaaaaaaaaaaaaaaaaa %d{HH:mm} %-5level %logger{36} - %msg%n</Pattern>
</layout>
</appender>
<logger name="example.logback.level.grandparents" level="TRACE"/>
<logger name="example.logback.level.grandparents.parents.children" level="INFO"/>
<root level="DEBUG">
<appender-ref ref="STDOUT" />
</root>
</configuration>
我的“ application.properties”
spring.application.name=elasticsearch-monitering
spring.kafka.consumer.group-id=foo
spring.kafka.consumer.auto-offset-reset=earliest
spring.mvc.view.prefix=/WEB-INF/jsp/
spring.mvc.view.suffix=.jsp
#elasticsearch server info
server.elasticsearch.host=my.i.p
server.elasticsearch.port=9200
答案 0 :(得分:0)
您至少需要参加3个课程
请参见以下示例:
application.properties
logback.appender.FILE-AUDIT.ConversionPattern=%d{yyyy-MM-dd HH:mm:ss, GMT+8} - %msg%n
logback-spring.xml
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
..........
<springProperty name="fileAppenderPattern" source="logback.appender.FILE-AUDIT.ConversionPattern"/>
..........
<include resource="logback-appender-file.xml"/>
..........
</configuration>
logback-appender-文件
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
<layout class="ch.qos.logback.classic.PatternLayout">
<Pattern>${fileAppenderPattern}</Pattern>
</layout>
</appender>
<logger name="example.logback.level.grandparents" level="TRACE"/>
<logger name="example.logback.level.grandparents.parents.children" level="INFO"/>
<root level="DEBUG">
<appender-ref ref="STDOUT" />
</root>
</configuration>