1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
#[macro_use] mod log_macro;
// mod log_out;
mod log_config;

pub use log_config::{set_level,set_prefix,show_time,show_file_line,output_to_file};
pub use log_config::{get_level,get_prefix,output};
pub use log_config::{Level,DEBUG,INFO,WARN,ERROR,PANIC};





#[cfg(test)]
mod tests {
    use crate::{show_time, show_file_line, set_prefix, set_level, DEBUG, output, output_to_file, INFO, Level};
    #[test]
    fn log_config() {
        //Set log level, default:Debug
         set_level( INFO);
        //Set the log output prefix, default:"wd_log"
         set_prefix("WDLOG");
        //Whether to display the print time, default:true
         show_time(false);
        //Whether to display the location, default:true
         show_file_line(false);
        //Set output to a file, default:stdout
         output_to_file("./log.txt").expect("file open failed");
         log_debug_ln!("this is file output");
    }
    #[test]
    fn log_print(){
         log_debug!("hello world");
         log_debug_ln!("hello world");
         log_info!("hello world");
         log_info_ln!("hello world");
         log_warn!("hello world");
         log_warn_ln!("hello world");
         log_error!("hello world");
         log_error_ln!("hello world");
    }
    #[test]
    #[should_panic]
    fn log_panic(){
         log_panic!("hello world");
    }
    #[test]
    fn error(){
        let result = Err("hello");
        let _res:Option<()> =  res_error!(result);
        let _res:Option<()> =  res_error_ln!(result);

        let _res:Option<()> =  res_error!(result;"this is {}","error");
        let _res:Option<()> =  res_error_ln!(result;"this is {}","error");

        let result:Result<&str,&str> = Ok("world");
        let res:Option<&str> =  res_error!(result);
        assert_eq!(res,Some("world"))
    }
    #[test]
    #[should_panic]
    fn res_panic(){
        let result:Result<&str,&str> = Ok("hello");
        let res =  res_panic!(result;"succes");
        println!("{}",res);
        let result = Err("hello");
        //It can lead to panic
        let _ =  res_panic!(result;"this is {}","error");
    }
    #[test]
    fn test_level(){
        let level = Level::from("inFO");
        println!("level {}",level.as_u8())
    }
}