zoukankan      html  css  js  c++  java
  • 日志通用类

     /**
      * 跟踪日志,trace.xml记录
      * @param className 类
      * @param methodName 方法
      * @param msg  消息
      */

     public static void trace(String className,String methodName,String msg){                Logger traceLogger = PafaCoreContexton.getInstance().getTracer();           traceLogger.log(ActionContext.getCurrentUmId(), Level.INFO ,className,   methodName, msg);

     }

       /**
         * 记录error日志
         *
         * @param className -
         *            抛出异常的类名
         * @param methodName -
         *            抛出异常的方法名
         * @param t -
         *            抛出的异常
         */
        public static void logError(String className, String methodName, Throwable t) {
            PafaApplicationContext coreContext = PafaCoreContexton.getInstance();
            Logger errorLogger = coreContext.getErrorLogger();
            errorLogger.log(ActionContext.getCurrentUmId(), Level.SEVERE, className, methodName, "", t, "");
        }

    /**
      * Description: 获取异常堆栈信息  
      * @param throwable
      * @return 
      */
     public static String getStackTrace(Throwable throwable) {
      
      if (throwable == null){
       return "";
      }
      
      String rtn = throwable.getStackTrace().toString();
      
      Writer writer = null;
      PrintWriter printWriter = null;
      try {
       writer = new StringWriter();
       printWriter = new PrintWriter(writer);
       
       throwable.printStackTrace(printWriter);
       
       printWriter.flush();
       writer.flush();
       
       rtn = writer.toString();
       
      } catch (IOException e) {
       LoggerUtil.logError("com.paic.egis.sales.common.util.LoggerUtil", "getStackTrace", e);
       
      } catch (Exception ex) {
       LoggerUtil.logError("com.paic.egis.sales.common.util.LoggerUtil", "getStackTrace", ex);
       
      }finally{
       
       if(printWriter != null){
        printWriter.close();
       }
       try {
        if(writer != null){
         writer.close();
        }
       } catch (IOException e) {
        LoggerUtil.logError("com.paic.egis.sales.common.util.LoggerUtil", "getStackTrace", e);
       }
       
      }
      
      return rtn;
     }

      @SuppressWarnings({ "rawtypes", "unchecked" })
     private static Map fecthParamFromRequest(HttpServletRequest request){
      Map paramMap = new HashMap();
      try{
       synchronized(request){
      
       Enumeration  paramEnum = request.getParameterNames();
       while(paramEnum.hasMoreElements()){
        String paramName = (String)paramEnum.nextElement();
        String messageContent = request.getParameter(paramName);
        paramMap.put(paramName,messageContent);
       }
      }
      }catch(Exception e){
       
      }
      return paramMap;
     }

  • 相关阅读:
    调度器2—cat /proc/<pid>/sched内容分析
    调度器1—相关接口和命令行工具
    Java中的String类
    Java中的数组
    代码访问使用Let's Encrypt证书的网站提示certificate has expired的解决方法
    Linux环境Clion使用Protobuf
    PyTorch Dataloader读取时如何在进程之间传输数据
    6 安装Grafana 展示promethues数据
    5 Prometheus relabel配置
    4 PromQL
  • 原文地址:https://www.cnblogs.com/songyunxinQQ529616136/p/6053877.html
Copyright © 2011-2022 走看看