Skip to content

Commit fe43a4b

Browse files
authored
Add cast debug output (#3767)
<!-- Reference any GitHub issues resolved by this PR --> Closes #3207 Closes #2879 ## Introduced changes <!-- A brief description of the changes --> - Added support for logging in `sncast`. Currently no logs are emitted by cast itself but various dependencies, like starknet-rs emit them, and now they can be displayed by providing `SNCAST_LOG={trace level}` ## Checklist <!-- Make sure all of these are complete --> - [x] Linked relevant issue - [x] Updated relevant documentation - [x] Added relevant tests - [x] Performed self-review of the code - [x] Added changes to `CHANGELOG.md`
1 parent f14ba50 commit fe43a4b

File tree

7 files changed

+62
-0
lines changed

7 files changed

+62
-0
lines changed

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,12 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
1313

1414
- Updated the error message returned when calling a nonexistent method on a contract to better align with the format used by the network
1515

16+
### Cast
17+
18+
#### Added
19+
20+
- Debug logging for `sncast` commands that can be enabled by setting `CAST_LOG` env variable.
21+
1622
## [0.50.0] - 2025-09-29
1723

1824
### Forge

Cargo.lock

Lines changed: 3 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
@@ -125,3 +125,4 @@ chrono = "0.4.41"
125125
tracing-subscriber = { version = "0.3.20", features = ["env-filter"] }
126126
tracing = "0.1.41"
127127
tracing-chrome = "0.7.2"
128+
tracing-log = "0.2.0"

crates/sncast/Cargo.toml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,9 @@ toml_edit.workspace = true
5858
num-traits.workspace = true
5959
foundry-ui = { path = "../foundry-ui" }
6060
universal-sierra-compiler-api = { path = "../universal-sierra-compiler-api" }
61+
tracing-subscriber.workspace = true
62+
tracing.workspace = true
63+
tracing-log.workspace = true
6164

6265
[dev-dependencies]
6366
ctor.workspace = true

crates/sncast/src/main.rs

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -211,7 +211,35 @@ impl From<DeployArguments> for Arguments {
211211
}
212212
}
213213

214+
fn init_logging() {
215+
use std::io;
216+
use std::io::IsTerminal;
217+
use tracing_log::LogTracer;
218+
use tracing_subscriber::filter::{EnvFilter, LevelFilter};
219+
use tracing_subscriber::fmt::Layer;
220+
use tracing_subscriber::fmt::time::Uptime;
221+
use tracing_subscriber::prelude::*;
222+
223+
let fmt_layer = Layer::new()
224+
.with_writer(io::stderr)
225+
.with_ansi(io::stderr().is_terminal())
226+
.with_timer(Uptime::default())
227+
.with_filter(
228+
EnvFilter::builder()
229+
.with_default_directive(LevelFilter::WARN.into())
230+
.with_env_var("SNCAST_LOG")
231+
.from_env_lossy(),
232+
);
233+
234+
LogTracer::init().expect("could not initialize log tracer");
235+
236+
tracing::subscriber::set_global_default(tracing_subscriber::registry().with(fmt_layer))
237+
.expect("could not set up global logger");
238+
}
239+
214240
fn main() -> Result<()> {
241+
init_logging();
242+
215243
let cli = Cli::parse();
216244

217245
let output_format = output_format_from_json_flag(cli.json);

docs/src/SUMMARY.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@
5959
* [Verifying Contracts](starknet/verify.md)
6060
* [Calldata Transformation](starknet/calldata-transformation.md)
6161
* [Block Explorers](starknet/block_explorer.md)
62+
* [Developer Functionalites](starknet/developer.md)
6263

6364
---
6465

docs/src/starknet/developer.md

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
# Developer Functionalities
2+
3+
## Logging
4+
5+
`sncast` supports emitting logs, including the logs from the requests sent to the network.
6+
Logs can be enabled by setting `SNCAST_LOG` environment variable to desired log level.
7+
8+
For example, to enable logs with level `debug` and higher, run:
9+
10+
```shell
11+
$ SNCAST_LOG="debug" sncast ...
12+
```
13+
14+
Additional filtering can be set to the `SNCAST_LOG` environment variable,
15+
see [tracing-subscriber](https://docs.rs/tracing-subscriber/0.3.20/tracing_subscriber/filter/struct.EnvFilter.html#directives)
16+
documentation for more details.
17+
18+
> ⚠️ **Warning**
19+
>
20+
> Logs can expose sensitive information, such as private keys. Never use logging in production environments.

0 commit comments

Comments
 (0)