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 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138
|
mod test_utils;
use flexi_logger::{opt_format, FileSpec, Logger, WriteMode};
use log::*;
const COUNT: u8 = 12;
#[test]
fn test_write_modes() {
if let Some(value) = test_utils::dispatch(COUNT) {
work(value)
}
}
fn work(value: u8) {
let logger = Logger::try_with_str("info").unwrap().format(opt_format);
let logger = match value {
0 => {
println!("stdout, direct");
logger.log_to_stdout().write_mode(WriteMode::Direct)
}
1 => {
println!("stdout, buffer+flush");
logger.log_to_stdout().write_mode(WriteMode::BufferAndFlush)
}
2 => {
#[cfg(feature = "async")]
{
println!("stdout, async");
logger.log_to_stdout().write_mode(WriteMode::Async)
}
#[cfg(not(feature = "async"))]
{
println!("!!! nothing done !!!");
return;
}
}
3 => {
println!("stdout, buffer no flush");
logger
.log_to_stdout()
.write_mode(WriteMode::BufferDontFlush)
}
4 => {
println!("stderr, direct");
logger.log_to_stderr().write_mode(WriteMode::Direct)
}
5 => {
println!("stderr, buffer+flush");
logger.log_to_stderr().write_mode(WriteMode::BufferAndFlush)
}
6 => {
#[cfg(feature = "async")]
{
println!("stderr, async");
logger.log_to_stderr().write_mode(WriteMode::Async)
}
#[cfg(not(feature = "async"))]
{
println!("!!! nothing done !!!");
return;
}
}
7 => {
println!("stderr, buffer no flush");
logger
.log_to_stderr()
.write_mode(WriteMode::BufferDontFlush)
}
8 => {
println!("file, direct");
logger
.log_to_file(
FileSpec::default()
.suppress_timestamp()
.directory(self::test_utils::dir()),
)
.write_mode(WriteMode::Direct)
}
9 => {
println!("file, buffer+flush");
logger
.log_to_file(
FileSpec::default()
.suppress_timestamp()
.directory(self::test_utils::dir()),
)
.write_mode(WriteMode::BufferAndFlush)
}
10 => {
#[cfg(feature = "async")]
{
println!("file, async");
logger
.log_to_file(
FileSpec::default()
.suppress_timestamp()
.directory(self::test_utils::dir()),
)
.write_mode(WriteMode::Async)
}
#[cfg(not(feature = "async"))]
{
println!("!!! nothing done !!!");
return;
}
}
11 => {
println!("file, buffer no flush");
logger
.log_to_file(
FileSpec::default()
.suppress_timestamp()
.directory(self::test_utils::dir()),
)
.write_mode(WriteMode::BufferDontFlush)
}
COUNT..=u8::MAX => {
unreachable!("got unexpected value {}", value)
}
};
let handle = logger.start().unwrap_or_else(|e| panic!("{e}, {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!");
handle.validate_logs(&[
("ERROR", "test_write_mode", "error"),
("WARN", "test_write_mode", "warning"),
("INFO", "test_write_mode", "info"),
]);
}
|