Skip to content

Commit

Permalink
Merge pull request #53 from flashbots/log-format
Browse files Browse the repository at this point in the history
Add log format json in args
  • Loading branch information
avalonche authored Jan 22, 2025
2 parents fff953d + 669a787 commit 81a9216
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 5 deletions.
3 changes: 2 additions & 1 deletion .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,5 @@ RPC_PORT=8081
TRACING=false
LOG_LEVEL=info
METRICS=false
BOOST_SYNC=false
BOOST_SYNC=false
LOG_FORMAT=text
24 changes: 20 additions & 4 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,10 @@ struct Args {
#[arg(long, env, default_value = "info")]
log_level: Level,

/// Log format
#[arg(long, env, default_value = "text")]
log_format: String,

/// Timeout for the builder client calls in milliseconds
#[arg(long, env, default_value = "200")]
builder_timeout: u64,
Expand All @@ -116,10 +120,22 @@ async fn main() -> Result<()> {
let args: Args = Args::parse();

// Initialize logging
tracing_subscriber::fmt()
.with_env_filter(EnvFilter::new(args.log_level.to_string())) // Set the log level
.with_ansi(false) // Disable colored logging
.init();
let log_format = args.log_format.to_lowercase();
let log_level = args.log_level.to_string();
if log_format == "json" {
// JSON log format
tracing_subscriber::fmt()
.json() // Use JSON format
.with_env_filter(EnvFilter::new(log_level)) // Set log level
.with_ansi(false) // Disable colored logging
.init();
} else {
// Default (text) log format
tracing_subscriber::fmt()
.with_env_filter(EnvFilter::new(log_level)) // Set log level
.with_ansi(false) // Disable colored logging
.init();
}

let metrics = if args.metrics {
let recorder = PrometheusBuilder::new().build_recorder();
Expand Down

0 comments on commit 81a9216

Please sign in to comment.