MCPcopy Create free account
hub / github.com/aws/amazon-q-developer-cli / test_logging

Function test_logging

crates/chat-cli/src/logging.rs:275–312  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

273
274 #[test]
275 fn test_logging() {
276 // Create a temp path for where we write logs to.
277 let tempdir = tempfile::TempDir::new().unwrap();
278 let log_path = tempdir.path().join("test.log");
279
280 // Assert that initialize logging simply doesn't panic.
281 let _guard = initialize_logging(LogArgs {
282 log_level: Some("trace".to_owned()),
283 log_to_stdout: true,
284 log_file_path: Some(&log_path),
285 delete_old_log_file: true,
286 })
287 .unwrap();
288
289 // Test that get log level functions as expected.
290 assert_eq!(get_log_level(), "trace");
291
292 // Write some log messages out to file. (and stderr)
293 trace!("abc");
294 debug!("def");
295 info!("ghi");
296 warn!("jkl");
297 error!("mno");
298
299 // Test that set log level functions as expected.
300 // This also restores the default log level.
301 set_log_level(DEFAULT_FILTER.to_string()).unwrap();
302 assert_eq!(get_log_level(), DEFAULT_FILTER.to_string());
303
304 // Sleep in order to ensure logs get written to file, then assert on the contents
305 std::thread::sleep(Duration::from_millis(100));
306 let logs = read_to_string(&log_path).unwrap();
307 for i in [
308 "TRACE", "DEBUG", "INFO", "WARN", "ERROR", "abc", "def", "ghi", "jkl", "mno",
309 ] {
310 assert!(logs.contains(i));
311 }
312 }
313}

Callers

nothing calls this directly

Calls 5

initialize_loggingFunction · 0.85
set_log_levelFunction · 0.85
joinMethod · 0.80
to_stringMethod · 0.80
pathMethod · 0.45

Tested by

no test coverage detected