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

com.zusmart.basic.logging.LoggerFactory Maven / Gradle / Ivy

Go to download

基础模块,提供配置,日志,SPI,图排序,路径匹配,资源扫描,包扫描,常用工具类

There is a newer version: 0.0.3
Show newest version
package com.zusmart.basic.logging;

import com.zusmart.basic.logging.support.JdkLoggerFactory;
import com.zusmart.basic.logging.support.Log4j2LoggerFactory;
import com.zusmart.basic.logging.support.Log4jLoggerFactory;
import com.zusmart.basic.logging.support.Slf4jLoggerFactory;

public abstract class LoggerFactory {

	private static volatile LoggerFactory defaultLoggerFactory;

	private static LoggerFactory createDefaultLoggerFactory(String name) {
		LoggerFactory loggerFactory;
		try {
			loggerFactory = new Slf4jLoggerFactory();
			loggerFactory.newInstance(name).debug("Using SLF4J as the default logging framework");
		} catch (Throwable e) {
			try {
				loggerFactory = new Log4jLoggerFactory();
				loggerFactory.newInstance(name).debug("Using Log4J as the default logging framework");
			} catch (Throwable ee) {
				try {
					loggerFactory = new Log4j2LoggerFactory();
					loggerFactory.newInstance(name).debug("Using Log4J2 as the default logging framework");
				} catch (Throwable eee) {
					loggerFactory = new JdkLoggerFactory();
					loggerFactory.newInstance(name).debug("Using java.util.logging as the default logging framework");
				}
			}
		}
		return loggerFactory;
	}

	public static LoggerFactory getDefaultLoggerFactory() {
		if (null == defaultLoggerFactory) {
			defaultLoggerFactory = createDefaultLoggerFactory(LoggerFactory.class.getName());
		}
		return defaultLoggerFactory;
	}

	public static void setDefaultLoggerFactory(LoggerFactory defaultLoggerFactory) {
		if (null == defaultLoggerFactory) {
			throw new NullPointerException("defaultLoggerFactory");
		}
		LoggerFactory.defaultLoggerFactory = defaultLoggerFactory;
	}

	public static Logger getLogger(Class classType) {
		return getLogger(classType.getName());
	}

	public static Logger getLogger(String name) {
		return getDefaultLoggerFactory().newInstance(name);
	}

	protected abstract Logger newInstance(String name);

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy