refactored formatted scripts
Some checks failed
Build Zenyx ⚡ / 🧪 Run Cargo Tests (pull_request) Failing after 3m47s
Build Zenyx ⚡ / 🏗️ Build aarch64-apple-darwin (pull_request) Has been skipped
Build Zenyx ⚡ / 🏗️ Build aarch64-pc-windows-msvc (pull_request) Has been skipped
Build Zenyx ⚡ / 🏗️ Build aarch64-unknown-linux-gnu (pull_request) Has been skipped
Build Zenyx ⚡ / 🏗️ Build x86_64-apple-darwin (pull_request) Has been skipped
Build Zenyx ⚡ / 🏗️ Build x86_64-pc-windows-msvc (pull_request) Has been skipped
Build Zenyx ⚡ / 🏗️ Build x86_64-unknown-linux-gnu (pull_request) Has been skipped
Some checks failed
Build Zenyx ⚡ / 🧪 Run Cargo Tests (pull_request) Failing after 3m47s
Build Zenyx ⚡ / 🏗️ Build aarch64-apple-darwin (pull_request) Has been skipped
Build Zenyx ⚡ / 🏗️ Build aarch64-pc-windows-msvc (pull_request) Has been skipped
Build Zenyx ⚡ / 🏗️ Build aarch64-unknown-linux-gnu (pull_request) Has been skipped
Build Zenyx ⚡ / 🏗️ Build x86_64-apple-darwin (pull_request) Has been skipped
Build Zenyx ⚡ / 🏗️ Build x86_64-pc-windows-msvc (pull_request) Has been skipped
Build Zenyx ⚡ / 🏗️ Build x86_64-unknown-linux-gnu (pull_request) Has been skipped
cpu struct types being worked on cpu error handling fixed moved from anyhow -> thiserror other shit i'm too tired to mention
This commit is contained in:
parent
528d4b03a3
commit
f8316f8ee4
32 changed files with 568 additions and 405 deletions
|
@ -74,7 +74,7 @@ impl LoggerConfig {
|
|||
self.log_json_show_message = i;
|
||||
self
|
||||
}
|
||||
|
||||
|
||||
pub fn log_json_show_additional_fields(mut self, i: bool) -> Self {
|
||||
self.log_json_show_additional_fields = i;
|
||||
self
|
||||
|
@ -96,7 +96,7 @@ impl Default for LoggerConfig {
|
|||
log_json_show_timestamp: false,
|
||||
log_json_show_level: false,
|
||||
log_json_show_message: false,
|
||||
log_json_show_additional_fields: false
|
||||
log_json_show_additional_fields: false,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -113,7 +113,7 @@ where
|
|||
level,
|
||||
message,
|
||||
#[cfg(feature = "json")]
|
||||
additional_fields
|
||||
additional_fields,
|
||||
});
|
||||
|
||||
if let LogEvent::Log(ref entry) = log_entry {
|
||||
|
@ -212,13 +212,7 @@ impl Logger {
|
|||
for msg in rx {
|
||||
match msg {
|
||||
LogEvent::Log(mut entry) => {
|
||||
println!(
|
||||
"{}",
|
||||
format_entry(
|
||||
&mut entry,
|
||||
&config_clone
|
||||
)
|
||||
);
|
||||
println!("{}", format_entry(&mut entry, &config_clone));
|
||||
}
|
||||
LogEvent::Shutdown => break,
|
||||
}
|
||||
|
@ -298,12 +292,12 @@ fn format_entry(entry: &mut LogEntry, log_config: &LoggerConfig) -> String {
|
|||
if log_config.log_use_json {
|
||||
return format_entry_json(entry, log_config);
|
||||
}
|
||||
|
||||
|
||||
if log_config.log_to_stdout || log_config.log_to_file {
|
||||
return format_entry_string(entry, log_config);
|
||||
} else {
|
||||
return String::new();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn format_entry_string(entry: &LogEntry, log_config: &LoggerConfig) -> String {
|
||||
|
@ -327,7 +321,10 @@ fn format_entry_json(entry: &mut LogEntry, log_config: &LoggerConfig) -> String
|
|||
let mut json_object = serde_json::Map::new();
|
||||
|
||||
if log_config.log_json_show_timestamp {
|
||||
json_object.insert("timestamp".to_string(), Value::String(DateTime::<Utc>::from(entry.timestamp).to_rfc3339()));
|
||||
json_object.insert(
|
||||
"timestamp".to_string(),
|
||||
Value::String(DateTime::<Utc>::from(entry.timestamp).to_rfc3339()),
|
||||
);
|
||||
}
|
||||
|
||||
if log_config.log_json_show_level {
|
||||
|
@ -335,7 +332,10 @@ fn format_entry_json(entry: &mut LogEntry, log_config: &LoggerConfig) -> String
|
|||
}
|
||||
|
||||
if log_config.log_json_show_message {
|
||||
json_object.insert("message".to_string(), Value::String(entry.message.to_string()));
|
||||
json_object.insert(
|
||||
"message".to_string(),
|
||||
Value::String(entry.message.to_string()),
|
||||
);
|
||||
}
|
||||
|
||||
if log_config.log_json_show_additional_fields {
|
||||
|
@ -343,4 +343,4 @@ fn format_entry_json(entry: &mut LogEntry, log_config: &LoggerConfig) -> String
|
|||
}
|
||||
|
||||
serde_json::to_string(&json_object).unwrap()
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
use pretty_assertions::assert_eq;
|
||||
use tracing::Level;
|
||||
use serde::{Deserialize, Serialize};
|
||||
use serde_json::Map;
|
||||
use serde::{Serialize, Deserialize};
|
||||
use tracing::Level;
|
||||
|
||||
use super::*;
|
||||
|
||||
|
@ -126,9 +126,15 @@ fn test_logger_sequential_consistency_json() {
|
|||
|
||||
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(
|
||||
"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()));
|
||||
json_object.insert(
|
||||
"message".to_string(),
|
||||
Value::String(log.message.to_string()),
|
||||
);
|
||||
|
||||
log_json.push(json_object);
|
||||
}
|
||||
|
@ -136,4 +142,4 @@ fn test_logger_sequential_consistency_json() {
|
|||
for log in log_json {
|
||||
serde_json::to_string(&log).unwrap();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue