Crates.io | wd_log |
lib.rs | wd_log |
version | 0.4.0 |
source | src |
created_at | 2021-05-15 09:17:05.415413 |
updated_at | 2024-06-27 06:50:21.998425 |
description | A practical log crate for rust |
homepage | |
repository | |
max_upload_size | |
id | 397771 |
size | 44,538 |
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.
The current version is preliminary and will get better in the future.
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...
[dependencies]
wd_log = "0.1"
Setting in multithreading is not supported
//Set log level, default:Debug
wd_log::set_level(wd_log::INFO);
//Set the log output prefix, default:"wd_log"
wd_log::set_prefix("WDLOG");
//Whether to display the print time, default:true
wd_log::show_time(false);
//Whether to display the location, default:true
wd_log::show_file_line(false);
//Set output to a file, default:stdout
wd_log::output_to_file("./log.txt").expect("file open failed");
wd_log::log_debug!("{}","hello world");
wd_log::log_debug_ln!("{}","hello world");
wd_log::log_info!("{}","hello world");
wd_log::log_info_ln!("{}","hello world");
wd_log::log_warn!("{}","hello world");
wd_log::log_warn_ln!("{}","hello world");
wd_log::log_error!("{}","hello world");
wd_log::log_error_ln!("{}","hello world");
wd_log::log_debug!();
wd_log::log_debug!("{} {}","hello","world");
//After printing, trigger panic.
wd_log::log_panic!("{}","hello world");
let result = Err("hello");
let _res:Option<()> = wd_log::res_error!(result);
let _res:Option<()> = wd_log::res_error_ln!(result);
let _res:Option<()> = wd_log::res_error!(result;"this is {}","error");
let _res:Option<()> = wd_log::res_error_ln!(result;"this is {}","error");
let result:Result<&str,&str> = Ok("world");
let res:Option<&str> = wd_log::res_error!(result);
assert_eq!(res,Some("world"))
let result:Result<&str,&str> = Ok("hello");
let res = wd_log::res_panic!(result;"succes");
println!("{}",res);
let result = Err("hello");
//It can lead to panic
let _ = wd_log::res_panic!(result;"this is {}","error");
Licensed under either of
at your option.
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.