title: Log4j formatting: Is it possible to truncate stacktraces?
body: <p>I want to log only the first few lines of Exceptions in my program. I know, I can do something like this to print only the first 5 lines of a stacktrace:</p>
  
  <pre><code>Throwable e = ...;
  StackTraceElement[] stack = e.getStackTrace();
  int maxLines = (stack.length &gt; 4) ? 5 : stack.length;
  for (int n = 0; n &lt; maxLines; n++) {
      System.err.println(stack[n].toString());
  }
  </code></pre>
  
  <p>But I would rather use log4j (or slf4j over log4j to be more precise) for logging. Is there a way to tell log4j that it should only print the first 5 lines of a stacktrace?</p>