Skip to content

Commit 6e9da1a

Browse files
committed
Add logging to the push attestation prototype
This adds `log` and `pretty_env_logger` as dependencies for the push attestation prototype. This allows setting the log level through the `RUST_LOG` environment variable. For example, setting `RUST_LOG=debug` will make the debug messages to be logged. Signed-off-by: Anderson Toshiyuki Sasaki <[email protected]>
1 parent cb8070e commit 6e9da1a

File tree

3 files changed

+18
-15
lines changed

3 files changed

+18
-15
lines changed

Cargo.lock

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

keylime-push-model-agent/Cargo.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,9 @@ actix-web.workspace = true
1212
assert_cmd.workspace = true
1313
clap.workspace = true
1414
keylime.workspace = true
15+
log.workspace = true
1516
predicates.workspace = true
17+
pretty_env_logger.workspace = true
1618
reqwest.workspace = true
1719
serde.workspace = true
1820
serde_derive.workspace = true

keylime-push-model-agent/src/main.rs

Lines changed: 14 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,8 @@
22
// Copyright 2025 Keylime Authors
33
use crate::struct_filler::StructureFiller;
44
use clap::Parser;
5-
use std::error::Error;
6-
use std::fs::File;
7-
use std::io::Read;
8-
use std::time::Duration;
5+
use log::{debug, error, info};
6+
use std::{error::Error, fs::File, io::Read, time::Duration};
97
mod struct_filler;
108

119
const DEFAULT_TIMEOUT_MILLIS: &str = "5000";
@@ -95,7 +93,7 @@ async fn send_attestation_request(
9593
let filler = get_attestation_filler_request(args);
9694
let request = filler.get_attestation_request();
9795
let serialized = serde_json::to_string(&request).unwrap();
98-
println!("Serialized Request: {}", serialized);
96+
info!("Serialized Request: {}", serialized);
9997
let reqb = get_request_builder_from_method(args)?;
10098

10199
let response = reqb
@@ -105,11 +103,11 @@ async fn send_attestation_request(
105103
.timeout(Duration::from_millis(args.timeout))
106104
.send()
107105
.await?;
108-
println!("Response code:{}", response.status());
109-
println!("Response headers: {:?}", response.headers());
106+
info!("Response code:{}", response.status());
107+
info!("Response headers: {:?}", response.headers());
110108
let response_body = response.text().await?;
111109
if !response_body.is_empty() {
112-
println!("Response body: {}", response_body);
110+
info!("Response body: {}", response_body);
113111
}
114112
Ok(response_body)
115113
}
@@ -149,21 +147,22 @@ struct Args {
149147

150148
async fn run() -> Result<(), Box<dyn std::error::Error>> {
151149
let args = Args::parse();
152-
println!("API version: {}", get_api_version(&args));
153-
println!("Verifier URL: {}", args.verifier_url);
154-
println!("Timeout: {}", args.timeout);
155-
println!("Certificate file: {}", args.certificate);
156-
println!("Insecure: {}", args.insecure.unwrap_or(false));
150+
info!("API version: {}", get_api_version(&args));
151+
info!("Verifier URL: {}", args.verifier_url);
152+
debug!("Timeout: {}", args.timeout);
153+
debug!("Certificate file: {}", args.certificate);
154+
debug!("Insecure: {}", args.insecure.unwrap_or(false));
157155
let res = send_attestation_request(&args).await;
158156
match res {
159-
Ok(_) => println!("Request sent successfully"),
160-
Err(e) => eprintln!("Error: {}", e),
157+
Ok(_) => info!("Request sent successfully"),
158+
Err(e) => error!("Error: {}", e),
161159
}
162160
Ok(())
163161
}
164162

165163
#[actix_web::main]
166164
async fn main() -> Result<(), Box<dyn std::error::Error>> {
165+
pretty_env_logger::init();
167166
run().await
168167
}
169168

0 commit comments

Comments
 (0)