libs/logging: fix clippy warnings

Fix clippy warnings of libs/logging.

Signed-off-by: Liu Jiang <gerry@linux.alibaba.com>
This commit is contained in:
Liu Jiang 2022-01-07 13:46:24 +08:00 committed by Fupan Li
parent 6f8acb94c2
commit 4f62a7618c
3 changed files with 22 additions and 22 deletions

View File

@ -264,13 +264,13 @@ mod tests {
rotator.rotate_count(1);
assert_eq!(rotator.rotate_size, 4);
assert_eq!(rotator.rotate_keep, 1);
assert_eq!(rotator.truncate, false);
assert!(!rotator.truncate);
rotator.write("test".as_bytes()).unwrap();
rotator.write_all("test".as_bytes()).unwrap();
rotator.flush().unwrap();
rotator.write("test1".as_bytes()).unwrap();
rotator.write_all("test1".as_bytes()).unwrap();
rotator.flush().unwrap();
rotator.write("t2".as_bytes()).unwrap();
rotator.write_all("t2".as_bytes()).unwrap();
rotator.flush().unwrap();
let content = fs::read_to_string(path).unwrap();
@ -298,16 +298,16 @@ mod tests {
rotator.rotate_count(1);
rotator.fail_rename = true;
rotator.write("test".as_bytes()).unwrap();
rotator.write_all("test".as_bytes()).unwrap();
rotator.flush().unwrap();
let size1 = path.metadata().unwrap().size();
rotator.write("test1".as_bytes()).unwrap();
rotator.write_all("test1".as_bytes()).unwrap();
rotator.flush().unwrap();
let size2 = path.metadata().unwrap().size();
assert!(size2 > size1);
rotator.write("test2".as_bytes()).unwrap();
rotator.write_all("test2".as_bytes()).unwrap();
rotator.flush().unwrap();
let size3 = path.metadata().unwrap().size();
assert!(size3 > size2);

View File

@ -534,13 +534,13 @@ mod tests {
let msg = format!("test[{}]", i);
// Create a writer for the logger drain to use
let writer =
NamedTempFile::new().expect(&format!("{:}: failed to create tempfile", msg));
let writer = NamedTempFile::new()
.unwrap_or_else(|_| panic!("{:}: failed to create tempfile", msg));
// Used to check file contents before the temp file is unlinked
let mut writer_ref = writer
.reopen()
.expect(&format!("{:?}: failed to clone tempfile", msg));
.unwrap_or_else(|e| panic!("{:?}: failed to clone tempfile, {}", msg, e));
let (logger, logger_guard) = create_logger(name, source, d.slog_level, writer);
@ -554,52 +554,52 @@ mod tests {
let mut contents = String::new();
writer_ref
.read_to_string(&mut contents)
.expect(&format!("{:?}: failed to read tempfile contents", msg));
.unwrap_or_else(|e| panic!("{:?}: failed to read tempfile contents, {}", msg, e));
// Convert file to JSON
let fields: Value = serde_json::from_str(&contents)
.expect(&format!("{:?}: failed to convert logfile to json", msg));
.unwrap_or_else(|e| panic!("{:?}: failed to convert logfile to json, {}", msg, e));
// Check the expected JSON fields
let field_ts = fields
.get("ts")
.expect(&format!("{:?}: failed to find timestamp field", msg));
.unwrap_or_else(|| panic!("{:?}: failed to find timestamp field", msg));
assert_ne!(field_ts, "", "{}", msg);
let field_version = fields
.get("version")
.expect(&format!("{:?}: failed to find version field", msg));
.unwrap_or_else(|| panic!("{:?}: failed to find version field", msg));
assert_eq!(field_version, env!("CARGO_PKG_VERSION"), "{}", msg);
let field_pid = fields
.get("pid")
.expect(&format!("{:?}: failed to find pid field", msg));
.unwrap_or_else(|| panic!("{:?}: failed to find pid field", msg));
assert_ne!(field_pid, "", "{}", msg);
let field_level = fields
.get("level")
.expect(&format!("{:?}: failed to find level field", msg));
.unwrap_or_else(|| panic!("{:?}: failed to find level field", msg));
assert_eq!(field_level, d.slog_level_tag, "{}", msg);
let field_msg = fields
.get("msg")
.expect(&format!("{:?}: failed to find msg field", msg));
.unwrap_or_else(|| panic!("{:?}: failed to find msg field", msg));
assert_eq!(field_msg, &json!(d.msg), "{}", msg);
let field_name = fields
.get("name")
.expect(&format!("{:?}: failed to find name field", msg));
.unwrap_or_else(|| panic!("{:?}: failed to find name field", msg));
assert_eq!(field_name, name, "{}", msg);
let field_source = fields
.get("source")
.expect(&format!("{:?}: failed to find source field", msg));
.unwrap_or_else(|| panic!("{:?}: failed to find source field", msg));
assert_eq!(field_source, source, "{}", msg);
let field_subsystem = fields
.get("subsystem")
.expect(&format!("{:?}: failed to find subsystem field", msg));
.unwrap_or_else(|| panic!("{:?}: failed to find subsystem field", msg));
// No explicit subsystem, so should be the default
assert_eq!(field_subsystem, &json!(DEFAULT_SUBSYSTEM), "{}", msg);

View File

@ -54,9 +54,9 @@ mod tests {
let (logger, guard) = create_logger("test", "hi", slog::Level::Info, rotator);
let mut writer = LogWriter::new(logger);
writer.write("test1\nblabla".as_bytes()).unwrap();
writer.write_all("test1\nblabla".as_bytes()).unwrap();
writer.flush().unwrap();
writer.write("test2".as_bytes()).unwrap();
writer.write_all("test2".as_bytes()).unwrap();
writer.flush().unwrap();
drop(guard);