Behold
A simple library to aide in contextual debugging. This is a partial Rust port of the Python Behold library.
Core Concept
Sometimes print debugging is the best way to examine the state of a running program.
But frequently you only care about the prints in a particular code path.
With Behold
, one part of the program can control debugging in another.
All Behold instances share the same global context to control what to print. However, a Behold instance can be created and configured to determine how or what it prints.
Contextual Debugging
BEHOLD.show("testing".to_string())
will print "testing" to the screen.
BEHOLD.when(true).show("testing".to_string())
will print "testing" to the screen.
BEHOLD.when(false).show("testing".to_string())
will do nothing.
BEHOLD.when_context("key".to_string()).show("testing".to_string())
will print "testing" to the screen but only if the "testing" key has been set to true
previously.
extern crate behold;
use behold;
Produces the output:
Behold: Hello from f(0)!
Behold: Hello from f2(0)!
Behold: Hello from f(1)!
Behold: Hello from f3(1)!
Behold: Hello from f(2)!
Behold: Hello from f2(2)!
Tagged Printing
Each instance of Behold can be configured with a tag to help distinguish output.
extern crate behold;
use behold;
Produces the output:
Hello world!, yolo