Skip to content

Commit d902c52

Browse files
chore: Fix log filters and refactor code to use log macros (#426)
* Fix the log layer in normal mode * switch to info messages * Update tests * taplo config * verbose output to stderr too * fix cli docs script * tweaks * snapshot upload should be info * Revert "snapshot upload should be info" This reverts commit e43af4f.
1 parent ed62012 commit d902c52

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

67 files changed

+492
-608
lines changed

Cargo.lock

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

Cargo.toml

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,6 @@ candid = "0.10.19"
3232
candid_parser = "0.3.0"
3333
clap = { version = "4.5.3", features = ["derive", "env"] }
3434
clap-markdown = "0.1.5"
35-
console = "0.16.0"
3635
cryptoki = "0.12.0"
3736
dialoguer = "0.12.0"
3837
directories = "6.0.0"
@@ -61,12 +60,7 @@ indoc = "2.0.6"
6160
itertools = "0.14.0"
6261
jsonschema = "0.45.0"
6362
k256 = { version = "0.13.4", features = ["pem", "pkcs8", "std"] }
64-
keyring = { version = "3.6.3", features = [
65-
"apple-native",
66-
"windows-native",
67-
"sync-secret-service",
68-
"crypto-rust",
69-
] }
63+
keyring = { version = "3.6.3", features = ["apple-native", "windows-native", "sync-secret-service", "crypto-rust"] }
7064
lazy_static = "1.5.0"
7165
mockall = "0.14.0"
7266
nix = { version = "0.31.2", features = ["process", "signal"] }
@@ -82,11 +76,7 @@ phf = { version = "0.13.1", features = ["macros"] }
8276
pkcs8 = { version = "0.10.2", features = ["encryption", "std"] }
8377
rand = "0.10.0"
8478
regex = "1.12.2"
85-
reqwest = { version = "0.13.2", default-features = false, features = [
86-
"rustls",
87-
"json",
88-
"stream",
89-
] }
79+
reqwest = { version = "0.13.2", default-features = false, features = ["rustls", "json", "stream"] }
9080
schemars = { version = "1.0.4", features = ["derive", "url2"] }
9181
scrypt = "0.11.0"
9282
sec1 = { version = "0.7.3", features = ["pkcs8"] }

crates/icp-cli/Cargo.toml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@ candid.workspace = true
2424
cargo-generate.workspace = true
2525
clap-markdown.workspace = true
2626
clap.workspace = true
27-
console.workspace = true
2827
dialoguer.workspace = true
2928
dunce.workspace = true
3029
elliptic-curve.workspace = true

crates/icp-cli/src/commands/build.rs

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
use std::sync::Arc;
2-
31
use clap::Args;
42
use futures::future::try_join_all;
53
use icp::context::{Context, EnvironmentSelection};
64

5+
use tracing::info;
6+
77
use crate::{operations::build::build_many_with_progress_bar, options::EnvironmentOpt};
88

99
/// Build canisters
@@ -44,19 +44,18 @@ pub(crate) async fn exec(ctx: &Context, args: &BuildArgs) -> Result<(), anyhow::
4444
)
4545
.await?;
4646
// Build the selected canisters
47-
let _ = ctx.term.write_line("Building canisters:");
47+
info!("Building canisters:");
4848

4949
build_many_with_progress_bar(
5050
canisters_to_build,
5151
ctx.builder.clone(),
5252
ctx.artifacts.clone(),
5353
&ctx.dirs.package_cache()?,
54-
Arc::new(ctx.term.clone()),
5554
ctx.debug,
5655
)
5756
.await?;
5857

59-
let _ = ctx.term.write_line("\nCanisters built successfully");
58+
info!("Canisters built successfully");
6059

6160
Ok(())
6261
}

crates/icp-cli/src/commands/canister/create.rs

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ use icp::context::Context;
55
use icp::parsers::{CyclesAmount, DurationAmount, MemoryAmount};
66
use icp::{Canister, context::CanisterSelection, prelude::*};
77
use icp_canister_interfaces::management_canister::CanisterSettingsArg;
8+
use tracing::info;
89

910
use crate::{commands::args, operations::create::CreateOperation};
1011

@@ -191,11 +192,9 @@ async fn create_canister(ctx: &Context, args: &CreateArgs) -> Result<(), anyhow:
191192
let id = create_operation.create(&canister_settings).await?;
192193

193194
if args.quiet {
194-
let _ = ctx.term.write_line(&format!("{id}"));
195+
println!("{id}");
195196
} else {
196-
let _ = ctx
197-
.term
198-
.write_line(&format!("Created canister with ID {id}"));
197+
println!("Created canister with ID {id}");
199198
}
200199

201200
Ok(())
@@ -224,9 +223,7 @@ async fn create_project_canister(ctx: &Context, args: &CreateArgs) -> Result<(),
224223
.await
225224
.is_ok()
226225
{
227-
let _ = ctx
228-
.term
229-
.write_line(&format!("Canister {canister} already exists"));
226+
info!("Canister {canister} already exists");
230227
return Ok(());
231228
}
232229

@@ -251,11 +248,9 @@ async fn create_project_canister(ctx: &Context, args: &CreateArgs) -> Result<(),
251248
ctx.update_custom_domains(&selections.environment).await;
252249

253250
if args.quiet {
254-
let _ = ctx.term.write_line(&format!("{id}"));
251+
println!("{id}");
255252
} else {
256-
let _ = ctx
257-
.term
258-
.write_line(&format!("Created canister {canister} with ID {id}"));
253+
println!("Created canister {canister} with ID {id}");
259254
}
260255

261256
Ok(())

crates/icp-cli/src/commands/canister/install.rs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ use icp::context::{CanisterSelection, Context};
88
use icp::manifest::InitArgsFormat;
99
use icp::prelude::*;
1010
use icp::{InitArgs, fs};
11+
use tracing::{info, warn};
1112

1213
use crate::{
1314
commands::args,
@@ -138,7 +139,7 @@ pub(crate) async fn exec(ctx: &Context, args: &InstallArgs) -> Result<(), anyhow
138139
);
139140

140141
if std::io::stdin().is_terminal() {
141-
let _ = ctx.term.write_line(&warning);
142+
warn!("{warning}");
142143
let confirmed = Confirm::new()
143144
.with_prompt("Do you want to proceed anyway?")
144145
.default(false)
@@ -164,9 +165,7 @@ pub(crate) async fn exec(ctx: &Context, args: &InstallArgs) -> Result<(), anyhow
164165
)
165166
.await?;
166167

167-
let _ = ctx.term.write_line(&format!(
168-
"Canister {canister_display} installed successfully"
169-
));
168+
info!("Canister {canister_display} installed successfully");
170169

171170
Ok(())
172171
}

crates/icp-cli/src/commands/canister/list.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ pub(crate) async fn exec(ctx: &Context, args: &ListArgs) -> Result<(), anyhow::E
1515
let env = ctx.get_environment(&environment_selection).await?;
1616

1717
for c in env.canisters.keys() {
18-
ctx.term.write_line(c)?;
18+
println!("{c}");
1919
}
2020

2121
Ok(())

crates/icp-cli/src/commands/canister/logs.rs

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -99,10 +99,10 @@ pub(crate) async fn exec(ctx: &Context, args: &LogsArgs) -> Result<(), anyhow::E
9999

100100
if args.follow {
101101
// Follow mode: continuously fetch and display new logs
102-
follow_logs(ctx, &mgmt, &canister_id, args.interval).await
102+
follow_logs(&mgmt, &canister_id, args.interval).await
103103
} else {
104104
// Single fetch mode: fetch all logs once
105-
fetch_and_display_logs(ctx, &mgmt, &canister_id, build_filter(args)?).await
105+
fetch_and_display_logs(&mgmt, &canister_id, build_filter(args)?).await
106106
}
107107
}
108108

@@ -141,7 +141,6 @@ fn build_filter(args: &LogsArgs) -> Result<Option<CanisterLogFilter>, anyhow::Er
141141
}
142142

143143
async fn fetch_and_display_logs(
144-
ctx: &Context,
145144
mgmt: &ManagementCanister<'_>,
146145
canister_id: &candid::Principal,
147146
filter: Option<CanisterLogFilter>,
@@ -157,7 +156,7 @@ async fn fetch_and_display_logs(
157156

158157
for log in result.canister_log_records {
159158
let formatted = format_log(&log);
160-
let _ = ctx.term.write_line(&formatted);
159+
println!("{formatted}");
161160
}
162161

163162
Ok(())
@@ -166,7 +165,6 @@ async fn fetch_and_display_logs(
166165
const FOLLOW_LOOKBACK_NANOS: u64 = 60 * 60 * 1_000_000_000; // 1 hour
167166

168167
async fn follow_logs(
169-
ctx: &Context,
170168
mgmt: &ManagementCanister<'_>,
171169
canister_id: &candid::Principal,
172170
interval_seconds: u64,
@@ -207,7 +205,7 @@ async fn follow_logs(
207205
if !new_logs.is_empty() {
208206
for log in &new_logs {
209207
let formatted = format_log(log);
210-
let _ = ctx.term.write_line(&formatted);
208+
println!("{formatted}");
211209
}
212210
// Update last_idx to the highest idx we've displayed
213211
if let Some(last_log) = new_logs.last() {

crates/icp-cli/src/commands/canister/metadata.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ pub(crate) async fn exec(ctx: &Context, args: &MetadataArgs) -> Result<(), anyho
4040

4141
match metadata {
4242
Some(value) => {
43-
ctx.term.write_line(&value)?;
43+
println!("{value}");
4444
Ok(())
4545
}
4646
None => bail!(

crates/icp-cli/src/commands/canister/migrate_id.rs

Lines changed: 23 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ use icp::context::Context;
1010
use icp_canister_interfaces::nns_migration::{MigrationStatus, NNS_MIGRATION_PRINCIPAL};
1111
use indicatif::{ProgressBar, ProgressStyle};
1212
use num_traits::ToPrimitive;
13+
use tracing::{info, warn};
1314

1415
use crate::commands::args::{self, Canister};
1516
use crate::operations::canister_migration::{
@@ -87,12 +88,12 @@ pub(crate) async fn exec(ctx: &Context, args: &MigrateIdArgs) -> Result<(), anyh
8788
if !args.resume_watch {
8889
let can_confirm = stdin().is_terminal();
8990
if !args.yes && can_confirm {
90-
ctx.term.write_line(&format!(
91+
info!(
9192
"This will migrate canister '{source_name}' ({source_cid}) to replace '{target_name}' ({target_cid})."
92-
))?;
93-
ctx.term.write_line(
94-
"The target canister will be deleted and the source canister will take over its ID.",
95-
)?;
93+
);
94+
info!(
95+
"The target canister will be deleted and the source canister will take over its ID."
96+
);
9697

9798
let confirmed = Confirm::new()
9899
.with_prompt("Do you want to proceed?")
@@ -136,11 +137,8 @@ pub(crate) async fn exec(ctx: &Context, args: &MigrateIdArgs) -> Result<(), anyh
136137

137138
if !args.yes && cycles > WARN_CYCLES_THRESHOLD {
138139
if can_confirm {
139-
ctx.term.write_line(&format!(
140-
"Warning: Canister '{source_name}' has more than 15T cycles ({cycles} cycles)."
141-
))?;
142-
ctx.term
143-
.write_line("The extra cycles will get burned during the migration.")?;
140+
warn!("Canister '{source_name}' has more than 15T cycles ({cycles} cycles).");
141+
warn!("The extra cycles will get burned during the migration.");
144142

145143
let confirmed = Confirm::new()
146144
.with_prompt("Do you want to proceed?")
@@ -178,20 +176,16 @@ pub(crate) async fn exec(ctx: &Context, args: &MigrateIdArgs) -> Result<(), anyh
178176
);
179177
}
180178

181-
ctx.term.write_line(&format!(
179+
info!(
182180
"Migrating canister '{source_name}' ({source_cid}) to replace '{target_name}' ({target_cid})"
183-
))?;
184-
ctx.term
185-
.write_line(&format!(" Source subnet: {source_subnet}"))?;
186-
ctx.term
187-
.write_line(&format!(" Target subnet: {target_subnet}"))?;
181+
);
182+
info!(" Source subnet: {source_subnet}");
183+
info!(" Target subnet: {target_subnet}");
188184

189185
// Add NNS migration canister as controller to both canisters if not already
190186
let source_controllers = source_status.settings.controllers;
191187
if !source_controllers.contains(&NNS_MIGRATION_PRINCIPAL) {
192-
ctx.term.write_line(&format!(
193-
"Adding NNS migration canister as controller of '{source_name}'..."
194-
))?;
188+
info!("Adding NNS migration canister as controller of '{source_name}'...");
195189
let mut new_controllers = source_controllers;
196190
new_controllers.push(NNS_MIGRATION_PRINCIPAL);
197191
let mut builder = mgmt.update_settings(&source_cid);
@@ -203,9 +197,7 @@ pub(crate) async fn exec(ctx: &Context, args: &MigrateIdArgs) -> Result<(), anyh
203197

204198
let target_controllers = target_status.settings.controllers;
205199
if !target_controllers.contains(&NNS_MIGRATION_PRINCIPAL) {
206-
ctx.term.write_line(&format!(
207-
"Adding NNS migration canister as controller of '{target_name}'..."
208-
))?;
200+
info!("Adding NNS migration canister as controller of '{target_name}'...");
209201
let mut new_controllers = target_controllers;
210202
new_controllers.push(NNS_MIGRATION_PRINCIPAL);
211203
let mut builder = mgmt.update_settings(&target_cid);
@@ -216,12 +208,12 @@ pub(crate) async fn exec(ctx: &Context, args: &MigrateIdArgs) -> Result<(), anyh
216208
}
217209

218210
// Initiate migration
219-
ctx.term.write_line("Initiating canister ID migration...")?;
211+
info!("Initiating canister ID migration...");
220212
migrate_canister(&agent, source_cid, target_cid).await?;
221213
} else {
222-
ctx.term.write_line(&format!(
214+
info!(
223215
"Resuming watch for migration of '{source_name}' ({source_cid}) to '{target_name}' ({target_cid})"
224-
))?;
216+
);
225217
}
226218

227219
// Create spinner for polling
@@ -246,12 +238,12 @@ pub(crate) async fn exec(ctx: &Context, args: &MigrateIdArgs) -> Result<(), anyh
246238
spinner.finish_with_message(format!(
247239
"Migration in progress: {status} (exiting early due to --skip-watch)"
248240
));
249-
ctx.term.write_line(&format!(
241+
info!(
250242
"The source canister '{source_name}' has been deleted. Migration will continue in the background."
251-
))?;
252-
ctx.term.write_line(&format!(
243+
);
244+
info!(
253245
"Use `icp canister migrate-id {source_name} --replace {target_name} --resume-watch` to monitor completion."
254-
))?;
246+
);
255247
return Ok(());
256248
}
257249
}
@@ -286,9 +278,9 @@ pub(crate) async fn exec(ctx: &Context, args: &MigrateIdArgs) -> Result<(), anyh
286278
}
287279
}
288280

289-
ctx.term.write_line(&format!(
281+
info!(
290282
"Canister '{source_name}' ({source_cid}) has been successfully migrated to the new subnet, replacing {target_cid}"
291-
))?;
283+
);
292284

293285
Ok(())
294286
}

0 commit comments

Comments
 (0)