com.launchdarkly.eventsource.LazyStackTrace Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of okhttp-eventsource Show documentation
Show all versions of okhttp-eventsource Show documentation
EventSource Implementation built on OkHttp
package com.launchdarkly.eventsource;
import java.io.PrintWriter;
import java.io.StringWriter;
/**
* This class wraps a exception so that we can log its stacktrace in a debug message without
* actually computing the stacktrace unless the logger has enabled debug output.
*
* We should only use this for cases where the stacktrace may actually be informative, such
* as an unchecked exception thrown from an application's message handler. For I/O exceptions
* where the source of the exception can be clearly indicated by the log message, we should
* not log stacktraces.
*/
final class LazyStackTrace {
private final Throwable throwable;
LazyStackTrace(Throwable throwable) {
this.throwable = throwable;
}
@Override
public String toString() {
StringWriter sw = new StringWriter();
throwable.printStackTrace(new PrintWriter(sw));
return sw.toString();
}
}
© 2015 - 2024 Weber Informatics LLC | Privacy Policy