You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Binary tests don't have cfg(test) set, so they log to user log file
($HOME/.local/share/meli/meli.log by default).
Change StderrLogger constructor to allow for passing a test boolean
argument.
Signed-off-by: Manos Pitsidianakis <[email protected]>
Copy file name to clipboardExpand all lines: melib/src/utils/logging.rs
+77-43Lines changed: 77 additions & 43 deletions
Original file line number
Diff line number
Diff line change
@@ -19,10 +19,10 @@
19
19
* along with meli. If not, see <http://www.gnu.org/licenses/>.
20
20
*/
21
21
22
-
#[cfg(not(test))]
23
-
use std::fs::{File,OpenOptions};
24
22
use std::{
23
+
fs::{File,OpenOptions},
25
24
io::{BufWriter,Write},
25
+
ops::DerefMut,
26
26
path::PathBuf,
27
27
sync::{
28
28
atomic::{AtomicU8,Ordering},
@@ -134,11 +134,35 @@ pub enum Destination {
134
134
None,
135
135
}
136
136
137
+
enumWriter{
138
+
Stderr(BufWriter<std::io::Stderr>),
139
+
File(BufWriter<std::fs::File>),
140
+
}
141
+
142
+
impl std::ops::DerefforWriter{
143
+
typeTarget = dyn std::io::Write;
144
+
145
+
#[inline]
146
+
fnderef(&self) -> &Self::Target{
147
+
matchself{
148
+
Self::Stderr(ref inner) => inner,
149
+
Self::File(ref inner) => inner,
150
+
}
151
+
}
152
+
}
153
+
154
+
impl std::ops::DerefMutforWriter{
155
+
#[inline]
156
+
fnderef_mut(&mutself) -> &mutSelf::Target{
157
+
matchself{
158
+
Self::Stderr(refmut inner) => inner,
159
+
Self::File(refmut inner) => inner,
160
+
}
161
+
}
162
+
}
163
+
137
164
structFileOutput{
138
-
#[cfg(test)]
139
-
writer:BufWriter<std::io::Stderr>,
140
-
#[cfg(not(test))]
141
-
writer:BufWriter<std::fs::File>,
165
+
writer:Writer,
142
166
path:PathBuf,
143
167
}
144
168
@@ -169,13 +193,23 @@ impl Default for StderrLogger {
0 commit comments