Skip to content

Commit

Permalink
updated log format
Browse files Browse the repository at this point in the history
  • Loading branch information
SebRollen committed Jun 16, 2021
1 parent a97fa4b commit ed333f6
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 24 deletions.
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "polygon-data-relay"
version = "1.2.4"
version = "1.2.5"
authors = ["Sebastian Rollen <[email protected]>"]
edition = "2018"

Expand Down
21 changes: 10 additions & 11 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,15 @@ 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::{layer::SubscriberExt, Registry};
use tracing_subscriber::EnvFilter;

fn main() -> Result<()> {
let _ = dotenv();
let formatting_layer = BunyanFormattingLayer::new("polygon-data-relay".into(), std::io::stdout);
let subscriber = Registry::default()
.with(JsonStorageLayer)
.with(formatting_layer);
let subscriber = tracing_subscriber::fmt()
.json()
.with_env_filter(EnvFilter::from_default_env())
.finish();
set_global_default(subscriber).expect("Failed to set subscriber");
LogTracer::init().expect("Failed to set logger");
let settings = Settings::new()?;
Expand All @@ -28,25 +27,25 @@ fn main() -> Result<()> {
..Default::default()
},
));
info!("Starting polygon-data-relay");
info!("Starting");

let mut data: Vec<&str> = vec![];

if settings.polygon.quotes {
data.push("Q");
debug!("Will subscribe to Quotes");
debug!(subscription = "Quotes", "Subscribing");
}
if settings.polygon.trades {
data.push("T");
debug!("Will subscribe to Trades");
debug!(subscription = "Trades", "Subscribing");
}
if settings.polygon.second_aggregates {
data.push("A");
debug!("Will subscribe to SecondAggregates");
debug!(subscription = "SecondAggregates", "Subscribing");
}
if settings.polygon.minute_aggregates {
data.push("AM");
debug!("Will subscribe to MinuteAggregates");
debug!(subscription = "MinuteAggregates", "Subscribing");
}

let (tx, rx) = channel();
Expand Down
17 changes: 6 additions & 11 deletions src/relay.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,10 +47,7 @@ pub async fn run(
let payload = serde_json::to_string(&polygon_message);
match payload {
Ok(payload) => {
debug!(
"Message received: {}. Assigning key: {}, sending to topic: {}",
&payload, &key, &topic
);
debug!(?polygon_message, ?key, ?topic);
let res = producer
.send(
FutureRecord::to(topic).key(key).payload(&payload),
Expand All @@ -60,23 +57,21 @@ pub async fn run(
if let Err((e, msg)) = res {
let e = e.into();
sentry_anyhow::capture_anyhow(&e);
error!(
"Failed to send message to kafka. Message: {:?}\nError: {}",
msg, e
)
error!(?msg, %e)
}
}
Err(e) => {
sentry_anyhow::capture_anyhow(&e.into());
error!("Failed to serialize payload: {:?}", &polygon_message)
let e = e.into();
sentry_anyhow::capture_anyhow(&e);
error!(%e, ?polygon_message)
}
}
}
Err(e) => match e {
polygon::errors::Error::Serde { .. } => {
let e = e.into();
sentry_anyhow::capture_anyhow(&e);
error!("Failed to reveive message from the WebSocket: {}", e)
error!(%e)
}
_ => panic!("Failed to receive message from the WebSocket: {}", e),
},
Expand Down

0 comments on commit ed333f6

Please sign in to comment.