I am using Log4j2, some beta-10 version or so.
It's easy to log a stack trace when you have an exception:
} catch (Exception ex) {
log.error("Doing stuff went wrong", ex);
}
Suppose though there is no Throwable
object available - I just realized there is a problem and want to log an error:
if (stuffIsWrong()) {
log.error("Stuff went wrong");
}
How can I tell Log4j2 to log a stack trace beginning in the current method?
Just create a new Exception
if (stuffIsWrong()) {
log.error("Stuff went wrong", new Exception("Stracktracegenerator"));
}
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments