package cn.ezhizao.framework.logGing;

import org.springframework.beans.factory.annotation.Value;

import java.io.IOException;
import java.util.logging.FileHandler;
import java.util.logging.Logger;
import java.util.logging.SimpleFormatter;

public class LoggerUtil {

    @Value("${file.upload.path}")
    private static String uploadPath;

    private static final Logger logger = Logger.getLogger(LoggerUtil.class.getName());

    static {
        try {
            // 设置日志文件的路径和文件名
            String logFileName = uploadPath+"carrierNum.log";
            FileHandler fileHandler = new FileHandler(logFileName, true); // true表示追加模式
            fileHandler.setFormatter(new SimpleFormatter());

            // 将FileHandler添加到Logger中
            logger.addHandler(fileHandler);
        } catch (IOException e) {
            // 处理异常
            logger.warning("无法初始化日志文件: " + e.getMessage());
        }
    }

    public static void logInfo(String message) {
        logger.info(message);
    }

    public static void logWarning(String message) {
        logger.warning(message);
    }

    public static void logSevere(String message) {
        logger.severe(message);
    }
}