14

I am loging error im my java swing application: logger.error("ERROR: " + ex); where ex is exception

this just print me 13:33:58,964 ERROR PlayOffPanel:292 - ERROR: java.lang.NullPointerException

but I wanna know stacktrace.

my log4j properites:

log4j.rootLogger=DEBUG,file

log4j.appender.file=org.apache.log4j.RollingFileAppender
log4j.appender.file.maxFileSize=100KB
log4j.appender.file.maxBackupIndex=5
log4j.appender.file.File=error.log
log4j.appender.file.threshold=DEBUG
log4j.appender.file.layout=org.apache.log4j.PatternLayout
log4j.appender.file.layout.ConversionPattern=%d{ABSOLUTE} %5p %c{1}:%L - %m%n
hudi
  • 15,555
  • 47
  • 142
  • 246

2 Answers2

45

You have to write

logger.error("Error description",ex);

Look at the javadoc, the exception must be the second arguments if you want stacktrace.

dash1e
  • 7,677
  • 1
  • 30
  • 35
  • What if it's not an exception, you're using `logger.error` for a custom error message and you want to print the stacktrace anyways? – Mark Apr 16 '14 at 22:31
9

Typically, you can pass the Throwable instance to the logger as well, e.g.

logger.error( "My custom message", exception )
Robin
  • 36,233
  • 5
  • 47
  • 99