Skip to content

Commit

Permalink
Fixed inconsistency with writing of message variable
Browse files Browse the repository at this point in the history
  • Loading branch information
Yuri6037 committed Mar 24, 2024
1 parent 7cbada0 commit 325380c
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 9 deletions.
9 changes: 2 additions & 7 deletions src/profiler/logpump.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,7 @@ use crate::profiler::log_msg::EventLog;
use crate::profiler::network_types as nt;
use crate::profiler::state::send_message;
use log::{Log, Metadata, Record};
use std::fmt::Write;
use time::OffsetDateTime;
use crate::profiler::network_types::log::Formatter;

pub struct LogPump;

Expand All @@ -58,17 +56,14 @@ impl Log for LogPump {

fn log(&self, record: &Record) {
let (target, module) = extract_target_module(record);
let mut msg = EventLog::new(
let msg = EventLog::new(
None,
OffsetDateTime::now_utc().unix_timestamp(),
nt::message::Level::from_log(record.level()),
module.unwrap_or("main"),
target
);
{
let mut formatter = Formatter::new(&mut msg);
let _ = write!(formatter, "{}", record.args());
}
nt::log::Field::new("message", record.args());
send_message(&msg);
}

Expand Down
13 changes: 11 additions & 2 deletions src/profiler/network_types/log.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use std::fmt::{Debug, Write};
use std::fmt::{Debug, Display, Write};
use bytesutil::WriteTo;
use crate::profiler::log_msg::Log;

Expand Down Expand Up @@ -66,6 +66,15 @@ impl FieldValue for i64 {
}
}

impl<D: Display> FieldValue for &D {
fn write_field<W: Log>(&self, log: &mut W) -> std::io::Result<()> {
FieldType::STR.write_field(log)?;
let mut formatter = Formatter::new(log);
let _ = write!(formatter, "{}", self);
Ok(())
}
}

impl FieldValue for &dyn Debug {
fn write_field<W: Log>(&self, log: &mut W) -> std::io::Result<()> {
FieldType::STR.write_field(log)?;
Expand Down Expand Up @@ -116,7 +125,7 @@ impl<'a, V: FieldValue> Field<'a, V> {
}

pub fn write_into<W: Log>(self, log: &mut W) {
{
if self.name != "message"{
//rust is too stupid to understand that formatter is not after write_str
let mut formatter = Formatter::new(log);
let _ = formatter.write_str(self.name);
Expand Down

0 comments on commit 325380c

Please sign in to comment.