Skip to content

feat(pyth-lazer-agent) Make the logging format configurable #2880

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Jul 22, 2025
Merged
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
57 changes: 42 additions & 15 deletions apps/pyth-lazer-agent/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
use serde::Deserialize;
use {
crate::lazer_publisher::LazerPublisher,
anyhow::Context,
Expand All @@ -14,38 +15,64 @@
mod relayer_session;
mod websocket_utils;

#[derive(Parser)]
#[derive(Parser, Deserialize)]
#[serde(rename_all = "kebab-case")]
#[command(version)]
struct Cli {
#[clap(short, long, default_value = "config/config.toml")]
config: String,
#[clap(short, long, default_value = "json")]
log_format: LogFormat,
}

#[derive(clap::ValueEnum, Clone, Deserialize, Default)]
#[serde(rename_all = "kebab-case")]
enum LogFormat {
#[default]
Json,
Compact,
Pretty,
}

#[tokio::main]
async fn main() -> anyhow::Result<()> {
let args = Cli::parse();
init_tracing_subscriber(args.log_format);

let config =
config::load_config(args.config.to_string()).context("Failed to read config file")?;
info!(?config, "starting lazer-agent");

let lazer_publisher = LazerPublisher::new(&config).await;
http_server::run(config, lazer_publisher).await?;

Ok(())
}

Check warning on line 50 in apps/pyth-lazer-agent/src/main.rs

View workflow job for this annotation

GitHub Actions / pyth-lazer-agent Rust Test Suite

Diff in /home/runner/work/pyth-crosschain/pyth-crosschain/apps/pyth-lazer-agent/src/main.rs

fn init_tracing_subscriber(log_format: LogFormat) {

#[allow(
clippy::expect_used,
reason = "application can fail on invalid RUST_LOG"
)]
tracing_subscriber::fmt()
let subscriber = tracing_subscriber::fmt()
.with_env_filter(
EnvFilter::builder()
.with_default_directive(LevelFilter::INFO.into())
.from_env()
.expect("invalid RUST_LOG env var"),
)
.with_span_events(FmtSpan::NONE)
.json()
.with_span_list(false)
.init();

let args = Cli::parse();
let config =
config::load_config(args.config.to_string()).context("Failed to read config file")?;
info!(?config, "starting lazer-agent");

let lazer_publisher = LazerPublisher::new(&config).await;
http_server::run(config, lazer_publisher).await?;
.with_span_events(FmtSpan::NONE);

Ok(())
match log_format {
LogFormat::Json => {
subscriber.json().with_span_list(false).init();
}
LogFormat::Compact => {
subscriber.compact().init();
}
LogFormat::Pretty => {
subscriber.pretty().init();
}
}
}
Loading