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

io.github.linyimin0812.profiler.common.logger.LogFactory Maven / Gradle / Ivy

There is a newer version: 3.1.4
Show newest version
package io.github.linyimin0812.profiler.common.logger;

import io.github.linyimin0812.profiler.common.utils.AgentHomeUtil;

import java.io.File;
import java.util.HashMap;
import java.util.Map;

/**
 * @author linyimin
 **/
public class LogFactory {
    private final static Map LOGGER_MAP = new HashMap<>();

    static {
        createLogger(LoggerName.STARTUP);
        createLogger(LoggerName.TRANSFORM);

        String asyncInitBeanLogPath = System.getProperty("user.home") + File.separator + "spring-startup-analyzer" + File.separator + "logs" + File.separator;
        createLogger(LoggerName.ASYNC_INIT_BEAN, asyncInitBeanLogPath);
    }

    public static Logger getStartupLogger() {
        return LOGGER_MAP.get(LoggerName.STARTUP);
    }

    public static Logger getTransFormLogger() {
        return LOGGER_MAP.get(LoggerName.TRANSFORM);
    }

    public static Logger getAsyncBeanLogger() {
        return LOGGER_MAP.get(LoggerName.ASYNC_INIT_BEAN);
    }

    public static void close() {
        for (Logger logger : LOGGER_MAP.values()) {
            logger.close();
        }
    }

    public static void createLogger(LoggerName loggerName, String path) {
        Logger logger = new Logger(loggerName, path);
        LOGGER_MAP.put(loggerName, logger);
    }

    private static void createLogger(LoggerName loggerName) {
        createLogger(loggerName, AgentHomeUtil.home() + "logs");
    }

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy