log4j print stacktrace

Java
try {
   ...
} catch (Exception e) {
    log.error( "failed!", e );
}
Source

Also in Java: