com.tersesystems.blindsight.inspection
Decorates the given if statement with logging statements.
Decorates the given if statement with logging statements.
For example, the following code:
decorateIfs(dif: BranchInspection => logger.debug(s"${dif.code} = ${dif.result}")) { if (System.currentTimeMillis() % 17 == 0) { println("branch 1") } else if (System.getProperty("derp") == null) { println("branch 2") } else { println("else branch") } }
would cause the logger to debug two lines:
"System.currentTimeMillis() % 17 == 0 = false" "System.getProperty("derp") == null = true"
the result type
the logging statement to apply on each branch.
the if statement to decorate with statements
the result of the if statement.
Decorates a match statement with logging statements at each case.
Decorates a match statement with logging statements at each case.
For example, given the following code:
val string = java.time.Instant.now().toString decorateMatch(dm: BranchInspection => logger.debug(s"${dm.code} = ${dm.result}")) { string match { case s if s.startsWith("20") => println("this example is still valid") case _ => println("oh dear") } }
This will log the following at DEBUG level:
"string match case s if s.startsWith("20") = true"
the result type
the logging statement to apply to each case
the match statement to decorate with statements
Decorates a given block with logging statements after each val
or var
(technically a ValDef
).
Decorates a given block with logging statements after each val
or var
(technically a ValDef
).
For example, given the following statement:
decorateVals(dval: ValDefInspection => logger.debug(s"${dval.name} = ${dval.value}")) { val a = 5 val b = 15 a + b }
There would be two statements logged at DEBUG level:
"a = 5" "b = 15"
the result type
the logging statement to put after each ValDef
the block to decorate with logging statements.
the result, if any
Creates a DebugResult
containing the code and result of a block / expression.
Creates a DebugResult
containing the code and result of a block / expression.
For example, the following statement:
val dr: ExprInspection[Int] = dumpExpression(1 + 1) logger.debug(s"result: ${dr.code} = ${dr.value}")
would result in "result: 1 + 1 = 2"
the result type
the block or expression
a debug result containing the code and value.
Dumps public fields from an object.
Dumps public fields from an object.
class ExampleClass(val someInt: Int) { protected val protectedInt = 22 } val exObj = new ExampleClass(42) val publicFields: Seq[ValDefInspection] = dumpPublicFields(exObj) logger.debug(publicFields.toString)
Should result in:
"Seq(DebugVal(someInt,42))"
the type of the object
the object instance
the DebugVal
representing the public fields of the object.
Macros used for close inspection and debugging values.
Easiest way to use these is to pay the import tax up front, or incorporate them into an
Inspections
trait.These macros are intended to be used in situations where you would use "printf debugging" to get a read on individual values and branches.
The macros here have not been rigorously tested and should be considered experimental.