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

com.aizuda.easy.retry.common.log.dialect.jdk.JdkLogFactory Maven / Gradle / Ivy

package com.aizuda.easy.retry.common.log.dialect.jdk;


import cn.hutool.core.io.IoUtil;
import cn.hutool.core.io.resource.ResourceUtil;
import cn.hutool.core.lang.Console;
import com.aizuda.easy.retry.common.log.dialect.Log;
import com.aizuda.easy.retry.common.log.factory.LogFactory;

import java.io.InputStream;
import java.util.logging.LogManager;

/**
 * JDK日志工厂类
 * java.util.logging log.
 *
 * @author wodeyangzipingpingwuqi
 */
public class JdkLogFactory extends LogFactory {

    public JdkLogFactory() {
        super("JDK Logging");
        readConfig();
    }

    @Override
    public Log createLog(String name) {
        return new com.aizuda.easy.retry.common.log.dialect.jdk.JdkLog(name);
    }

    @Override
    public Log createLog(Class clazz) {
        return new com.aizuda.easy.retry.common.log.dialect.jdk.JdkLog(clazz);
    }

    /**
     * 读取ClassPath下的logging.properties配置文件
     */
    private void readConfig() {
        //避免循环引用,Log初始化的时候不使用相关工具类
        InputStream in = ResourceUtil.getStreamSafe("logging.properties");
        if (null == in) {
            System.err.println("[WARN] Can not find [logging.properties], use [%JRE_HOME%/lib/logging.properties] as default!");
            return;
        }

        try {
            LogManager.getLogManager().readConfiguration(in);
        } catch (Exception e) {
            Console.error(e, "Read [logging.properties] from classpath error!");
            try {
                LogManager.getLogManager().readConfiguration();
            } catch (Exception e1) {
                Console.error(e, "Read [logging.properties] from [%JRE_HOME%/lib/logging.properties] error!");
            }
        } finally {
            IoUtil.close(in);
        }
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy