All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.nxyfan.framework.common.pojo.CommonAsyncAppender Maven / Gradle / Ivy

package com.nxyfan.framework.common.pojo;

import ch.qos.logback.classic.AsyncAppender;
import ch.qos.logback.classic.spi.ILoggingEvent;
import ch.qos.logback.classic.spi.LoggingEvent;
import cn.hutool.core.util.StrUtil;

/** 
 *
 * Describe: 通用Logback的异步日志增强appender类
 * Author: Administrator  
 * Create Time: 2024年5月31日 下午2:49:06 
 * Copyright @ 2024 51LIFE  
 */
public class CommonAsyncAppender  extends AsyncAppender {

	// 本系统的日志名称
	private String appName;
	// 自定义的日志名称
	private String customName;
    
	@Override
    protected void append(ILoggingEvent eventObject) {
        if(eventObject instanceof LoggingEvent){
            LoggingEvent loggingEvent = (LoggingEvent)eventObject;
            if(!StrUtil.contains(customName, loggingEvent.getLoggerName())) {
            	loggingEvent.setLoggerName(appName);
            }
            eventObject = loggingEvent;
        }
        super.append(eventObject);
    }
	
	public void setAppName(String appName) {
        this.appName = appName;
    }

	public void setCustomName(String customName) {
		this.customName = customName;
	}
	
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy