Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Logging #19

Open
colin-kiegel opened this issue Dec 27, 2015 · 0 comments
Open

Logging #19

colin-kiegel opened this issue Dec 27, 2015 · 0 comments

Comments

@colin-kiegel
Copy link
Member

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?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant