wd_log: A practical log crate for rust
This is a Rust Log Crate. Log output is mainly achieved through macros. Log composite output will be supported in future releases. The following features are now supported.
- configurable
- color identification
- output to file
- combination field (coding)
The current version is preliminary and will get better in the future.
Getting Started
wd_log is available on crates.io. It is recommended to look there for the newest released version, as well as links to the newest builds of the docs.
At the point of the last update of this README, the latest published version could be used like this:
Add the following dependency to your Cargo manifest...
= "0.1"
wd_log
Example
config
//Set log level, default:Debug
set_level;
//Set the log output prefix, default:"wd_log"
set_prefix;
//Whether to display the print time, default:true
show_time;
//Whether to display the location, default:true
show_file_line;
//Set output to a file, default:stdout
output_to_file.expect;
- By default there is no line break; macros ending in '_ln' indicate line breaks.
!;
log_debug_ln!;
log_info!;
log_info_ln!;
log_warn!;
log_warn_ln!;
log_error!;
log_error_ln!;
log_debug
- Allows empty and formatted printing
!;
log_debug!;
log_debug
- panic
//After printing, trigger panic.
log_panic!;
result type deal
- Macros that begin with 'res_' can handle the result type
- if result is Err, print an error and return None
- if result if Ok(T), direct return Some(T)
let result = Err;
let _res: = res_error!;
let _res: = res_error_ln!;
let _res: = res_error!;
let _res: = res_error_ln!;
let result: = Ok;
let res: = res_error!;
assert_eq!
- if result is Err, res_panic will panic after printing this error
- if result is Ok(T), direct return Some(T)
let result: = Ok;
let res = res_panic!;
println!;
let result = Err;
//It can lead to panic
let _ = res_panic!;
License
Licensed under either of
- Apache License, Version 2.0, (LICENSE-APACHE or http://www.apache.org/licenses/LICENSE-2.0)
- MIT license (LICENSE-MIT or http://opensource.org/licenses/MIT)
at your option.
Contribution
Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.