1

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
  • 74,158
  • 163
  • 522
  • 986

2 Answers2

1

Try with:

Logger.getRootLogger().fatal(e, e);
Paul Vargas
  • 40,346
  • 15
  • 98
  • 144
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,631
  • 5
  • 34
  • 48