package cc.smtweb.system.bpm.util;

import cc.smtweb.framework.core.util.CommUtil;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.text.MessageFormat;

@SuppressWarnings("UnusedDeclaration")
public class UtilLogger {
    private static final Logger logger = LoggerFactory.getLogger(Logger.ROOT_LOGGER_NAME);

    private static String getOrigMsg(String message, Throwable e) {
        if (message != null) return message;
        return CommUtil.getOrigMsg(e);
    }

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

    public static void debug(String message, String module) {
        logger.debug(MessageFormat.format("[{0}]{1}", module, message));
    }

    public static void debug(String message, Throwable e) {
        logger.debug(getOrigMsg(message, e), e);
    }

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

    public static void info(String message, String module) {
        logger.info(MessageFormat.format("[{0}]{1}", module, message));
    }

    public static void info(String message, Throwable e) {
        logger.info(getOrigMsg(message, e), e);
    }

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

    public static void warn(String message, String module) {
        logger.warn(MessageFormat.format("[{0}]{1}", module, message));
    }

    public static void warn(String message, Throwable e) {
        logger.warn(getOrigMsg(message, e), e);
    }

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

    public static void error(String message, String module) {
        logger.error(MessageFormat.format("[{0}]{1}", module, message));
    }

    public static void error(String message, Throwable e) {
        if (e instanceof Exception) logger.info(message + CommUtil.getOrigMsg(e));
        else logger.error(getOrigMsg(message, e), e);
    }
}
