问题
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