Expand description
Logging library.
This is probably the only part of squeekboard that should be doing any direct printing.
There are several approaches to logging, in the order of increasing flexibility and/or purity:
println!
directly
It can’t be easily replaced by a different solution
- simple
log!
macro
Replacing the destination at runtime other than globally would be awkward, so no easy way to suppress errors for things that don’t matter, but formatting is still easy.
- logging to a mutable destination type
Can be easily replaced, but logging Result
types,
which should be done by calling a method on the result,
can’t be formatted directly.
Cannot be parallelized.
- logging to an immutable destination type
Same as above, except it can be parallelized. Logs being outputs, they get returned instead of being misleadingly passed back through arguments. It seems more difficult to pass the logger around, but this may be a solved problem from the area of functional programming.
This library generally aims at the approach in 3.
Macros
Sugar for approach 2
Structs
Prints info to stdout, everything else to stderr
Warning handler that will panic at any warning, error, surprise, bug, or panic. Don’t use except in tests
Enums
Levels are not in order.
Only levels which indicate problems
To use with Result::Err
handlers,
which are needed only when something went off the optimal path.
A separate type ensures that Err
can’t end up misclassified as a benign event like Info
.
Traits
Functions
Approach 2