Skip to content

Commit

Permalink
fixup! plugin: allow to exectute in an async way
Browse files Browse the repository at this point in the history
Signed-off-by: Vincenzo Palazzo <[email protected]>
  • Loading branch information
vincenzopalazzo committed Apr 7, 2024
1 parent 9a2ade3 commit 2ac9518
Showing 1 changed file with 7 additions and 8 deletions.
15 changes: 7 additions & 8 deletions plugin/src/plugin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -66,11 +66,13 @@ impl log::Log for Log {
}

fn log(&self, record: &Record) {
use std::io::Write;

if self.enabled(record.metadata()) {
let level: LogLevel = record.level().into();
let msg = record.args();

let mut writer = io::stdout();
let mut writer = std::io::stdout();
let mut payload = init_payload();
add_str(&mut payload, "level", &level.to_string());
add_str(&mut payload, "message", &format!("{msg}"));
Expand All @@ -81,13 +83,10 @@ impl log::Log for Log {
params: payload,
};

let _ = tokio::task::spawn(async move {
writer
.write_all(serde_json::to_string(&request).unwrap().as_bytes())
.await
.unwrap();
writer.flush().await.unwrap();
});
writer
.write_all(serde_json::to_string(&request).unwrap().as_bytes())
.unwrap();
writer.flush().unwrap();
}
}

Expand Down

0 comments on commit 2ac9518

Please sign in to comment.