12 unstable releases (4 breaking)

0.4.0 Jun 27, 2024
0.3.0 Apr 8, 2024
0.2.0 Apr 23, 2023
0.1.8 Apr 7, 2023
0.0.2 May 15, 2021

#57 in Procedural macros

Download history 4/week @ 2024-03-15 1/week @ 2024-03-22 40/week @ 2024-03-29 144/week @ 2024-04-05 27/week @ 2024-04-12 40/week @ 2024-04-19 4/week @ 2024-04-26 1/week @ 2024-05-17 1/week @ 2024-05-24 1/week @ 2024-05-31 1/week @ 2024-06-07 122/week @ 2024-06-21 32/week @ 2024-06-28

156 downloads per month
Used in 6 crates


775 lines

wd_log: A practical log crate for rust

wd_log GitHub Actions wd_log on crates.io wd_log on docs.rs License

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...

wd_log = "0.1"



Setting in multithreading is not supported

    //Set log level, default:Debug
    //Set the log output prefix, default:"wd_log"
    //Whether to display the print time, default:true
    //Whether to display the location, default:true
    //Set output to a file, default:stdout
    wd_log::output_to_file("./log.txt").expect("file open failed");


  • By default there is no line break; macros ending in '_ln' indicate line breaks.
    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");
  • Allows empty and formatted printing
    wd_log::log_debug!("{} {}","hello","world");
  • panic
    //After printing, trigger panic.
    wd_log::log_panic!("{}","hello world");

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("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);
  • if result is Err, res_panic will panic after printing this error
  • if result is Ok(T), direct return Some(T)
        let result:Result<&str,&str> = Ok("hello");
        let res = wd_log::res_panic!(result;"succes");
        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.


~31K SLoC