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

Refactor using of sofa-common-tools and support for console logging #760

Merged
merged 15 commits into from
Nov 9, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.alipay.sofa.boot.logging;

import com.alipay.sofa.common.log.Constants;
import com.alipay.sofa.common.log.env.LogEnvUtils;
import com.alipay.sofa.common.utils.StringUtil;
import org.springframework.boot.context.event.ApplicationEnvironmentPreparedEvent;
import org.springframework.context.ApplicationListener;
import org.springframework.core.Ordered;
import org.springframework.core.env.ConfigurableEnvironment;
import org.springframework.core.env.EnumerablePropertySource;
import org.springframework.core.env.PropertySource;

/**
* @author <a href="mailto:guaner.zzx@alipay.com">Alaneuler</a>
* Created on 2020/11/7
*/
public class LogEnvironmentPreparingListener
implements
ApplicationListener<ApplicationEnvironmentPreparedEvent>,
Ordered {
@Override
public void onApplicationEvent(ApplicationEnvironmentPreparedEvent event) {
prepare(event.getEnvironment());
}

@Override
public int getOrder() {
return Ordered.HIGHEST_PRECEDENCE + 100;
}

private void prepare(ConfigurableEnvironment environment) {
loadLogConfiguration(Constants.LOG_PATH, environment.getProperty(Constants.LOG_PATH));
loadLogConfiguration(Constants.OLD_LOG_PATH,
environment.getProperty(Constants.OLD_LOG_PATH));
loadLogConfiguration(Constants.LOG_ENCODING_PROP_KEY,
environment.getProperty(Constants.LOG_ENCODING_PROP_KEY));

for (PropertySource<?> propertySource : environment.getPropertySources()) {
if (propertySource instanceof EnumerablePropertySource) {
for (String key : ((EnumerablePropertySource) propertySource).getPropertyNames()) {
if (LogEnvUtils.filterAllLogConfig(key)) {
loadLogConfiguration(key, environment.getProperty(key));
}
}
}
}
}

private void loadLogConfiguration(String key, String value) {
if (!System.getProperties().contains(key) && !System.getenv().containsKey(key)
&& StringUtil.isNotEmpty(value)) {
System.setProperty(key, value);
}
}
}

This file was deleted.

This file was deleted.

Loading