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

解决日志系统未初始化完成时,apollo 的加载日志没法输出问题 #3677

Merged
merged 29 commits into from
May 23, 2021
Merged
Show file tree
Hide file tree
Changes from 20 commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
fe75b4d
add tech-support-qq-4.png
klboke May 16, 2019
99bf97a
Update README.md
klboke May 16, 2019
1579f41
Merge remote-tracking branch 'upstream/master'
klboke Nov 11, 2020
9f65eed
Merge remote-tracking branch 'upstream/master'
klboke Dec 9, 2020
d7d3fd9
Enhance the user experience in the scenario of submitting duplicate keys
klboke Dec 11, 2020
7329fab
Merge branch 'master' into master
nobodyiam Dec 12, 2020
5def448
Modify the key-value conflict exception prompt, adjust the code style
klboke Dec 12, 2020
6942564
Merge branch 'master' into master
nobodyiam Dec 12, 2020
0fc1f91
Merge remote-tracking branch 'upstream/master'
klboke Dec 19, 2020
61ad016
Merge remote-tracking branch 'origin/master'
klboke Dec 19, 2020
587ce33
rge remote-tracking branch 'upstream/master'
klboke Mar 1, 2021
9de6563
Merge remote-tracking branch 'upstream/master'
klboke Mar 8, 2021
9aab632
Merge remote-tracking branch 'upstream/master'
klboke Mar 25, 2021
050dd0a
Merge branch 'ctripcorp:master' into master
klboke May 10, 2021
5a64035
Merge branch 'master' of github.com:klboke/apollo
klboke May 10, 2021
d053f4a
feat[apollo-client]: Solve the problem that the log before the log sy…
klboke May 11, 2021
41acba5
Merge branch 'master' into DeferredLog
nobodyiam May 15, 2021
b1ce641
refactor(DeferredLog): Delay log refactoring
klboke May 19, 2021
6357c8f
Merge remote-tracking branch 'origin/DeferredLog' into DeferredLog
klboke May 19, 2021
93560e8
fix(DeferredLog): Fix log level definition error
klboke May 19, 2021
072c58a
feat(DeferredLog): Complete test cases
klboke May 20, 2021
ea37efc
fix(DeferredLog): Fix problems with test cases
klboke May 21, 2021
65c7714
refactor(DeferredLog): Remove useless packages
klboke May 21, 2021
f47fc44
refactor(DeferredLog): DeferredLogCache only stores logs
klboke May 21, 2021
2c4fde5
refactor(DeferredLog): AbstractConfigFile adds delay log
klboke May 21, 2021
2532a7f
refactor(DeferredLog): Improve delayed log implementation
klboke May 21, 2021
6ea77e5
Merge branch 'master' into DeferredLog
nobodyiam May 21, 2021
ee2339c
fix(DeferredLog): Fix the problem of test case compilation failure, a…
klboke May 21, 2021
4eecb14
refactor(DeferredLog): DeferredLogCache method reconstruction
klboke May 23, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.ctrip.framework.apollo.internals;

import com.ctrip.framework.apollo.core.utils.DeferredLogFactory;
import com.ctrip.framework.apollo.enums.ConfigSourceType;
import java.io.IOException;
import java.io.InputStream;
Expand All @@ -13,7 +14,6 @@
import java.util.concurrent.atomic.AtomicReference;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.ctrip.framework.apollo.core.utils.ClassLoaderUtil;
import com.ctrip.framework.apollo.enums.PropertyChangeType;
Expand All @@ -29,7 +29,7 @@
* @author Jason Song([email protected])
*/
public class DefaultConfig extends AbstractConfig implements RepositoryChangeListener {
private static final Logger logger = LoggerFactory.getLogger(DefaultConfig.class);
private static final Logger logger = DeferredLogFactory.getLogger(DefaultConfig.class);
private final String m_namespace;
private final Properties m_resourceProperties;
private final AtomicReference<Properties> m_configProperties;
Expand Down Expand Up @@ -59,7 +59,7 @@ private void initialize() {
} catch (Throwable ex) {
Tracer.logError(ex);
logger.warn("Init Apollo Local Config failed - namespace: {}, reason: {}.",
m_namespace, ExceptionUtil.getDetailMessage(ex));
m_namespace, ExceptionUtil.getDetailMessage(ex));
klboke marked this conversation as resolved.
Show resolved Hide resolved
} finally {
//register the change listener no matter config repository is working or not
//so that whenever config repository is recovered, config could get changed
Expand Down Expand Up @@ -154,12 +154,12 @@ private void updateConfig(Properties newConfigProperties, ConfigSourceType sourc
}

private Map<String, ConfigChange> updateAndCalcConfigChanges(Properties newConfigProperties,
ConfigSourceType sourceType) {
ConfigSourceType sourceType) {
List<ConfigChange> configChanges =
calcPropertyChanges(m_namespace, m_configProperties.get(), newConfigProperties);
calcPropertyChanges(m_namespace, m_configProperties.get(), newConfigProperties);

ImmutableMap.Builder<String, ConfigChange> actualChanges =
new ImmutableMap.Builder<>();
new ImmutableMap.Builder<>();

/** === Double check since DefaultConfig has multiple config sources ==== **/

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,15 @@
import com.ctrip.framework.apollo.core.ConfigConsts;
import com.ctrip.framework.apollo.core.enums.Env;
import com.ctrip.framework.apollo.core.spi.MetaServerProvider;
import com.ctrip.framework.apollo.core.utils.DeferredLogFactory;
import com.ctrip.framework.foundation.Foundation;
import com.google.common.base.Strings;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public class DefaultMetaServerProvider implements MetaServerProvider {

public static final int ORDER = 0;
private static final Logger logger = LoggerFactory.getLogger(DefaultMetaServerProvider.class);
private static final Logger logger = DeferredLogFactory.getLogger(DefaultMetaServerProvider.class);

private final String metaServerAddress;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import com.ctrip.framework.apollo.Config;
import com.ctrip.framework.apollo.ConfigService;
import com.ctrip.framework.apollo.core.ConfigConsts;
import com.ctrip.framework.apollo.core.utils.DeferredLogCache;
import com.ctrip.framework.apollo.spring.config.ConfigPropertySourceFactory;
import com.ctrip.framework.apollo.spring.config.PropertySourcesConstants;
import com.ctrip.framework.apollo.spring.util.SpringInjector;
Expand Down Expand Up @@ -91,7 +92,8 @@ public void initialize(ConfigurableApplicationContext context) {
protected void initialize(ConfigurableEnvironment environment) {

if (environment.getPropertySources().contains(PropertySourcesConstants.APOLLO_BOOTSTRAP_PROPERTY_SOURCE_NAME)) {
//already initialized
//already initialized , replay the logs that were printed before the logging system was initialized
klboke marked this conversation as resolved.
Show resolved Hide resolved
DeferredLogCache.replayTo();
return;
}

Expand Down Expand Up @@ -160,6 +162,7 @@ public void postProcessEnvironment(ConfigurableEnvironment configurableEnvironme
Boolean bootstrapEnabled = configurableEnvironment.getProperty(PropertySourcesConstants.APOLLO_BOOTSTRAP_ENABLED, Boolean.class, false);

if (bootstrapEnabled) {
DeferredLogCache.enableDeferredLog();
initialize(configurableEnvironment);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicBoolean;

import com.ctrip.framework.apollo.core.utils.DeferredLogFactory;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.ctrip.framework.apollo.core.spi.MetaServerProvider;
import com.ctrip.framework.apollo.core.utils.ApolloThreadFactory;
Expand Down Expand Up @@ -46,7 +46,7 @@ public class MetaDomainConsts {
private static volatile List<MetaServerProvider> metaServerProviders = null;

private static final long REFRESH_INTERVAL_IN_SECOND = 60;// 1 min
private static final Logger logger = LoggerFactory.getLogger(MetaDomainConsts.class);
private static final Logger logger = DeferredLogFactory.getLogger(MetaDomainConsts.class);
// comma separated meta server address -> selected single meta server address cache
private static final Map<String, String> selectedMetaServerAddressCache = Maps.newConcurrentMap();
private static final AtomicBoolean periodicRefreshStarted = new AtomicBoolean(false);
Expand Down Expand Up @@ -91,7 +91,7 @@ private static void initMetaServerAddress(Env env) {
metaAddress = provider.getMetaServerAddress(env);
if (!Strings.isNullOrEmpty(metaAddress)) {
logger.info("Located meta server address {} for env {} from {}", metaAddress, env,
provider.getClass().getName());
provider.getClass().getName());
break;
}
}
Expand All @@ -100,8 +100,8 @@ private static void initMetaServerAddress(Env env) {
// Fallback to default meta address
metaAddress = DEFAULT_META_URL;
logger.warn(
"Meta server address fallback to {} for env {}, because it is not available in all MetaServerProviders",
metaAddress, env);
"Meta server address fallback to {} for env {}, because it is not available in all MetaServerProviders",
metaAddress, env);
}

metaServerAddressCache.put(env, metaAddress.trim());
Expand Down Expand Up @@ -178,7 +178,7 @@ private static void updateMetaServerAddresses(String metaServerAddresses) {

if (!serverAvailable) {
logger.warn("Could not find available meta server for configured meta server addresses: {}, fallback to: {}",
metaServerAddresses, selectedMetaServerAddressCache.get(metaServerAddresses));
metaServerAddresses, selectedMetaServerAddressCache.get(metaServerAddresses));
}

transaction.setStatus(Transaction.SUCCESS);
Expand All @@ -192,7 +192,7 @@ private static void updateMetaServerAddresses(String metaServerAddresses) {

private static void schedulePeriodicRefresh() {
ScheduledExecutorService scheduledExecutorService =
Executors.newScheduledThreadPool(1, ApolloThreadFactory.create("MetaServiceLocator", true));
Executors.newScheduledThreadPool(1, ApolloThreadFactory.create("MetaServiceLocator", true));

scheduledExecutorService.scheduleAtFixedRate(new Runnable() {
@Override
Expand All @@ -203,7 +203,7 @@ public void run() {
}
} catch (Throwable ex) {
logger.warn(String.format("Refreshing meta server address failed, will retry in %d seconds",
REFRESH_INTERVAL_IN_SECOND), ex);
REFRESH_INTERVAL_IN_SECOND), ex);
}
}
}, REFRESH_INTERVAL_IN_SECOND, REFRESH_INTERVAL_IN_SECOND, TimeUnit.SECONDS);
Expand Down
Loading