From 5db0e60e17a923409e6ca55acdeb51509a25b420 Mon Sep 17 00:00:00 2001 From: Sebastian Rollen Date: Tue, 15 Jun 2021 21:03:39 -0400 Subject: [PATCH] emit logs in json --- Cargo.lock | 30 +++++++++++++++++++++++++++++- Cargo.toml | 3 ++- src/main.rs | 10 ++++++---- 3 files changed, 37 insertions(+), 6 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 7d55031..d453adb 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -697,6 +697,16 @@ dependencies = [ "version_check", ] +[[package]] +name = "gethostname" +version = "0.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e692e296bfac1d2533ef168d0b60ff5897b8b70a4009276834014dd8924cc028" +dependencies = [ + "libc", + "winapi 0.3.9", +] + [[package]] name = "getrandom" version = "0.1.16" @@ -1427,7 +1437,7 @@ dependencies = [ [[package]] name = "polygon-data-relay" -version = "1.2.3" +version = "1.2.4" dependencies = [ "actix-service", "actix-web", @@ -1444,6 +1454,7 @@ dependencies = [ "serde_json", "tokio 1.5.0", "tracing", + "tracing-bunyan-formatter", "tracing-log", "tracing-subscriber", ] @@ -2361,6 +2372,23 @@ dependencies = [ "syn", ] +[[package]] +name = "tracing-bunyan-formatter" +version = "0.2.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dce1eae70720bd6bb3944f7cf501761aeae658bd1f9293aa373c71a195064910" +dependencies = [ + "chrono", + "gethostname", + "log", + "serde 1.0.125", + "serde_json", + "tracing", + "tracing-core", + "tracing-log", + "tracing-subscriber", +] + [[package]] name = "tracing-core" version = "0.1.17" diff --git a/Cargo.toml b/Cargo.toml index 9856cd9..29f714a 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "polygon-data-relay" -version = "1.2.3" +version = "1.2.4" authors = ["Sebastian Rollen "] edition = "2018" @@ -24,3 +24,4 @@ tokio = {version = "1.2", features = ["macros", "rt-multi-thread"]} tracing = "0.1" tracing-log = "0.1" tracing-subscriber = "0.2" +tracing-bunyan-formatter = { version = "0.2.4", default-features = false } diff --git a/src/main.rs b/src/main.rs index fa7e93b..5d1e72e 100644 --- a/src/main.rs +++ b/src/main.rs @@ -8,14 +8,16 @@ use sentry_anyhow::capture_anyhow; use std::sync::mpsc::channel; use std::thread; use tracing::{debug, info, subscriber::set_global_default}; +use tracing_bunyan_formatter::{BunyanFormattingLayer, JsonStorageLayer}; use tracing_log::LogTracer; -use tracing_subscriber::{filter::EnvFilter, FmtSubscriber}; +use tracing_subscriber::{layer::SubscriberExt, Registry}; fn main() -> Result<()> { let _ = dotenv(); - let subscriber = FmtSubscriber::builder() - .with_env_filter(EnvFilter::from_default_env()) - .finish(); + let formatting_layer = BunyanFormattingLayer::new("polygon-data-relay".into(), std::io::stdout); + let subscriber = Registry::default() + .with(JsonStorageLayer) + .with(formatting_layer); set_global_default(subscriber).expect("Failed to set subscriber"); LogTracer::init().expect("Failed to set logger"); let settings = Settings::new()?;