简体   繁体   中英

Log4j not printing complete stack trace

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?

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM