com.alipay.sofa.common.log.factory.LogbackLoggerSpaceFactory Maven / Gradle / Ivy
The newest version!
/*
* 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.common.log.factory;
import ch.qos.logback.classic.Level;
import ch.qos.logback.classic.LoggerContext;
import ch.qos.logback.classic.encoder.PatternLayoutEncoder;
import ch.qos.logback.classic.filter.ThresholdFilter;
import ch.qos.logback.classic.joran.JoranConfigurator;
import ch.qos.logback.classic.spi.ILoggingEvent;
import ch.qos.logback.classic.turbo.TurboFilter;
import ch.qos.logback.classic.util.ContextInitializer;
import ch.qos.logback.core.ConsoleAppender;
import ch.qos.logback.core.LogbackException;
import ch.qos.logback.core.joran.spi.JoranException;
import ch.qos.logback.core.spi.FilterReply;
import ch.qos.logback.core.spi.ScanException;
import ch.qos.logback.core.util.OptionHelper;
import com.alipay.sofa.common.log.CommonLoggingConfigurations;
import com.alipay.sofa.common.log.Constants;
import com.alipay.sofa.common.log.adapter.level.AdapterLevel;
import com.alipay.sofa.common.space.SpaceId;
import com.alipay.sofa.common.utils.StringUtil;
import org.slf4j.Logger;
import org.slf4j.MDC;
import org.slf4j.Marker;
import org.slf4j.spi.MDCAdapter;
import java.lang.reflect.Method;
import java.net.URL;
import java.util.Map;
import java.util.Properties;
/**
* @author qilong.zql
* @since 1.0.15
*/
public class LogbackLoggerSpaceFactory extends AbstractLoggerSpaceFactory {
private static final Method logContextSetMDCAdapterMethod;
private final SpaceId spaceId;
private final LoggerContext loggerContext;
private final Properties properties;
private ConsoleAppender consoleAppender;
static {
// Resolve logContext#setMDCAdapter method if logback version >= 1.4.8
Method logContextSetMDCAdapter;
try {
logContextSetMDCAdapter = LoggerContext.class.getDeclaredMethod("setMDCAdapter",
MDCAdapter.class);
} catch (Throwable t) {
logContextSetMDCAdapter = null;
}
logContextSetMDCAdapterMethod = logContextSetMDCAdapter;
}
public LogbackLoggerSpaceFactory(SpaceId spaceId, LoggerContext loggerContext,
Properties properties, URL confFile, String source) {
super(source);
this.spaceId = spaceId;
this.loggerContext = loggerContext;
this.properties = properties;
for (Map.Entry
© 2015 - 2025 Weber Informatics LLC | Privacy Policy