Skip to content

Commit 325380c

Browse files
committed
Fixed inconsistency with writing of message variable
1 parent 7cbada0 commit 325380c

File tree

2 files changed

+13
-9
lines changed

2 files changed

+13
-9
lines changed

src/profiler/logpump.rs

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -33,9 +33,7 @@ use crate::profiler::log_msg::EventLog;
3333
use crate::profiler::network_types as nt;
3434
use crate::profiler::state::send_message;
3535
use log::{Log, Metadata, Record};
36-
use std::fmt::Write;
3736
use time::OffsetDateTime;
38-
use crate::profiler::network_types::log::Formatter;
3937

4038
pub struct LogPump;
4139

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

5957
fn log(&self, record: &Record) {
6058
let (target, module) = extract_target_module(record);
61-
let mut msg = EventLog::new(
59+
let msg = EventLog::new(
6260
None,
6361
OffsetDateTime::now_utc().unix_timestamp(),
6462
nt::message::Level::from_log(record.level()),
6563
module.unwrap_or("main"),
6664
target
6765
);
68-
{
69-
let mut formatter = Formatter::new(&mut msg);
70-
let _ = write!(formatter, "{}", record.args());
71-
}
66+
nt::log::Field::new("message", record.args());
7267
send_message(&msg);
7368
}
7469

src/profiler/network_types/log.rs

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use std::fmt::{Debug, Write};
1+
use std::fmt::{Debug, Display, Write};
22
use bytesutil::WriteTo;
33
use crate::profiler::log_msg::Log;
44

@@ -66,6 +66,15 @@ impl FieldValue for i64 {
6666
}
6767
}
6868

69+
impl<D: Display> FieldValue for &D {
70+
fn write_field<W: Log>(&self, log: &mut W) -> std::io::Result<()> {
71+
FieldType::STR.write_field(log)?;
72+
let mut formatter = Formatter::new(log);
73+
let _ = write!(formatter, "{}", self);
74+
Ok(())
75+
}
76+
}
77+
6978
impl FieldValue for &dyn Debug {
7079
fn write_field<W: Log>(&self, log: &mut W) -> std::io::Result<()> {
7180
FieldType::STR.write_field(log)?;
@@ -116,7 +125,7 @@ impl<'a, V: FieldValue> Field<'a, V> {
116125
}
117126

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

0 commit comments

Comments
 (0)