spring-cloud-config icon indicating copy to clipboard operation
spring-cloud-config copied to clipboard

Spring cloud config server on refresh -> logback config also refresh automatically

Open fuzzy28 opened this issue 4 years ago • 11 comments

I can't find any existing article/documentation related to this. The spring cloud config server and logback XML configuration are working in harmony, whenever I change something in my git repo config and trigger refresh of my application, somehow the logback automatically gets updated even though the logback is not in the config server but in the jar file itself.

Basically, my configuration is something like this:

I have an SMTP appender in my logback XML, at startup I'm checking if the enableSMTP is enabled, then I only set the recipient.

<if condition='property("smtpEnabled").equals("true")'>
    <then>
        <to>[email protected]</to>
    </then>
</if>

This is to prevent email sending if the property is disabled, then I'm setting it back programmatically, ideally in EnvironmentChangeEvent. However, changing the property in the config server and calling the /monitor endpoint from the spring cloud config server automatically sets this value in logback without programmatically setting it through the event handler.

Is this behavior of environment change and auto reconfigure of logback expected? (note that logback scan is disabled)

fuzzy28 avatar Oct 26 '21 04:10 fuzzy28

So is the event handler not called? Logging is reinitialized when a refresh event is received.

ryanjbaxter avatar Oct 26 '21 13:10 ryanjbaxter

@ryanjbaxter The event handler is invoked, initially my implementation was using this to listen for the property change and then I reconfigure the logback appended property programmatically. To my surprise, I don't need to do it anymore since logging is indeed reinitialized after the invocation of /refresh from the spring cloud server. But still, I don't see any related discussion about this, was this discussed somewhere in the docs?

fuzzy28 avatar Oct 26 '21 15:10 fuzzy28

Are you upgrading from a previous version of Spring Cloud that caused a change in behavior?

ryanjbaxter avatar Oct 26 '21 15:10 ryanjbaxter

@ryanjbaxter no I am not, we are using Finchley.RELEASE from the beginning, I just don't know that this feature exists.

fuzzy28 avatar Oct 27 '21 00:10 fuzzy28

To my surprise, I don't need to do it anymore

So you are saying this is a chance in behavior from Finchley.RELEASE?

What release are you trying now?

ryanjbaxter avatar Oct 27 '21 15:10 ryanjbaxter

@ryanjbaxter I'm not exploring any other release version if I understand you correctly.

So you are saying this is a chance in behavior from Finchley.RELEASE?

Yes, is this really expected? any documentation can I refer to this behavior?

fuzzy28 avatar Oct 27 '21 15:10 fuzzy28

I am really lost on how the behavior changed if you did not change the Spring Cloud version. Maybe I am not understanding you. I can't point you to any kind of documentation because I am not understanding how the behavior could change.

ryanjbaxter avatar Oct 27 '21 16:10 ryanjbaxter

@ryanjbaxter sorry for my mistake, what I mean is, I've been using Finchley.RELEASE spring cloud version from the start of the project, I didn't try any other release version aside from this.

From the beginning, I didn't know that when you call /refresh will also refresh the logback cause I haven't seen this in any article or documentation. If this is expected behavior, then could you please refer me to the documentation or the code to where this reload of logback is located.

fuzzy28 avatar Oct 27 '21 16:10 fuzzy28

Refresh events will restart the application context so logging will be reinitialized I believe

ryanjbaxter avatar Oct 27 '21 16:10 ryanjbaxter

@ryanjbaxter any document related to this that you may share?

fuzzy28 avatar Oct 28 '21 11:10 fuzzy28

I think the most relevant documentation might be here https://docs.spring.io/spring-cloud-commons/docs/current/reference/html/#environment-changes

ryanjbaxter avatar Oct 28 '21 15:10 ryanjbaxter

If you would like us to look at this issue, please provide the requested information. If the information is not provided within the next 7 days this issue will be closed.

spring-cloud-issues avatar May 16 '23 00:05 spring-cloud-issues

Closing due to lack of requested feedback. If you would like us to look at this issue, please provide the requested information and we will re-open the issue.

spring-cloud-issues avatar May 23 '23 00:05 spring-cloud-issues