Nacos logs do not print to nacos
logs file but print into users' application logs.
#4567
Labels
area/Client
Related to Nacos Client SDK
area/Spring Boot
Related to Spring Boot
area/Spring Cloud
Related to Spring Cloud
kind/refactor
Milestone
Describe the bug
When nacos-client run with Spring Cloud Alibaba. almost of nacos log will print into applications' log file but not into nacos log file we expected, which will make users confused because nacos client has async-thread to execute and print result in logs.
Expected behavior
Almost nacos-client logs should print into ${user.home}/logs/nacos/naming.log or ${user.home}/logs/nacos/config.log
Acutally behavior
Print into users' application business logs file.
How to Reproduce
Steps to reproduce the behavior:
nacos-config-example
ornacos-discovery-spring-cloud-config-client-example
com.alibaba.nacos.client.config.XXX
log info orcom.alibaba.nacos.client.naming.XXX
log infoDesktop (please complete the following information):
Additional context
After researching, the reason is that spring will fire mutilple times
ApplicationEnvironmentPreparedEvent
event during init.And each event will cause LogSystem clean and reload log configuration, Detail See
AbstractLoggingSystem
and its implementations likeLogbackLoggingSystem
orLog4j2LoggingSystem
.And nacos-client also will append its configuration into LogContext, But only once. If appending configuration after all event fired, It will work well. But if appending between two events, the nacos log configuration will be cleaned. So the log will print into users log file.
I think we should refactor the codes about nacos log load first. And then we should do changes in spring-boot-nacos and spring-cloud-alibaba-nacos to listener the
ApplicationEnvironmentPreparedEvent
and reload nacos log configuration.Because nacos log config load should be a part of
ApplicationEnvironmentPrepared
.But we should pay attention to the order, nacos log reload need after
LoggingSystem
reload.The text was updated successfully, but these errors were encountered: