Log4j not printing complete stack trace

↘锁芯ラ 提交于 2020-01-02 17:00:33

问题


I checked all the answers in the SO. But none really helped me.

My Log4j property file

log4j.rootLogger=debug,console,file

log4j.appender.console=org.apache.log4j.ConsoleAppender
log4j.appender.console.layout=org.apache.log4j.PatternLayout
log4j.appender.console.layout.ConversionPattern=%d %5p [%t] (%F:%L) - %m%n

log4j.appender.file=org.apache.log4j.RollingFileAppender
log4j.appender.file.File=eseries.log
log4j.appender.file.MaxFileSize=1KB
log4j.appender.file.layout=org.apache.log4j.EnhancedPatternLayout
log4j.appender.file.layout.ConversionPattern=%d %5p [%t] (%F:%L) - %m%n %throwable{short}

My log4j version

<dependency>
    <groupId>log4j</groupId>
    <artifactId>log4j</artifactId>
    <version>1.2.11</version>
  </dependency>

Loggin Format

    logger.error("*****Error Id is:"+errorId+"\t" , e);

What I am getting

I am just getting the e.getMessage() in the log. Not the complete log trace.

Any suggestion?


回答1:


This is because of your conversion pattern

 log4j.appender.file.layout.ConversionPattern=%d %5p [%t] (%F:%L) - %m%n %throwable{short}

Here is excerpt from ThrowableInformationPatternConverter

Outputs the ThrowableInformation portion of the LoggingEvent. By default, outputs the full stack trace.

%throwable{none} or %throwable{0} suppresses the stack trace.

%throwable{short} or %throwable{1} outputs just the first line.

%throwable{n} will output n lines for a positive integer or drop the last -n lines for a negative integer.

You need to remove %throwable{short} to see full stack trace



来源:https://stackoverflow.com/questions/37206067/log4j-not-printing-complete-stack-trace

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!