Skip to content

Commit 208b82e

Browse files
committed
logging: change remote log serialization format to string for more efficient sending
1 parent ba37036 commit 208b82e

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

src/logging.rs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,14 @@ pub struct TerminalWriterMaker {
4242

4343
impl std::io::Write for RemoteWriter {
4444
fn write(&mut self, buf: &[u8]) -> std::io::Result<usize> {
45-
let body = serde_json::json!({"Log": buf});
45+
let log = if let Ok(json_log) = serde_json::from_slice(buf) {
46+
serde_json::to_string(&json_log).unwrap()
47+
} else {
48+
let string = String::from_utf8(buf.to_vec())
49+
.map_err(|e| std::io::Error::new(std::io::ErrorKind::InvalidData, e))?;
50+
string
51+
};
52+
let body = serde_json::json!({"Log": log});
4653
let body = serde_json::to_vec(&body).unwrap();
4754
Request::to(&self.target).body(body).send().unwrap();
4855
Ok(buf.len())

0 commit comments

Comments
 (0)