我把我的原木4j2.yml与泉水boot的特性混为一谈:
Properties:
property:
- name: LOGSTASH_HOST
value: ${spring:logstash.server.host}
- name: LOGSTASH_PORT
value: ${spring:logstash.server.port}
- name: APPLICATION_NAME
value: ${lower:${spring:spring.application.name:-spring}}
If I start my application I get a bunch of error messages saying:
ERROR StatusConsoleListener Resolver failed to lookup spring:logstash.server.host java.lang.IllegalStateException: Unable to obtain Spring Environment from LoggerContext
以及
ERROR StatusConsoleListener Unable to write to stream TCP:localhost:9800 for appender LOGSTASH org.apache.logging.log4j.core.appender.AppenderLoggingException: Error writing to TCP:localhost:9800: socket not available at org.apache.logging.log4j.core.net.TcpSocketManager.write(TcpSocketManager.java:214)
It can not find the serverhost until springboot starts which takes a few seconds, after that the logging works fine 以及 no more error messages.
How could I configure my log4J2 to start after or when springboot starts 以及 don t spam error messages.
I ve试图排除 spring开端 logging的 logging木:
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter</artifactId>
<exclusions>
<exclusion>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-logging</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-log4j2</artifactId>
</dependency>
or I ve tried fallback hosts 以及 ports:
Properties:
property:
- name: LOGSTASH_HOST
value: "${sys:LOGSTASH_HOST:-${env:LOGSTASH_HOST:-localhost}}" # Prefer system property, then env variable, fallback to localhost
- name: LOGSTASH_PORT
value: "${sys:LOGSTASH_PORT:-${env:LOGSTASH_PORT:-5044}}" # Prefer system property, then env variable, fallback to 5044
- name: APPLICATION_NAME
value: "${sys:spring.application.name:-${env:spring_application_name:-default-application}}" # System property, env variable, fallback