2

I'm using log4j to log unhandled exceptions. But how can I log the stacktrace?

I tried the following:

Logger.getRootLogger().fatal(e);

Result: 2013-11-05 14:25:07,078 FATAL root: java.lang.NullPointerException BUT no stacktrace! Why?

membersound
  • 81,582
  • 193
  • 585
  • 1,120

2 Answers2

1

Try with:

Logger.getRootLogger().fatal(e, e);
Paul Vargas
  • 41,222
  • 15
  • 102
  • 148
0

field element

private static final Logger LOGGER = LogFactory.getLogger(YourClazz.class);

in your methods, simply log e

LOGGER.error("There was an error {}",e);

and it will print the full stacktrace

RamonBoza
  • 8,898
  • 6
  • 36
  • 48