记录器不在spring mvc中

时间:2016-09-28 10:19:57

标签: java spring logging log4j

我无法在我的eclipse控制台中打印记录器的堆栈跟踪。

log4j.properties

  log4j.rootLogger=ERROR,console

  #Console Appender 
  log4j.appender.console=org.apache.log4j.ConsoleAppender
  log4j.appender.console.layout=org.apache.log4j.PatternLayout
  log4j.appender.console.layout.ConversionPattern=[%5p] [%t %d{hh:mm:ss}] (%F:%M:%L) %m%n

  #Custom assignments
  log4j.logger.controller=INFO,console
  log4j.logger.service=INFO,console

  #Disable additivity
  log4j.additivity.controller=false
  log4j.additivity.service=false

服务层:

@Override
@Transactional(readOnly = true)
public List<MRPSDepositHistory> getDepositDetails(String searchCondition,
        String searchText, String jtSorting, int startPaginationVal,
        int endPaginationVal) {
    String searchConditionEmpty = ManagementConstants.SEARCHCONDITIONNONE;

    List<MRPSDepositHistory> fileNetStatus = new ArrayList<MRPSDepositHistory>();
    try {
        if (!searchConditionEmpty.equalsIgnoreCase(searchCondition)) {
            if (searchCondition.equalsIgnoreCase(ManagementConstants.DEPOSITNUMBERKEY)) {
                fileNetStatus = mrpsDepositHistoryDao.findByDepositNumber(
                        searchCondition, Short.valueOf(searchText), jtSorting,
                        startPaginationVal, endPaginationVal);
            } else {
                fileNetStatus = mrpsDepositHistoryDao.findBySearchText(
                        searchCondition, searchText, jtSorting,
                        startPaginationVal, endPaginationVal);
            }
        } else {
            fileNetStatus = mrpsDepositHistoryDao.findByRestrictions(
                    searchCondition, searchText, jtSorting);
        }
    }
    catch (NumberFormatException e) {

        logger.error("ERROR:" + e);
    }
    return fileNetStatus;
}

日志在eclipse中打印到控制台:

  

[ERROR] [http-bio-8080-exec-9 03:46:16](MrpsDepositHistoryServiceImpl.java:getDepositDetails:57)错误:java.lang.NumberFormatException:值超出范围。值:&#34; 353453454&#34;基数:10

我在上面的代码中犯了错误。

1 个答案:

答案 0 :(得分:3)

替换

logger.error("ERROR:"+ e);

通过

logger.error("ERROR:", e);

前一个实际上连接字符串并调用Logger.error(String),它只记录该连接字符串。但是稍后会调用Logger.error(String, Throwable)Throwable(超级Exception)进行单独管理。