@@ -9,17 +9,16 @@ mod a {
9
9
use std:: io:: Write ;
10
10
use tracing:: { debug, error, info, trace, warn} ;
11
11
12
- const WAIT_MILLIS : u64 = 2000 ;
12
+ const WAIT_MILLIS : u64 = 1_500 ;
13
13
14
- /// Test of the specfile feature
15
14
#[ test]
16
15
fn test_specfile ( ) {
17
16
let specfile = super :: test_utils:: file ( "logspec.toml" ) ;
18
17
19
18
std:: fs:: remove_file ( & specfile) . ok ( ) ;
20
19
assert ! ( !specfile. exists( ) ) ;
21
20
22
- let _keep_alive_handles = flexi_logger:: trc:: setup_tracing (
21
+ let keep_alive_handles = flexi_logger:: trc:: setup_tracing (
23
22
LogSpecification :: info ( ) ,
24
23
Some ( & specfile) ,
25
24
FileLogWriter :: builder ( FileSpec :: default ( ) . directory ( super :: test_utils:: dir ( ) ) )
@@ -39,11 +38,8 @@ mod a {
39
38
40
39
assert ! ( specfile. exists( ) ) ;
41
40
42
- error ! ( "This is an error-0" ) ;
43
- warn ! ( "This is a warning-0" ) ;
44
- info ! ( "This is an info-0" ) ;
45
- debug ! ( "This is a debug-0" ) ;
46
- trace ! ( "This is a trace-0" ) ;
41
+ write_logs ( 0 ) ;
42
+ super :: b:: write_logs ( 0 ) ;
47
43
48
44
eprintln ! (
49
45
"[{}] ===== behave like many editors: rename and recreate; set to warn" ,
@@ -60,20 +56,18 @@ mod a {
60
56
. unwrap ( ) ;
61
57
file. write_all (
62
58
b"
63
- global_level = 'warn'
64
- [modules]
59
+ global_level = 'warn'\n \
60
+ [modules]\n \
61
+ 'test_trc::b' = 'error'\n \
65
62
",
66
63
)
67
64
. unwrap ( ) ;
68
65
}
69
66
70
67
std:: thread:: sleep ( std:: time:: Duration :: from_millis ( WAIT_MILLIS ) ) ;
71
68
72
- error ! ( "This is an error-1" ) ;
73
- warn ! ( "This is a warning-1" ) ;
74
- info ! ( "This is an info-1" ) ;
75
- debug ! ( "This is a debug-1" ) ;
76
- trace ! ( "This is a trace-1" ) ;
69
+ write_logs ( 1 ) ;
70
+ super :: b:: write_logs ( 1 ) ;
77
71
78
72
eprintln ! (
79
73
"[{}] ===== truncate and rewrite; set to error" ,
@@ -89,6 +83,7 @@ mod a {
89
83
"\
90
84
global_level = 'error'\n \
91
85
[modules]\n \
86
+ 'test_trc::b' = 'debug'\n \
92
87
"
93
88
. as_bytes ( ) ,
94
89
)
@@ -97,10 +92,45 @@ mod a {
97
92
98
93
std:: thread:: sleep ( std:: time:: Duration :: from_millis ( WAIT_MILLIS ) ) ;
99
94
100
- error ! ( "This is an error-2" ) ;
101
- warn ! ( "This is a warning-2" ) ;
102
- info ! ( "This is an info-2" ) ;
103
- debug ! ( "This is a debug-2" ) ;
104
- trace ! ( "This is a trace-2" ) ;
95
+ write_logs ( 2 ) ;
96
+ super :: b:: write_logs ( 2 ) ;
97
+
98
+ std:: thread:: sleep ( std:: time:: Duration :: from_millis ( WAIT_MILLIS ) ) ;
99
+
100
+ keep_alive_handles. 0 . validate_logs ( & [
101
+ ( "ERROR" , "test_trc::a" , "0" ) ,
102
+ ( "WARN" , "test_trc::a" , "0" ) ,
103
+ ( "INFO" , "test_trc::a" , "0" ) ,
104
+ ( "ERROR" , "test_trc::b" , "0" ) ,
105
+ ( "WARN" , "test_trc::b" , "0" ) ,
106
+ ( "INFO" , "test_trc::b" , "0" ) ,
107
+ ( "ERROR" , "test_trc::a:" , "1" ) ,
108
+ ( "WARN" , "test_trc::a:" , "1" ) ,
109
+ ( "ERROR" , "test_trc::b:" , "1" ) ,
110
+ ( "ERROR" , "test_trc::a:" , "2" ) ,
111
+ ( "ERROR" , "test_trc::b:" , "2" ) ,
112
+ ( "WARN" , "test_trc::b:" , "2" ) ,
113
+ ( "INFO" , "test_trc::b:" , "2" ) ,
114
+ ( "DEBUG" , "test_trc::b:" , "2" ) ,
115
+ ] ) ;
116
+ }
117
+
118
+ pub ( crate ) fn write_logs ( idx : u8 ) {
119
+ error ! ( "Error from a::write_logs {idx}" ) ;
120
+ warn ! ( "Warning from a::write_logs {idx}" ) ;
121
+ info ! ( "Info from a::write_logs {idx}" ) ;
122
+ debug ! ( "Debug from a::write_logs {idx}" ) ;
123
+ trace ! ( "Trace from a::write_logs {idx}" ) ;
124
+ }
125
+ }
126
+ mod b {
127
+ use tracing:: { debug, error, info, trace, warn} ;
128
+
129
+ pub ( crate ) fn write_logs ( idx : u8 ) {
130
+ error ! ( "Error from b::write_logs {idx}" ) ;
131
+ warn ! ( "Warning from b::write_logs {idx}" ) ;
132
+ info ! ( "Info from b::write_logs {idx}" ) ;
133
+ debug ! ( "Debug from b::write_logs {idx}" ) ;
134
+ trace ! ( "Trace from b::write_logs {idx}" ) ;
105
135
}
106
136
}
0 commit comments