我无法在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中,日志已在控制台中打印:


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


我在上面的代码中弄错了什么。

最佳答案

更换

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


通过

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


前一个实际上是连接字符串的,并调用Logger.error(String),它仅记录该连接字符串。但是后来有人呼叫Logger.error(String, Throwable),其中ThrowableException的超类)是单独管理的。

关于java - 记录器未在Spring MVC中打印堆栈跟踪,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/39744671/

10-12 00:44