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

    /**
    * log4j日志Util
    */
    public class LogUtil {
    private static Logger logger=null;

    static{
    StackTraceElement[] stackTraceElements=new Throwable().getStackTrace();
    String callerClassName=stackTraceElements[1].getClassName();
    logger=LoggerFactory.getLogger(callerClassName);
    }

    private LogUtil(){}

    //---------------------error---------------------------------
    public static void error(String param,String msg,Throwable e){
    StackTraceElement se = Thread.currentThread().getStackTrace()[2];
    String clazzMethod = " "+se.getClassName() +"." + se.getMethodName() + "("+se.getFileName()+":"+se.getLineNumber()+") ";

    String log = clazzMethod+" PARAMS: " +param+" "+" MSG: "+ msg;
    logger.error(log,e);
    }

    //---------------------warn----------------------------------
    public static void warn(String param,String msg){
    StackTraceElement se = Thread.currentThread().getStackTrace()[2];
    String clazzMethod = " "+se.getClassName() +"." + se.getMethodName() + "("+se.getFileName()+":"+se.getLineNumber()+") ";

    String log = clazzMethod+" PARAMS: " +param+" "+" MSG: "+ msg;
    logger.warn(log);
    }

    //---------------------info----------------------------------
    public static void info(String param,String msg){//
    StackTraceElement se = Thread.currentThread().getStackTrace()[2];
    String clazzMethod = " "+se.getClassName() +"." + se.getMethodName() + "("+se.getFileName()+":"+se.getLineNumber()+") ";

    String log = clazzMethod + " PARAMS: " +param+" "+" MSG: "+ msg;
    logger.info(log);
    }

    public static void debug(String msg) {
    StackTraceElement se = Thread.currentThread().getStackTrace()[2];
    String clazzMethod = " "+se.getClassName() +"." + se.getMethodName() + "("+se.getFileName()+":"+se.getLineNumber()+") ";

    String log = clazzMethod + " MSG: "+ msg;
    logger.debug(log);
    }

    }

  • 相关阅读:
    Redis集群(一)
    Mysql分库分表
    Redisson分布式锁
    Spring Cloud Eureka 高可用
    Spring RestTemplate具备负载均衡功能
    Redis分布式锁
    B树/B-树/B+树/B*树的数据库应用
    ABAC访问控制模型
    Maven自定义打包的包名
    Versions maven plugin 修改版本
  • 原文地址:https://www.cnblogs.com/wangjing666/p/6842181.html
Copyright © 2011-2022 走看看