Merge pull request #211 from eed3si9n/wip/stacktrace

reimplement stacktrace suppression
This commit is contained in:
eugene yokota 2019-08-20 12:46:37 -04:00 committed by GitHub
commit f48340f708
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 20 additions and 10 deletions

View File

@ -481,16 +481,23 @@ class ConsoleAppender private[ConsoleAppender] (
} }
private def appendTraceEvent(te: TraceEvent): Unit = { private def appendTraceEvent(te: TraceEvent): Unit = {
val traceLevel = if (getTrace < 0) Int.MaxValue else getTrace val traceLevel = getTrace
val throwableShowLines: ShowLines[Throwable] = if (traceLevel >= 0) {
ShowLines[Throwable]((t: Throwable) => { val throwableShowLines: ShowLines[Throwable] =
List(StackTrace.trimmed(t, traceLevel)) ShowLines[Throwable]((t: Throwable) => {
}) List(StackTrace.trimmed(t, traceLevel))
val codec: ShowLines[TraceEvent] = })
ShowLines[TraceEvent]((t: TraceEvent) => { val codec: ShowLines[TraceEvent] =
throwableShowLines.showLines(t.message) ShowLines[TraceEvent]((t: TraceEvent) => {
}) throwableShowLines.showLines(t.message)
codec.showLines(te).toVector foreach { appendLog(Level.Error, _) } })
codec.showLines(te).toVector foreach { appendLog(Level.Error, _) }
}
if (traceLevel <= 2) {
suppressedMessage(new SuppressedTraceContext(traceLevel, ansiCodesSupported && useFormat)) foreach {
appendLog(Level.Error, _)
}
}
} }
private def appendProgressEvent(pe: ProgressEvent): Unit = private def appendProgressEvent(pe: ProgressEvent): Unit =

View File

@ -20,6 +20,9 @@ object StackTrace {
* - If d is greater than 0, then up to that many lines are included, * - If d is greater than 0, then up to that many lines are included,
* where the line for the Throwable is counted plus one line for each stack element. * where the line for the Throwable is counted plus one line for each stack element.
* Less lines will be included if there are not enough stack elements. * Less lines will be included if there are not enough stack elements.
*
* See also ConsoleAppender where d <= 2 is treated specially by
* printing a prepared statement.
*/ */
def trimmedLines(t: Throwable, d: Int): List[String] = { def trimmedLines(t: Throwable, d: Int): List[String] = {
require(d >= 0) require(d >= 0)