-
Notifications
You must be signed in to change notification settings - Fork 255
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* feat: simple wasm log to send over unix socket * feat: hook up logs subscription * refactor: extra comments * refactor: simpler interface * refactor: combine JsonVisitors * refactor: clippy suggestions * refactor: update tests * refactor: extra comment * refactor: increase channel for better performance * refactor: move off stderr
- Loading branch information
Showing
15 changed files
with
640 additions
and
159 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
use serde_json::json; | ||
use tracing::field::Visit; | ||
|
||
// Boilerplate for extracting the fields from the event | ||
#[derive(Default)] | ||
pub struct JsonVisitor { | ||
pub fields: serde_json::Map<String, serde_json::Value>, | ||
pub target: Option<String>, | ||
pub file: Option<String>, | ||
pub line: Option<u32>, | ||
} | ||
|
||
impl JsonVisitor { | ||
/// Ignores log metadata as it is included in the other LogItem fields (target, file, line...) | ||
fn filter_insert(&mut self, field: &tracing::field::Field, value: serde_json::Value) { | ||
match field.name() { | ||
"log.line" => self.line = value.as_u64().map(|u| u as u32), | ||
"log.target" => self.target = value.as_str().map(ToOwned::to_owned), | ||
"log.file" => self.file = value.as_str().map(ToOwned::to_owned), | ||
"log.module_path" => {} | ||
name => { | ||
self.fields.insert(name.to_string(), json!(value)); | ||
} | ||
} | ||
} | ||
} | ||
impl Visit for JsonVisitor { | ||
fn record_str(&mut self, field: &tracing::field::Field, value: &str) { | ||
self.filter_insert(field, json!(value)); | ||
} | ||
fn record_bool(&mut self, field: &tracing::field::Field, value: bool) { | ||
self.filter_insert(field, json!(value)); | ||
} | ||
fn record_u64(&mut self, field: &tracing::field::Field, value: u64) { | ||
self.filter_insert(field, json!(value)); | ||
} | ||
fn record_i64(&mut self, field: &tracing::field::Field, value: i64) { | ||
self.filter_insert(field, json!(value)); | ||
} | ||
fn record_f64(&mut self, field: &tracing::field::Field, value: f64) { | ||
self.filter_insert(field, json!(value)); | ||
} | ||
fn record_error( | ||
&mut self, | ||
field: &tracing::field::Field, | ||
value: &(dyn std::error::Error + 'static), | ||
) { | ||
self.filter_insert(field, json!(value.to_string())); | ||
} | ||
fn record_debug(&mut self, field: &tracing::field::Field, value: &dyn std::fmt::Debug) { | ||
self.filter_insert(field, json!(format!("{value:?}"))); | ||
} | ||
} |
Oops, something went wrong.