Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 345
Gibbs Avatar asked Feb 08 '23 01:02

Gibbs


1 Answers

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

like image 175
Sanjeev Avatar answered Feb 09 '23 22:02

Sanjeev