
commons.box.util.Logs Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of commons-box-app Show documentation
Show all versions of commons-box-app Show documentation
Common utils for BOX projects.
The newest version!
package commons.box.util;
import commons.box.app.AppLog;
import commons.box.app.AppLogFactory;
import commons.box.app.SafeRefMap;
import commons.box.app.internal.InternalAppLogFactoryByJDK;
import commons.box.app.internal.InternalServiceLoaders;
import java.util.Map;
/**
* 通用日志工具 获取日志必须通过此工具类获取 工具类会缓存已知LOG
*
*
* 本工具类使用了 Slf4j
*
* compile("org.slf4j:slf4j-api:${version_slf4j}")
* 默认LOG实现
* compile("ch.qos.logback:logback-classic:${version_logback}")
* compile("junit:junit:${version_junit}")
*
*
*
创建作者:xingxiuyi
* 版权所属:xingxiuyi
*/
public final class Logs {
private static final Map CACHE = new SafeRefMap<>();
private static final AppLogFactory FACTORY = InternalServiceLoaders.loadService(AppLogFactory.class, new InternalAppLogFactoryByJDK());
private static final AppLog EMPTY = FACTORY.get(null);
private Logs() {
}
public static AppLog get(Class> cls) {
if (FACTORY == null || cls == null) return EMPTY;
return get(cls.getName());
}
public static AppLog get(String name) {
if (FACTORY == null || Strs.isEmpty(name)) return EMPTY;
AppLog log = CACHE.get(name);
if (log == null) {
log = FACTORY.get(name);
if (log == null) log = EMPTY;
CACHE.put(name, log);
}
return log;
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy