Skip to content

Commit bcd3376

Browse files
committed
Add logger
1 parent 495919b commit bcd3376

File tree

4 files changed

+44
-37
lines changed

4 files changed

+44
-37
lines changed

Cargo.lock

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

fortanix-vme/fortanix-vme-runner/Cargo.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,10 @@ edition = "2018"
55
authors = ["Fortanix, Inc."]
66

77
[dependencies]
8+
env_logger = "0.8.4"
89
fnv = "1.0.7"
910
fortanix-vme-abi = { path = "../fortanix-vme-abi", features = ["std"] }
11+
log = "0.4.14"
1012
nix = "0.22.1"
1113
serde = { version = "1.0", features = ["derive"] }
1214
serde_cbor = { version = "0.11" }

fortanix-vme/fortanix-vme-runner/src/lib.rs

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
#![deny(warnings)]
22
use fnv::FnvHashMap;
33
use nix::sys::select::{select, FdSet};
4+
use log::{error, info, warn};
45
use serde_cbor::{self, StreamDeserializer};
56
use serde_cbor::de::IoRead;
67
use std::cmp;
@@ -214,7 +215,7 @@ impl<'de> ClientConnection<'de> {
214215
Direction::Left => format!("<{:-^width$}", prot, width = 10),
215216
Direction::Right => format!("{:-^width$}>", prot, width = 10),
216217
};
217-
println!("{:>20} {} {:<20}: {:?}", src, arrow, dst, msg);
218+
info!("{:>20} {} {:<20}: {:?}", src, arrow, dst, msg);
218219
}
219220

220221
pub fn send(&mut self, response: &Response) -> Result<(), IoError> {
@@ -331,7 +332,7 @@ impl Server {
331332
Ok(())
332333
};
333334
if let Err(e) = accept_connection() {
334-
println!("[error] Failed to accept connection from the enclave: {:?}", e);
335+
error!("Failed to accept connection from the enclave: {:?}", e);
335336
}
336337
Ok(())
337338
}
@@ -372,7 +373,7 @@ impl Server {
372373

373374
thread::Builder::new().spawn(move || {
374375
if let Err(e) = connection.proxy() {
375-
eprintln!("Connection failed: {}", e);
376+
error!("Connection failed: {}", e);
376377
}
377378
self.connections.write().unwrap().remove(&k);
378379
})
@@ -432,7 +433,7 @@ impl Server {
432433
Ok(())
433434
};
434435
if let Err(e) = connect() {
435-
println!("[error] Failed to connect to the enclave after it requested an accept: {:?}", e);
436+
error!("Failed to connect to the enclave after it requested an accept: {:?}", e);
436437
}
437438
Ok(())
438439
}
@@ -444,7 +445,7 @@ impl Server {
444445
// Close `TcpListener`
445446
drop(listener);
446447
} else {
447-
println!("[warning] Can't close the connection as it can't be located.");
448+
warn!("Can't close the connection as it can't be located.");
448449
}
449450
conn.send(&Response::Closed)?;
450451
Ok(())
@@ -519,10 +520,10 @@ impl Server {
519520
}
520521

521522
pub fn run(port: u32) -> std::io::Result<JoinHandle<()>> {
522-
println!("Starting enclave runner.");
523+
info!("Starting enclave runner.");
523524
let server = Arc::new(Self::bind(port)?);
524525
let port = server.command_listener.lock().unwrap().local_addr()?.port();
525-
println!("Listening on vsock port {}...", port);
526+
info!("Listening on vsock port {}...", port);
526527

527528
server.start_command_server()
528529
}

fortanix-vme/fortanix-vme-runner/src/main.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@ use fortanix_vme_abi::SERVER_PORT;
33
use std::io::ErrorKind;
44

55
fn main() {
6+
env_logger::init();
7+
68
match Server::run(SERVER_PORT) {
79
Ok(handle) => { handle.join().unwrap(); },
810
Err(e) if e.kind() == ErrorKind::AddrInUse => println!("Server failed. Do you already have a runner running on vsock port {}? (Error: {:?})", SERVER_PORT, e),

0 commit comments

Comments
 (0)