Description
I suggest we implement some basic logging - this seems to be a popular crate and enables clients of our library to implement the actual logging backend:
https://crates.io/crates/log/
Possible use cases:
- It would be useful to log some INFO or WARNING if variables of templates are not set for example.
- 'INFO: rendering template "X"'
- 'WARN: template variable "X" uninitialized'
- We could use it for debugging
- 'DEBUG: parsed token "X" at ..'
I think we could even make this optional in our cargo [features] section. If someone compiles without that feature, we can fallback to real noop-macros. To optimize the runtime costs for different usages, we could even have two compile flags "log" < "debug", where debug implies log, but not otherwise. Our tests could then benefit of some debug logging.
Example from their documentation:
#[macro_use]
extern crate log;
pub fn shave_the_yak(yak: &Yak) {
info!(target: "yak_events", "Commencing yak shaving for {:?}", yak);
loop {
match find_a_razor() {
Ok(razor) => {
info!("Razor located: {}", razor);
yak.shave(razor);
break;
}
Err(err) => {
warn!("Unable to locate a razor: {}, retrying", err);
}
}
}
}
I don't know if we really need LogLevel::Error, because I think we should just return a Result::Err in these cases - so I don't expect us to use this log level, but anyway, here is the list from the log-crate:
pub enum LogLevel {
Error, // log OR debug
Warn, // log OR debug
Info, // log OR debug
Debug, // debug
Trace, // debug
}
What do you think?