File: test_windows_line_ending.rs

package info (click to toggle)
rust-flexi-logger 0.29.8-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 1,084 kB
  • sloc: makefile: 2
file content (62 lines) | stat: -rw-r--r-- 2,017 bytes parent folder | download
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
mod test_utils;

use flexi_logger::{detailed_format, FileSpec, Logger, LoggerHandle};
use log::*;

#[test]
fn test_mods() {
    let handle: LoggerHandle = Logger::try_with_env_or_str(
        "info, test_windows_line_ending::mymod1=debug, test_windows_line_ending::mymod2=error",
    )
    .unwrap()
    .format(detailed_format)
    .log_to_file(
        FileSpec::default()
            .suppress_timestamp()
            .directory(self::test_utils::dir()),
    )
    .use_windows_line_ending()
    .start()
    .unwrap_or_else(|e| panic!("Logger initialization failed with {e}"));

    error!("This is an error message");
    warn!("This is a warning");
    info!("This is an info message");
    debug!("This is a debug message - you must not see it!");
    trace!("This is a trace message - you must not see it!");

    mymod1::test_traces();
    mymod2::test_traces();

    handle.validate_logs(&[
        ("ERROR", "test_windows_line_ending", "error"),
        ("WARN", "test_windows_line_ending", "warning"),
        ("INFO", "test_windows_line_ending", "info"),
        ("ERROR", "test_windows_line_ending", "error"),
        ("WARN", "test_windows_line_ending", "warning"),
        ("INFO", "test_windows_line_ending", "info"),
        ("DEBUG", "test_windows_line_ending", "debug"),
        ("ERROR", "test_windows_line_ending", "error"),
    ]);
}

mod mymod1 {
    use log::*;
    pub fn test_traces() {
        error!("This is an error message");
        warn!("This is a warning");
        info!("This is an info message");
        debug!("This is a debug message");
        trace!("This is a trace message - you must not see it!");
    }
}
mod mymod2 {
    use log::*;
    pub fn test_traces() {
        error!("This is an error message");
        warn!("This is a warning - you must not see it!");
        info!("This is an info message - you must not see it!");
        debug!("This is a debug message - you must not see it!");
        trace!("This is a trace message - you must not see it!");
    }
}