Skip to content

Commit 5707c33

Browse files
authored
Merge pull request #146 from hyperware-ai/hf/logging-remote-log-to-string
logging: change remote log serialization format to string for more efficient sending
2 parents ba37036 + 451d4b5 commit 5707c33

File tree

2 files changed

+9
-1
lines changed

2 files changed

+9
-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::<serde_json::Value>(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())

src/vfs/file.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ use crate::{get_blob, PackageId};
66
/// VFS (Virtual File System) helper struct for a file.
77
/// Opening or creating a `File` will give you a `Result<File, VfsError>`.
88
/// You can call its impl functions to interact with it.
9+
#[derive(serde::Deserialize, serde::Serialize)]
910
pub struct File {
1011
pub path: String,
1112
pub timeout: u64,

0 commit comments

Comments
 (0)