Skip to content

Commit 9bb7e72

Browse files
committed
Configure logging level using RUST_LOG environment variable
1 parent 7312650 commit 9bb7e72

File tree

4 files changed

+59
-6
lines changed

4 files changed

+59
-6
lines changed

Cargo.lock

Lines changed: 44 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ thiserror = "1.0.32"
3636
solana-shadow = "0.2.4"
3737
clap = { version = "4.0.32", features = ["derive"] }
3838
humantime-serde = "1.1.1"
39+
slog-envlogger = "2.2.0"
3940

4041
[dev-dependencies]
4142
tokio-util = { version = "0.7.0", features = ["full"] }

integration-tests/tests/test_integration.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -307,6 +307,7 @@ def agent(self, sync_accounts, agent_keystore, tmp_path):
307307
LOGGER.debug("Launching agent logging to %s", log_dir)
308308

309309
os.environ["RUST_BACKTRACE"] = "full"
310+
os.environ["RUST_LOG"] = "debug"
310311
with self.spawn("../target/release/agent --config agent_conf.toml", log_dir=log_dir):
311312
time.sleep(3)
312313
yield

src/bin/agent.rs

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,11 @@ use {
1111
Drain,
1212
Logger,
1313
},
14-
std::path::PathBuf,
14+
slog_envlogger::LogBuilder,
15+
std::{
16+
env,
17+
path::PathBuf,
18+
},
1519
};
1620

1721
#[derive(Parser, Debug)]
@@ -26,12 +30,15 @@ struct Arguments {
2630
#[tokio::main]
2731
async fn main() {
2832
let logger = slog::Logger::root(
29-
slog_async::Async::new(
30-
slog_term::CompactFormat::new(slog_term::TermDecorator::new().build())
31-
.build()
32-
.fuse(),
33+
slog_async::Async::default(
34+
LogBuilder::new(
35+
slog_term::CompactFormat::new(slog_term::TermDecorator::new().stdout().build())
36+
.build()
37+
.fuse(),
38+
)
39+
.parse(&env::var("RUST_LOG").unwrap_or("info".to_string()))
40+
.build(),
3341
)
34-
.build()
3542
.fuse(),
3643
o!(),
3744
);

0 commit comments

Comments
 (0)