A zero-dependency logger for Rust.
During the development of another project I am working on, I decided to implement basic logging functionality, just to reassure the user on what was happening. My friend saw this and asked if I could make it a public crate for them to use. And so, log_zero was born.
What's especially important about this logging crate, is
that it has ZERO dependencies outside of the std crate.
It's pretty simple!
First, you should call log_zero::init(loglevel) somewhere
near the start of your program - maybe near fn main().
Example:
use log_zero::{init, LogLevel};
fn main() {
init(LogLevel::Info);
}In this case, I have chosen to set the minimum log level to
Info, which means that any log severity below info will
NOT be printed to the console (debug logs will not be shown).
Additionally, you are able to change the minimum severity level at any point via:
log_zero::set_min_level(log_level);log_level correlates to any of the 5 severity levels.
This change is immediate, and doesn't affect any prior logging.
You can also log to a file, like so:
log_zero::set_log_out(...);In this case, set_log_out takes either Some(&str) or None.
If set to Some(&str), the logger will write any log events
to the file path specified. It will even create the directory
for you! If it is set to None, then the logger will write the
logs to the console.
There is a similarly-named variant called try_set_log_out,
which returns a result that determines whether the attempt to
place a log file in the specified directory was successful
or not.
From there, you can call any of the following logging macros:
log_debug!("debug-level message");
log_info!("informational message");
log_warn!("be aware of this message");
log_error!("erroneous event caused this message");
log_fatal!("bad message, should terminate the program");As mentioned before, if the program has set the minimum level
to, for example, LogLevel::Error, then log_warn, log_info,
log_debug will not be shown in the console output.
If you'd like to contribute to this crate, feel free to do so! However, make sure that any core contributions don't use any other crate, since I'd like to maintain strict zero-dependency for the core functionality.
On that note...
If the pull request you are making is for compatibility between another crate, PLEASE make it a feature set that is NOT part of default.
Thank you for viewing my little project. I hope that it ends up being useful to you :)