1
+ use std:: {
2
+ thread,
3
+ time:: Duration ,
4
+ } ;
5
+
6
+ use tklog:: handle:: { FileSizeMode , FileTimeMode } ;
7
+ use tklog:: { debug, error, fatal, info, trace, warn, LogOption , LEVEL , LOG } ;
8
+ use tklog:: {
9
+ async_debug, async_error, async_fatal, async_info, async_trace, async_warn, ASYNC_LOG
10
+ } ;
11
+
12
+ #[ test]
13
+ fn testlog ( ) {
14
+ LOG
15
+ . set_level_option ( LEVEL :: Debug , LogOption { format : None , formatter : None , level : None , console : None , fileoption : Some ( Box :: new ( FileTimeMode :: new ( "0200time.log" , tklog:: MODE :: DAY , 0 , false ) ) ) } )
16
+ . set_level_option ( LEVEL :: Error , LogOption { format : None , formatter : None , level : None , console : None , fileoption : Some ( Box :: new ( FileSizeMode :: new ( "0200size.log" , 1 <<10 , 0 , false ) ) ) } )
17
+ . set_level_option ( LEVEL :: Fatal , LogOption { format : None , formatter : None , level : None , console : None , fileoption : Some ( Box :: new ( FileSizeMode :: new ( "0200size.log" , 1 <<10 , 0 , false ) ) ) } ) ;
18
+
19
+ trace ! ( "this is trace log" ) ;
20
+ debug ! ( "this is debug log" ) ;
21
+ info ! ( "this is info log" ) ;
22
+ warn ! ( "this is warn log" ) ;
23
+ error ! ( "this is error log" ) ;
24
+ fatal ! ( "this is fatal log" ) ;
25
+ thread:: sleep ( Duration :: from_secs ( 1 ) )
26
+ }
27
+
28
+
29
+
30
+ #[ tokio:: test]
31
+ async fn asynctestlog ( ) {
32
+ ASYNC_LOG . set_level_option ( LEVEL :: Info , LogOption { format : None , formatter : None , level : None , console : None , fileoption : Some ( Box :: new ( FileTimeMode :: new ( "0200asynctime.log" , tklog:: MODE :: DAY , 0 , false ) ) ) } ) . await
33
+ . set_level_option ( LEVEL :: Fatal , LogOption { format : None , formatter : None , level : None , console : None , fileoption : Some ( Box :: new ( FileSizeMode :: new ( "0200asyncsize.log" , 1 <<10 , 0 , false ) ) ) } ) . await ;
34
+ async_trace ! ( "this is async trace log" ) ;
35
+ async_debug ! ( "this is async debug log" ) ;
36
+ async_info ! ( "this is async info log" ) ;
37
+ async_warn ! ( "this is async warn log" ) ;
38
+ async_error ! ( "this is async error log" ) ;
39
+ async_fatal ! ( "this is async fatal log" ) ;
40
+ tokio:: time:: sleep ( tokio:: time:: Duration :: from_secs ( 3 ) ) . await ;
41
+ }
0 commit comments