apolloconfig / apollo

Apollo is a reliable configuration management system suitable for microservice configuration management scenarios.
https://www.apolloconfig.com
Apache License 2.0
29.16k stars 10.2k forks source link

logback日志中springProperty方式的占位参数出现_IS_UNDEFINED #2723

Closed mark0614 closed 4 years ago

mark0614 commented 5 years ago

apollo配置:

apollo.bootstrap.enabled=true
apollo.bootstrap.namespaces=application,config-gateway-route,RD.config-jasypt,RD.config-eureka-client,RD.config-redis,RD.config-monitor
apollo.bootstrap.eagerLoad.enabled=true

apollo中心的application.properties配置:

server.port = 1002
spring.main.allow-bean-definition-overriding = true

hystrix.command.default.execution.isolation.strategy = SEMAPHORE
hystrix.shareSecurityContext = true
hystrix.command.default.execution.isolation.thread.timeoutInMilliseconds = 30000

spring.application.name = doudou-gateway
spring.profiles.active = dev
com.toyou.doudou.log.trace.enabled = false

logging.level.com.ctrip.framework.apollo.use.cases.doudou.gateway = info

业务服务的logback-spring.xml部分配置:

<configuration>
    <contextName>${APP_NAME}</contextName>
    <springProperty name="APP_NAME" scope="context" source="spring.application.name"/>
    <springProperty name="LOG_FILE" scope="context" source="logging.file" defaultValue="/logs/application/${APP_NAME}"/>
    <springProperty name="LOG_POINT_FILE" scope="context" source="logging.file" defaultValue="/logs/point"/>
    <springProperty name="LOG_MAXFILESIZE" scope="context" source="logback.filesize" defaultValue="50MB"/>
    <springProperty name="LOG_FILEMAXDAY" scope="context" source="logback.filemaxday" defaultValue="7"/>
    <springProperty name="ServerIP" scope="context" source="spring.cloud.client.ip-address" defaultValue="0.0.0.0"/>
    <springProperty name="ServerPort" scope="context" source="server.port" defaultValue="0000"/>

    <!-- 彩色日志 -->
    <!-- 彩色日志依赖的渲染类 -->
    <conversionRule conversionWord="clr" converterClass="org.springframework.boot.logging.logback.ColorConverter" />
    <conversionRule conversionWord="wex" converterClass="org.springframework.boot.logging.logback.WhitespaceThrowableProxyConverter" />
    <conversionRule conversionWord="wEx" converterClass="org.springframework.boot.logging.logback.ExtendedWhitespaceThrowableProxyConverter" />

    <!-- 彩色日志格式 -->
    <property name="CONSOLE_LOG_PATTERN"
              value="[${APP_NAME}:${ServerIP}:${ServerPort}] %clr(%d{yyyy-MM-dd HH:mm:ss.SSS}){faint} %clr(%level){blue} %clr(${PID}){magenta} %clr([%X{traceId}]){yellow} %clr([%thread]){orange} %clr(%logger){cyan} %m%n${LOG_EXCEPTION_CONVERSION_WORD:-%wEx}" />
    <property name="CONSOLE_LOG_PATTERN_NO_COLOR" value="[${APP_NAME}:${ServerIP}:${ServerPort}] %d{yyyy-MM-dd HH:mm:ss.SSS} %level ${PID} [%X{traceId}] [%thread] %logger %m%n${LOG_EXCEPTION_CONVERSION_WORD:-%wEx}" />

    <!-- 控制台日志 -->
    <appender name="StdoutAppender" class="ch.qos.logback.core.ConsoleAppender">
        <withJansi>true</withJansi>
        <encoder>
            <pattern>${CONSOLE_LOG_PATTERN}</pattern>
            <charset>UTF-8</charset>
        </encoder>
    </appender>

服务启动后的部分日志:

[doudou-gateway:172.20.13.124:1002] 2019-11-01 17:47:45.554 INFO 4693140 [] [main] com.ulisesbocchio.jasyptspringboot.EncryptablePropertySourceConverter Converting PropertySource springCloudClientHostInfo [org.springframework.core.env.MapPropertySource] to EncryptableMapPropertySourceWrapper
[doudou-gateway:172.20.13.124:1002] 2019-11-01 17:47:45.554 INFO 4693140 [] [main] com.ulisesbocchio.jasyptspringboot.EncryptablePropertySourceConverter Converting PropertySource applicationConfig: [classpath:/bootstrap.properties] [org.springframework.boot.env.OriginTrackedMapPropertySource] to EncryptableMapPropertySourceWrapper
[doudou-gateway:172.20.13.124:1002] 2019-11-01 17:47:45.569 INFO 4693140 [] [main] org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor JSR-330 'javax.inject.Inject' annotation found and supported for autowiring
[doudou-gateway:172.20.13.124:1002] 2019-11-01 17:47:45.612 INFO 4693140 [] [main] org.springframework.context.support.PostProcessorRegistrationDelegate$BeanPostProcessorChecker Bean 'configurationPropertiesRebinderAutoConfiguration' of type [org.springframework.cloud.autoconfigure.ConfigurationPropertiesRebinderAutoConfiguration$$EnhancerBySpringCGLIB$$1d2b506a] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying)
[doudou-gateway:172.20.13.124:1002] 2019-11-01 17:47:45.700 INFO 4693140 [] [main] com.ulisesbocchio.jasyptspringboot.resolver.DefaultLazyPropertyResolver Property Resolver custom Bean not found with name 'encryptablePropertyResolver'. Initializing Default Property Resolver
[doudou-gateway:172.20.13.124:1002] 2019-11-01 17:47:45.701 INFO 4693140 [] [main] com.ulisesbocchio.jasyptspringboot.detector.DefaultLazyPropertyDetector Property Detector custom Bean not found with name 'encryptablePropertyDetector'. Initializing Default Property Detector

[APP_NAME_IS_UNDEFINED:172.20.13.124:0000] 2019-11-01 17:47:46.043 INFO 4693140 [] [main] com.ulisesbocchio.jasyptspringboot.encryptor.DefaultLazyEncryptor String Encryptor custom Bean not found with name 'jasyptStringEncryptor'. Initializing Default String Encryptor
[APP_NAME_IS_UNDEFINED:172.20.13.124:0000] 2019-11-01 17:47:46.052 INFO 4693140 [] [main] com.ulisesbocchio.jasyptspringboot.encryptor.DefaultLazyEncryptor Encryptor config not found for property jasypt.encryptor.keyObtentionIterations, using default value: 1000
[APP_NAME_IS_UNDEFINED:172.20.13.124:0000] 2019-11-01 17:47:46.053 INFO 4693140 [] [main] com.ulisesbocchio.jasyptspringboot.encryptor.DefaultLazyEncryptor Encryptor config not found for property jasypt.encryptor.providerName, using default value: null
[APP_NAME_IS_UNDEFINED:172.20.13.124:0000] 2019-11-01 17:47:46.053 INFO 4693140 [] [main] com.ulisesbocchio.jasyptspringboot.encryptor.DefaultLazyEncryptor Encryptor config not found for property jasypt.encryptor.providerClassName, using default value: null
[APP_NAME_IS_UNDEFINED:172.20.13.124:0000] 2019-11-01 17:47:46.053 INFO 4693140 [] [main] com.ulisesbocchio.jasyptspringboot.encryptor.DefaultLazyEncryptor Encryptor config not found for property jasypt.encryptor.saltGeneratorClassname, using default value: org.jasypt.salt.RandomSaltGenerator

问题: 日志文件配置中的APP_NAME变量为什么会出现APP_NAME_IS_UNDEFINED这种情况,而且刚启动的时候APP_NAME是有值得,启动了一会就没值了

nobodyiam commented 5 years ago

我在apollo-use-cases中增加了一个例子,跑下来是OK的,可以参考下

https://github.com/ctripcorp/apollo-use-cases/blob/master/spring-boot-dubbo/spring-boot-dubbo-provider/src/main/resources/logback-spring.xml

mark0614 commented 5 years ago

我在apollo-use-cases中增加了一个例子,跑下来是OK的,可以参考下

https://github.com/ctripcorp/apollo-use-cases/blob/master/spring-boot-dubbo/spring-boot-dubbo-provider/src/main/resources/logback-spring.xml

楼主,你好。按照你的方法,我使用springInitializer自定义了一个demo项目(spring boot版本:2.0.3.RELEASE),启动后,log是正常的:

[demo1:8080] 2019-11-04 18:07:30.523 INFO 5976 [] [main] com.example.demo1.Demo1Application No active profile set, falling back to default profiles: default
[demo1:8080] 2019-11-04 18:07:30.535 INFO 5976 [] [main] org.springframework.boot.web.servlet.context.AnnotationConfigServletWebServerApplicationContext Refreshing org.springframework.boot.web.servlet.context.AnnotationConfigServletWebServerApplicationContext@636e8cc: startup date [Mon Nov 04 18:07:30 CST 2019]; parent: org.springframework.context.annotation.AnnotationConfigApplicationContext@57bc27f5
[demo1:8080] 2019-11-04 18:07:31.330 INFO 5976 [] [main] org.springframework.cloud.context.scope.GenericScope BeanFactory id=5ea7cbcb-b13e-31c0-85f3-8b61ad769e22
[demo1:8080] 2019-11-04 18:07:31.357 INFO 5976 [] [main] org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor JSR-330 'javax.inject.Inject' annotation found and supported for autowiring
[demo1:8080] 2019-11-04 18:07:31.552 INFO 5976 [] [main] org.springframework.context.support.PostProcessorRegistrationDelegate$BeanPostProcessorChecker Bean 'org.springframework.cloud.autoconfigure.ConfigurationPropertiesRebinderAutoConfiguration' of type [org.springframework.cloud.autoconfigure.ConfigurationPropertiesRebinderAutoConfiguration$$EnhancerBySpringCGLIB$$ec377eac] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying)
[demo1:8080] 2019-11-04 18:07:31.871 INFO 5976 [] [main] org.springframework.boot.web.embedded.tomcat.TomcatWebServer Tomcat initialized with port(s): 8080 (http)

当我加入spring cloud(Finchley.SR3)依赖后,同时加入了jasypt-spring-boot-starter(版本:1.18)问题来了:

[demo1:172.20.13.124:8080] 2019-11-04 19:00:13.217 INFO 17732 [] [main] com.ulisesbocchio.jasyptspringboot.EncryptablePropertySourceConverter Converting PropertySource configurationProperties [org.springframework.boot.context.properties.source.ConfigurationPropertySourcesPropertySource] to AOP Proxy
[demo1:172.20.13.124:8080] 2019-11-04 19:00:13.218 INFO 17732 [] [main] com.ulisesbocchio.jasyptspringboot.EncryptablePropertySourceConverter Converting PropertySource ApolloBootstrapPropertySources [org.springframework.core.env.CompositePropertySource] to EncryptableEnumerablePropertySourceWrapper
[demo1:172.20.13.124:8080] 2019-11-04 19:00:13.219 INFO 17732 [] [main] com.ulisesbocchio.jasyptspringboot.EncryptablePropertySourceConverter Converting PropertySource bootstrap [org.springframework.core.env.MapPropertySource] to EncryptableMapPropertySourceWrapper
[demo1:172.20.13.124:8080] 2019-11-04 19:00:13.219 INFO 17732 [] [main] com.ulisesbocchio.jasyptspringboot.EncryptablePropertySourceConverter Converting PropertySource systemProperties [org.springframework.core.env.MapPropertySource] to EncryptableMapPropertySourceWrapper
[demo1:172.20.13.124:8080] 2019-11-04 19:00:13.219 INFO 17732 [] [main] com.ulisesbocchio.jasyptspringboot.EncryptablePropertySourceConverter Converting PropertySource systemEnvironment [org.springframework.boot.env.SystemEnvironmentPropertySourceEnvironmentPostProcessor$OriginAwareSystemEnvironmentPropertySource] to EncryptableMapPropertySourceWrapper
[demo1:172.20.13.124:8080] 2019-11-04 19:00:13.219 INFO 17732 [] [main] com.ulisesbocchio.jasyptspringboot.EncryptablePropertySourceConverter Converting PropertySource random [org.springframework.boot.env.RandomValuePropertySource] to EncryptablePropertySourceWrapper
[demo1:172.20.13.124:8080] 2019-11-04 19:00:13.219 INFO 17732 [] [main] com.ulisesbocchio.jasyptspringboot.EncryptablePropertySourceConverter Converting PropertySource springCloudClientHostInfo [org.springframework.core.env.MapPropertySource] to EncryptableMapPropertySourceWrapper
[demo1:172.20.13.124:8080] 2019-11-04 19:00:13.219 INFO 17732 [] [main] com.ulisesbocchio.jasyptspringboot.EncryptablePropertySourceConverter Converting PropertySource applicationConfig: [classpath:/bootstrap.properties] [org.springframework.boot.env.OriginTrackedMapPropertySource] to EncryptableMapPropertySourceWrapper
[demo1:172.20.13.124:8080] 2019-11-04 19:00:13.232 INFO 17732 [] [main] org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor JSR-330 'javax.inject.Inject' annotation found and supported for autowiring
[demo1:172.20.13.124:8080] 2019-11-04 19:00:13.260 INFO 17732 [] [main] org.springframework.context.support.PostProcessorRegistrationDelegate$BeanPostProcessorChecker Bean 'configurationPropertiesRebinderAutoConfiguration' of type [org.springframework.cloud.autoconfigure.ConfigurationPropertiesRebinderAutoConfiguration$$EnhancerBySpringCGLIB$$2eddb6e0] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying)
[demo1:172.20.13.124:8080] 2019-11-04 19:00:13.328 INFO 17732 [] [main] com.ulisesbocchio.jasyptspringboot.resolver.DefaultLazyPropertyResolver Property Resolver custom Bean not found with name 'encryptablePropertyResolver'. Initializing Default Property Resolver
[demo1:172.20.13.124:8080] 2019-11-04 19:00:13.329 INFO 17732 [] [main] com.ulisesbocchio.jasyptspringboot.detector.DefaultLazyPropertyDetector Property Detector custom Bean not found with name 'encryptablePropertyDetector'. Initializing Default Property Detector
[APP_NAME_IS_UNDEFINED:172.20.13.124:0000] 2019-11-04 19:00:13.654 INFO 17732 [] [main] com.ulisesbocchio.jasyptspringboot.encryptor.DefaultLazyEncryptor String Encryptor custom Bean not found with name 'jasyptStringEncryptor'. Initializing Default String Encryptor
[APP_NAME_IS_UNDEFINED:172.20.13.124:0000] 2019-11-04 19:00:13.660 INFO 17732 [] [main] com.ulisesbocchio.jasyptspringboot.encryptor.DefaultLazyEncryptor Encryptor config not found for property jasypt.encryptor.keyObtentionIterations, using default value: 1000
[APP_NAME_IS_UNDEFINED:172.20.13.124:0000] 2019-11-04 19:00:13.660 INFO 17732 [] [main] com.ulisesbocchio.jasyptspringboot.encryptor.DefaultLazyEncryptor Encryptor config not found for property jasypt.encryptor.providerName, using default value: null
[APP_NAME_IS_UNDEFINED:172.20.13.124:0000] 2019-11-04 19:00:13.660 INFO 17732 [] [main] com.ulisesbocchio.jasyptspringboot.encryptor.DefaultLazyEncryptor Encryptor config not found for property jasypt.encryptor.providerClassName, using default value: null
[APP_NAME_IS_UNDEFINED:172.20.13.124:0000] 2019-11-04 19:00:13.660 INFO 17732 [] [main] com.ulisesbocchio.jasyptspringboot.encryptor.DefaultLazyEncryptor Encryptor config not found for property jasypt.encryptor.saltGeneratorClassname, using default value: org.jasypt.salt.RandomSaltGenerator
[APP_NAME_IS_UNDEFINED:172.20.13.124:0000] 2019-11-04 19:00:13.661 INFO 17732 [] [main] com.ulisesbocchio.jasyptspringboot.encryptor.DefaultLazyEncryptor Encryptor config not found for property jasypt.encryptor.stringOutputType, using default value: base64
[APP_NAME_IS_UNDEFINED:172.20.13.124:0000] 2019-11-04 19:00:16.714 INFO 17732 [] [main] com.ulisesbocchio.jasyptspringboot.configuration.EnableEncryptablePropertiesConfiguration Bootstraping jasypt-string-boot auto configuration in context: demo1-1
[APP_NAME_IS_UNDEFINED:172.20.13.124:0000] 2019-11-04 19:00:16.715 INFO 17732 [] [main] com.example.demo1.Demo1Application No active profile set, falling back to default profiles: default
[APP_NAME_IS_UNDEFINED:172.20.13.124:0000] 2019-11-04 19:00:16.727 INFO 17732 [] [main] org.springframework.boot.web.servlet.context.AnnotationConfigServletWebServerApplicationContext Refreshing org.springframework.boot.web.servlet.context.AnnotationConfigServletWebServerApplicationContext@362a019c: startup date [Mon Nov 04 19:00:16 CST 2019]; parent: org.springframework.context.annotation.AnnotationConfigApplicationContext@38ba6ce3
[APP_NAME_IS_UNDEFINED:172.20.13.124:0000] 2019-11-04 19:00:17.439 INFO 17732 [] [main] org.springframework.cloud.context.scope.GenericScope BeanFactory id=1b490803-88ca-36b5-9885-e312ed5e9a70
[APP_NAME_IS_UNDEFINED:172.20.13.124:0000] 2019-11-04 19:00:17.461 INFO 17732 [] [main] com.ulisesbocchio.jasyptspringboot.configuration.EnableEncryptablePropertiesBeanFactoryPostProcessor Post-processing PropertySource instances
......省略
nobodyiam commented 5 years ago

能否控制下变量,看看具体是哪个依赖引入引起的?

mark0614 commented 5 years ago

能否控制下变量,看看具体是哪个依赖引入引起的?

加入这个依赖后,就会变成这个样子
<dependency>
            <groupId>com.github.ulisesbocchio</groupId>
            <artifactId>jasypt-spring-boot-starter</artifactId>
            <version>1.18</version>
        </dependency>
mark0614 commented 5 years ago

能否控制下变量,看看具体是哪个依赖引入引起的?

加入这个依赖后,就会变成这个样子
<dependency>
            <groupId>com.github.ulisesbocchio</groupId>
            <artifactId>jasypt-spring-boot-starter</artifactId>
            <version>1.18</version>
        </dependency>

我将1.18降到1.16就没有这个问题了。亲测

nobodyiam commented 5 years ago

see #2162 #2170

stale[bot] commented 4 years ago

This issue has been automatically marked as stale because it has not had activity in the last 90 days. It will be closed in 14 days unless it is tagged "help wanted" or other activity occurs. Thank you for your contributions.

stale[bot] commented 4 years ago

This issue has been automatically closed because it has not had activity in the last 14 days. If this issue is still valid, please ping a maintainer and ask them to label it as "help wanted". Thank you for your contributions.