Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Nacos logs do not print to nacos logs file but print into users' application logs. #4567

Closed
KomachiSion opened this issue Dec 24, 2020 · 3 comments · Fixed by #4572
Closed
Assignees
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

Comments

@KomachiSion
Copy link
Collaborator

KomachiSion commented Dec 24, 2020

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:

  1. Clone Spring cloud alibaba source code
  2. Run with example nacos-config-example or nacos-discovery-spring-cloud-config-client-example
  3. see ${user.home}/logs/nacos/naming.log or ${user.home}/logs/nacos/config.log, no logs or only little logs
  4. See console, there are com.alibaba.nacos.client.config.XXX log info or com.alibaba.nacos.client.naming.XXX log info

Desktop (please complete the following information):

  • OS: All
  • Version All
  • Module naming and config
  • SDK spring-cloud-alibaba-nacos

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 like LogbackLoggingSystem or Log4j2LoggingSystem.

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.

@KomachiSion KomachiSion added kind/refactor area/Client Related to Nacos Client SDK area/Spring Boot Related to Spring Boot area/Spring Cloud Related to Spring Cloud labels Dec 24, 2020
@KomachiSion KomachiSion added this to the 1.4.1 milestone Dec 24, 2020
@KomachiSion
Copy link
Collaborator Author

KomachiSion commented Dec 25, 2020

Issue Detai:

Troubleshooting

For normal startup and init

image

For trouble, problematic loading sequence and steps

image

Solution

Plan A

Do nothing in nacos-client, only Add listener for ContextRefreshedEvent and reload configuration

image

Advantage:

Easy to Implementation

Disadvantage:

Some logs during Init may also print into business log.

Plan B

Listen properties changes event of log framework like logback and log4j2

logback `LoggerContextListener` 
log4j2 `PropertyChangeListener` 

image

Advantage:

Whatever application framework user use. Only changes nacos-client.

Disadvantage:

Depend on log framework. If log has no event or listener extension. This plan can't works.

Plan C

Listen same spring events with Spring log system. And do reload after spring log system load finished.

image

Advantage:

Full meet the spring event meanings.

Disadvantage:

We need do changes all in nacos-client, nacos-spring-context, nacos-spring-boot and SCA-nacos.

@KomachiSion
Copy link
Collaborator Author

KomachiSion commented Dec 25, 2020

For now, We think Plan C is best. nacos-client need to do refactor to support API of reload log configurations.

@Maijh97
Copy link
Collaborator

Maijh97 commented Dec 25, 2020

@i will solve it@

@Maijh97 Maijh97 self-assigned this Dec 25, 2020
KomachiSion pushed a commit that referenced this issue Dec 26, 2020
…4572)

* for #4567, refactor nacos-client logging load Configuration code.

* Modify exception handling.

* When customizing AbstractNacosLogging Load Configuration Fail, use the default Logging Load Configuration.

* NacosLogging has been modified to a single-column mode.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/Client Related to Nacos Client SDK area/Spring Boot Related to Spring Boot area/Spring Cloud Related to Spring Cloud kind/refactor
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants