zoukankan      html  css  js  c++  java
  • 日志工具类

    package com.pt.platform.core.common;
    
    import java.text.SimpleDateFormat;
    import java.util.Date;
    import java.util.HashMap;
    import java.util.Map;
    import org.slf4j.Logger;
    import org.slf4j.LoggerFactory;
    
    public class JYLoggerUtil {
        private static final Logger log = LoggerFactory.getLogger(JYLoggerUtil.class);
        private static final SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        private static ThreadLocal<Map<String, Date>> threadMap = new ThreadLocal();
    
        public JYLoggerUtil() {
        }
    
        public static <T> void info(Class<T> clazz, String message) {
            Logger logger = LoggerFactory.getLogger(clazz);
            logger.info(message);
        }
    
        public static <T> void info(Class<T> clazz, String message, Throwable t) {
            Logger logger = LoggerFactory.getLogger(clazz);
            logger.info(message, t);
        }
    
        public static <T> void debug(Class<T> clazz, String message) {
            Logger logger = LoggerFactory.getLogger(clazz);
            logger.debug(message);
        }
    
        public static <T> void error(Class<T> clazz, String message) {
            Logger logger = LoggerFactory.getLogger(clazz);
            logger.error(message);
        }
    
        public static <T> void error(Class<T> clazz, String message, Exception ex) {
            Logger logger = LoggerFactory.getLogger(clazz);
            logger.error(message, ex);
        }
    
        public static <T> void logCurrentTime(String key, boolean isStart, Class<T> cls) {
            if(log.isInfoEnabled()) {
                Object timeMap = (Map)threadMap.get();
                if(timeMap == null) {
                    timeMap = new HashMap();
                    threadMap.set(timeMap);
                }
    
                String mapKey = cls.getName() + ":" + key;
                Date curDate = new Date();
                if(isStart) {
                    ((Map)timeMap).put(mapKey, curDate);
                } else {
                    Date lastDate = (Date)((Map)timeMap).get(mapKey);
                    if(lastDate != null) {
                        ((Map)timeMap).remove(mapKey);
                        StringBuilder logInfo = new StringBuilder("=========");
                        logInfo.append(",(位置:").append(cls.getName());
                        logInfo.append(",内容:").append(key).append(")");
                        logInfo.append(",间隔:").append(curDate.getTime() - lastDate.getTime());
                        logInfo.append(",开始start:").append(sdf.format(lastDate));
                        logInfo.append(",结束end:").append(sdf.format(curDate)).append("=========");
                        log.info(logInfo.toString());
                        threadMap.remove();
                    }
                }
    
            }
        }
    }
  • 相关阅读:
    CSP201412-2:Z字形扫描
    CSP201409-2:画图
    CSP201403-2:窗口
    CSP201312-2:ISBN号码
    CSP201709-1:打酱油
    CSP201703-1:分蛋糕
    CSP201612-1:中间数
    LOAM笔记及A-LOAM源码阅读
    特征值、特征向量与PCA算法
    欧几里得与区域生长算法
  • 原文地址:https://www.cnblogs.com/yy123/p/7388255.html
Copyright © 2011-2022 走看看