mercredi 31 mai 2017

How to include Exceptions and Errors in log4j

I have made log4j appender that stores all logs into one file:

log.info("Hello world");

will store Hello World into the file. How I can make that even Exceptions are stored into that file as log. For example statement:

log.info(5 / 0);

should store whole stack from DivisionByZero Exception into file that is stated in log4j appender.

P.S. I know that I can put log.info(e.printStackTrace()) into catch clause, but I want every catched and non-catched exception is logged.

P.S.S. I know I can redirect stderr output to file, but I don't want touch the console.

Aucun commentaire:

Enregistrer un commentaire