예제 #1
0
  /**
   * apo:around环绕方式记录日志
   *
   * @param jp
   * @return
   * @throws Throwable
   */
  public Object saveLoginAndLogic(ProceedingJoinPoint jp) throws Throwable {

    LogMethod logMethod = LogMethodText(jp);

    Object ret = null;
    try {
      if (logMethod != null
          && (logMethod.loglevel().equals(LOGLEVEL.ALL)
              || logMethod.loglevel().equals(LOGLEVEL.OPERATION))
          && (logMethod.logpos().equals(LOGPOS.BEFORE) || logMethod.logpos().equals(LOGPOS.ALL))) {
        doLog(logMethod, jp);
      }

      ret = jp.proceed();

      if (logMethod != null
          && (logMethod.loglevel().equals(LOGLEVEL.ALL)
              || logMethod.loglevel().equals(LOGLEVEL.OPERATION))
          && (logMethod.logpos().equals(LOGPOS.AFTER) || logMethod.logpos().equals(LOGPOS.ALL))) {
        doLog(logMethod, jp);
      }
    } catch (Throwable e) {
      e.printStackTrace();
      throw e;
    }
    return ret;
  }
예제 #2
0
 /**
  * 发生异常的时候,记录异常日志【记录范围:已经注册过的动作中的BusinessException】
  *
  * @param jp
  * @param ex
  * @throws Exception
  * @author 朱启亮
  * @date 2008-1-24
  */
 public void saveException(JoinPoint jp, Exception ex) throws Exception {
   if (ex instanceof BusinessException) {
     LogMethod logMethod = LogMethodText(jp);
     if (logMethod != null
         && (logMethod.loglevel().equals(LOGLEVEL.ALL)
             || logMethod.loglevel().equals(LOGLEVEL.EXCEPTION))) {
       String logText = logMethod.name();
       String exceptionStr = exceptionToString(ex);
       String classStr = jp.getTarget().getClass().getName();
       String methodStr = classStr + "." + jp.getSignature().getName();
       logText += "时发生异常(" + methodStr + ")  具体信息:" + exceptionStr;
       saveLog(jp, logText, classStr, ex);
     }
   }
 }
예제 #3
0
  /**
   * 创建并保存日志对象
   *
   * @param logMethod
   * @param jp
   */
  private void doLog(LogMethod logMethod, ProceedingJoinPoint jp) {
    String logText = logMethod.name();
    String classStr = jp.getTarget().getClass().getName();

    Object obj = jp.getThis();
    if (obj instanceof AbstractAction) {
      AbstractAction action = (AbstractAction) obj;
      HttpServletRequest request = action.getRequest();
      logText += "\r\n请求:" + request.getRequestURI() + "\r\n";
      Enumeration params = request.getParameterNames();
      while (params.hasMoreElements()) {
        String param = (String) params.nextElement();
        String value = request.getParameter(param);
        logText += ("参数->" + param + ":" + value + "\r\n");
      }
    }
    saveLog(jp, logText, classStr);
  }