scoop:scoop.core:0.1.0
src/debug.scoop
Selected production source · src/debug.scoop
1
/**2
* Controls whether debug output is compact or arranged on indented lines.3
*/4
public enum DebugLayout {5
/**6
* Keeps structural output compact without pretty-print line breaks.7
*/8
Compact,9
/**10
* Uses line breaks and the configured indentation for nested structures.11
*/12
Pretty }14
/**15
* Controls debug layout and maximum depth, item count, and string length. Limits must be16
* nonnegative and truncate presentation rather than altering the observed value.17
*/18
public struct DebugOptions(19
val layout: DebugLayout = DebugLayout.Compact,20
val indent: String = " ",21
val maxDepth: Long = 8L,22
val maxItems: Long = 32L,23
val maxStringLength: Long = 256L24
)26
/**27
* Omits an annotated field or property from debug output.28
*/29
@Target([AnnotationTarget.Field, AnnotationTarget.Property])30
public annotation class DebugIgnore32
/**33
* Substitutes the configured text for an annotated field or property without exposing its value.34
*/35
@Target([AnnotationTarget.Field, AnnotationTarget.Property])36
public annotation class DebugRedact(val replacement: String = "<redacted>")38
/**39
* Formats ValueView observations with cycle handling, redaction, and bounded presentation.40
*/41
public object DebugPrinter {42
/**43
* Writes an observation to the supplied text destination. Invalid negative limits throw44
* IllegalArgumentException.45
*/46
public fun write(view: ValueView, writer: TextWriter, options: DebugOptions = DebugOptions()) {47
if (options.maxDepth < 0L || options.maxItems < 0L || options.maxStringLength < 0L) {48
throw IllegalArgumentException()49
}50
DebugSession(writer, options).write(view, 0L, true)51
}53
/**54
* Returns the same debug representation as write in an immutable string.55
*/56
public fun format(view: ValueView, options: DebugOptions = DebugOptions()): String {57
val writer = StringWriter()58
write(view, writer, options)59
return writer.toString()60
}61
}