feat(zlog): add tests
Some checks failed
Build Zenyx ⚡ / 🔧 Setup Environment (push) Failing after 52s
Build Zenyx ⚡ / 🏗️ Build aarch64-unknown-linux-gnu (push) Has been skipped
Build Zenyx ⚡ / 🏗️ Build x86_64-unknown-linux-gnu (push) Has been skipped
Build Zenyx ⚡ / 🏗️ Build x86_64-pc-windows-msvc (push) Has been skipped
Build Zenyx ⚡ / 🔧 Setup Environment (pull_request) Failing after 55s
Build Zenyx ⚡ / 🏗️ Build aarch64-unknown-linux-gnu (pull_request) Has been skipped
Build Zenyx ⚡ / 🏗️ Build x86_64-unknown-linux-gnu (pull_request) Has been skipped
Build Zenyx ⚡ / 🏗️ Build x86_64-pc-windows-msvc (pull_request) Has been skipped
Some checks failed
Build Zenyx ⚡ / 🔧 Setup Environment (push) Failing after 52s
Build Zenyx ⚡ / 🏗️ Build aarch64-unknown-linux-gnu (push) Has been skipped
Build Zenyx ⚡ / 🏗️ Build x86_64-unknown-linux-gnu (push) Has been skipped
Build Zenyx ⚡ / 🏗️ Build x86_64-pc-windows-msvc (push) Has been skipped
Build Zenyx ⚡ / 🔧 Setup Environment (pull_request) Failing after 55s
Build Zenyx ⚡ / 🏗️ Build aarch64-unknown-linux-gnu (pull_request) Has been skipped
Build Zenyx ⚡ / 🏗️ Build x86_64-unknown-linux-gnu (pull_request) Has been skipped
Build Zenyx ⚡ / 🏗️ Build x86_64-pc-windows-msvc (pull_request) Has been skipped
This commit is contained in:
parent
9f8633ff62
commit
c8f8863940
1 changed files with 51 additions and 0 deletions
|
@ -1,5 +1,7 @@
|
|||
use pretty_assertions::assert_eq;
|
||||
use tracing::Level;
|
||||
use serde_json::Map;
|
||||
use serde::{Serialize, Deserialize};
|
||||
|
||||
use super::*;
|
||||
|
||||
|
@ -90,3 +92,52 @@ fn test_logger_sequential_consistency() {
|
|||
counts.dedup();
|
||||
assert_eq!(counts.len(), 4096 * 128, "Found duplicate log entries");
|
||||
}
|
||||
|
||||
struct LogJsonStructure {
|
||||
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_logger_sequential_consistency_json() {
|
||||
use std::sync::atomic::{AtomicUsize, Ordering};
|
||||
|
||||
use tracing::{debug, error, info, trace, warn};
|
||||
|
||||
let config = LoggerConfig::default()
|
||||
.log_to_stdout(false)
|
||||
.log_to_file(false)
|
||||
.log_use_json(true)
|
||||
.log_json_show_timestamp(true)
|
||||
.log_json_show_level(true)
|
||||
.log_json_show_message(true)
|
||||
.log_json_show_additional_fields(false); // Not implemented yet
|
||||
let logger = Logger::new(config);
|
||||
|
||||
static COUNTER: AtomicUsize = AtomicUsize::new(0);
|
||||
|
||||
for i in 0..4096 * 128 {
|
||||
let count = COUNTER.fetch_add(1, Ordering::SeqCst);
|
||||
match i % 5 {
|
||||
0 => error!("Error message {}", count),
|
||||
1 => warn!("Warning message {}", count),
|
||||
2 => info!("Info message {}", count),
|
||||
3 => debug!("Debug message {}", count),
|
||||
_ => trace!("Trace message {}", count),
|
||||
}
|
||||
}
|
||||
|
||||
let mut log_json: Vec<Map<String, Value>> = vec![];
|
||||
|
||||
for log in logger.get_logs(LogQuery::All) {
|
||||
let mut json_object = serde_json::Map::new();
|
||||
json_object.insert("timestamp".to_string(), Value::String(DateTime::<Utc>::from(log.timestamp).to_rfc3339()));
|
||||
json_object.insert("level".to_string(), Value::String(log.level.to_string()));
|
||||
json_object.insert("message".to_string(), Value::String(log.message.to_string()));
|
||||
|
||||
log_json.push(json_object);
|
||||
}
|
||||
|
||||
for log in log_json {
|
||||
serde_json::to_string(&log).unwrap();
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue