diff --git a/platform/util/api-dump-unreviewed.txt b/platform/util/api-dump-unreviewed.txt index ed0dcca48eea..40b0fc731e07 100644 --- a/platform/util/api-dump-unreviewed.txt +++ b/platform/util/api-dump-unreviewed.txt @@ -543,8 +543,10 @@ f:com.intellij.openapi.diagnostic.LoggerKt - bs:debug$default(com.intellij.openapi.diagnostic.Logger,java.lang.Exception,kotlin.jvm.functions.Function0,I,java.lang.Object):V - sf:fileLogger():com.intellij.openapi.diagnostic.Logger - sf:getOrLogException(java.lang.Object,com.intellij.openapi.diagnostic.Logger):java.lang.Object +- sf:ifTraceEnabled(com.intellij.openapi.diagnostic.Logger,kotlin.jvm.functions.Function0):java.lang.Object - sf:runAndLogException(com.intellij.openapi.diagnostic.Logger,kotlin.jvm.functions.Function0):java.lang.Object - sf:trace(com.intellij.openapi.diagnostic.Logger,kotlin.jvm.functions.Function0):V +- sf:traceThrowable(com.intellij.openapi.diagnostic.Logger,kotlin.jvm.functions.Function0):V *:com.intellij.openapi.diagnostic.ReportingClassSubstitutor - s:getClassToReport(java.lang.Object):java.lang.Class - a:getSubstitutedClass():java.lang.Class diff --git a/platform/util/src/com/intellij/openapi/diagnostic/logger.kt b/platform/util/src/com/intellij/openapi/diagnostic/logger.kt index cc14afb0f820..083a667d5700 100644 --- a/platform/util/src/com/intellij/openapi/diagnostic/logger.kt +++ b/platform/util/src/com/intellij/openapi/diagnostic/logger.kt @@ -67,6 +67,20 @@ inline fun Logger.trace(@NonNls lazyMessage: () -> String) { } } +/* Cannot name it `trace` due to the clash with the function above */ +inline fun Logger.traceThrowable(lazyThrowable: () -> Throwable) { + if (isTraceEnabled) { + return trace(lazyThrowable()) + } +} + +inline fun Logger.ifTraceEnabled(lazyValue: () -> T): T? { + if (isTraceEnabled) { + return lazyValue() + } + return null +} + /** Consider using [Result.getOrLogException] for more straight-forward API instead. */ inline fun Logger.runAndLogException(runnable: () -> T): T? { return runCatching {