- environment
- SpringBoot:2.6.8
- SpringCloud:2021.0.2
- SpringCloudAlibaba:2021.0.1.0
- nacos:2.1.0
- important step
pom.xmladd dependencyspring-boot-starter-actuator- modify the configuration
- Add the following configuration to
bootstrap.ymlorapplication.ymlyaml logging: file: name: ./log/a.log - Add the following configuration in the
nacosconfiguration centeryaml management: endpoints: web: exposure: include: "logfile" # enable log endpoint logging: file: name: ./log/b.log
- Add the following configuration to
- start server
- Open the
logfolder, Contains two filesa.logandb.log, Logs are refreshed inb.log - issue
- Browser open url
http://[ip]:[port]/actuator/logfile,Only the file content ofa.logis displayed - If
logging.file.nameis not configured inbootstrap.ymlorapplication.yml, A404error code is displayed when visit the url
Comment From: wilkinsona
Thanks for the report but it's hard to say what is causing the problem based on a description alone. Spring Boot will auto-configured the LogFileWebEndpoint only once and it will use the logging.file.name configuration that's available at that time. There is no support in Spring Boot itself for changing this configuration later on.
If the intention is for the logging.file.name from Nacos to be available at startup, I would guess it's becoming available too late and is being missed.
If the intention is for the change to logging.file.name to be picked up later on, I would guess that the use of refresh and Cloud's refresh scope hasn't been done correctly.
If you would like us to spend some more time investigating, please spend some time providing a complete yet minimal sample that reproduces the problem. You can share it with us by pushing it to a separate repository on GitHub or by zipping it up and attaching it to this issue.
Comment From: Max-Qiu
a complete yet minimal sample, include documentation
https://github.com/Max-Qiu/test-logfile
Comment From: wilkinsona
Thank you. As I suspected, the configuration of logging.file.name from nacos is becoming available after the LogFile bean has been injected into LogFileWebEndpoint. As a result, it isn't used by the endpoint. This looks to be very similar to this problem with Spring Cloud Config which was closed as feedback was not provided.
There's nothing that we can do about this in Spring Boot as it is Spring Cloud that is responsible for the reinitialization of logging. You may be able to work around the problem by declaring your own LogFileWebEndpoint bean using @RefreshScope but, ideally, this would be something that Spring Cloud handles for you. I'm not sure if that should be done in Spring Cloud Commons or in the Nacos starter. @spencergibb may be able to offer some guidance.
Comment From: spencergibb
It's not a current feature to do anything with LogFileWebEndpoint. You're welcome to open an enhancement request in spring cloud commons and we can gauge interest there.