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

io.github.wycst.wast.log.LogFactory Maven / Gradle / Ivy

Go to download

Wast is a high-performance Java toolset library package that includes JSON, YAML, CSV, HttpClient, JDBC and EL engines

There is a newer version: 0.0.16
Show newest version
package io.github.wycst.wast.log;

import java.util.List;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
import java.util.logging.Handler;
import java.util.logging.Level;

/**
 * @Author: wangy
 * @Date: 2020/5/5 15:46
 * @Description:
 */
public class LogFactory {

    private static Map, Log> loggers = new ConcurrentHashMap, Log>();
    public static final String LOG_ON_CONSOLE = "java.util.logging.console";
    private static Map fileHandlerHolders = new ConcurrentHashMap();

    static {
        LoggerManagerHandler.init();
    }

    // 重置所有的日志对象
    void reset() {
    }

    public static Log getLog(Class logCls) {
        synchronized (logCls) {
            Log log = loggers.get(logCls);
            if (log == null) {
                log = new Log(logCls);
                List handlers = LoggerManagerHandler.matchHandlers(logCls);
                Level level = LoggerManagerHandler.matchLevel(logCls);
                if (level != null) {
                    log.setLevel(level);
                }
                for (Handler handler : handlers) {
                    log.addHandler(handler);
                }
                loggers.put(logCls, log);
            }
            return log;
        }
    }

    public static void setConsoleLevel(String consoleLevel) {
        Level levelValue = Level.parse(consoleLevel);
        LoggerManagerHandler.setConsoleLevel(levelValue);
    }

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy