Skip to content

Commit

Permalink
fix: fallback-logger depends on bug to work
Browse files Browse the repository at this point in the history
`fallback-logger` will recoginze one line as two lines when
`logger.append` was called with `msg` ends with `\n`, `\r` or `\0`. This
commit fixes `fallback-logger`'s wrong asuumption, so it works correctly
with last commit's bug fix.
  • Loading branch information
sisungo committed Jun 16, 2024
1 parent c05f457 commit 6b2f83e
Showing 1 changed file with 13 additions and 15 deletions.
28 changes: 13 additions & 15 deletions extensions/fallback-logger/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,21 +25,19 @@ async fn append(subject: String, module: String, msg: Vec<u8>) -> Result<(), Err
})?;
let timestamp = airupfx::time::timestamp_ms();

for m in msg.split(|x| b"\r\n\0".contains(x)) {
let record = LogRecord {
timestamp,
module: module.to_owned(),
message: String::from_utf8_lossy(m).into_owned(),
};
writeln!(
appender,
"{}",
serde_json::to_string(&record).unwrap().as_str()
)
.map_err(|x| airup_sdk::Error::Io {
message: x.to_string(),
})?;
}
let record = LogRecord {
timestamp,
module: module.to_owned(),
message: String::from_utf8_lossy(&msg).into_owned(),
};
writeln!(
appender,
"{}",
serde_json::to_string(&record).unwrap().as_str()
)
.map_err(|x| airup_sdk::Error::Io {
message: x.to_string(),
})?;

Ok(())
}
Expand Down

0 comments on commit 6b2f83e

Please sign in to comment.