@@ -24,7 +24,6 @@ use tokio::{
2424 process:: Command as TokioCommand ,
2525 sync:: oneshot:: { channel, Sender } ,
2626} ;
27- use tracing:: debug;
2827
2928use crate :: signer:: ledger_signer:: speculus:: { Handle , Options } ;
3029
@@ -64,7 +63,6 @@ impl PodmanDriver {
6463 Ok ( Self )
6564 }
6665
67- /// Helper to run a synchronous std::process::Command in a non-blocking way.
6866 fn run_command ( mut command : std:: process:: Command ) -> anyhow:: Result < std:: process:: Output > {
6967 let command_str = format ! ( "{:?}" , command) ;
7068 let output = command. output ( ) . unwrap ( ) ;
@@ -77,7 +75,7 @@ impl PodmanDriver {
7775 String :: from_utf8_lossy( & output. stderr)
7876 ) ;
7977 }
80- debug ! (
78+ logging :: log :: debug!(
8179 "Successfully ran podman command: {}\n STDOUT: {}" ,
8280 command_str,
8381 String :: from_utf8_lossy( & output. stdout)
@@ -96,7 +94,7 @@ impl Driver for PodmanDriver {
9694 let name = format ! ( "speculos-{}" , opts. http_port) ;
9795
9896 // Ensure any previous container with the same name is removed.
99- debug ! ( "Force removing existing container '{}'" , & name) ;
97+ logging :: log :: debug!( "Force removing existing container '{}'" , & name) ;
10098 let mut cleanup_cmd = std:: process:: Command :: new ( "podman" ) ;
10199 cleanup_cmd. args ( [ "rm" , "-f" , & name] ) ;
102100 // We don't care if this fails (e.g., if the container didn't exist).
@@ -117,12 +115,11 @@ impl Driver for PodmanDriver {
117115 let mut speculos_cmd_args = opts. args ( ) ;
118116 speculos_cmd_args. push ( format ! ( "/app/{}" , app_file_name) ) ;
119117
120- debug ! ( "Container command: {}" , speculos_cmd_args. join( " " ) ) ;
118+ logging :: log :: debug!( "Container command: {}" , speculos_cmd_args. join( " " ) ) ;
121119
122120 // Build the `podman run` command.
123121 let mut command = std:: process:: Command :: new ( "podman" ) ;
124122 command. arg ( "run" ) ;
125- // command.args(["--detach", "--name", &name]);
126123 command. arg ( "--detach" ) ;
127124 command. arg ( "--name" ) ;
128125 command. arg ( & name) ;
@@ -138,25 +135,24 @@ impl Driver for PodmanDriver {
138135 command. arg ( "-p" ) . arg ( format ! ( "{}:{}" , port, port) ) ;
139136 }
140137
141- // Mount the app's directory as a volume instead of copying the file.
142- // This is simpler and more efficient than creating a tarball.
138+ // Mount the app's directory as a volume
143139 command. arg ( "-v" ) . arg ( format ! ( "{}:/app:ro" , app_parent_dir) ) ;
144140
145141 // Set image and the command to run.
146142 command. arg ( DEFAULT_IMAGE ) ;
147143 command. args ( & speculos_cmd_args) ;
148144
149145 // Create and start the container.
150- debug ! ( "Creating and starting container '{}'" , & name) ;
146+ logging :: log :: debug!( "Creating and starting container '{}'" , & name) ;
151147 Self :: run_command ( command) ?;
152- debug ! ( "Container '{}' started" , & name) ;
148+ logging :: log :: debug!( "Container '{}' started" , & name) ;
153149
154150 let ( exit_tx, mut exit_rx) = channel ( ) ;
155151
156152 // Spawn a task to stream container logs.
157153 let container_name_clone = name. clone ( ) ;
158154 tokio:: spawn ( async move {
159- debug ! (
155+ logging :: log :: debug!(
160156 "Starting log streaming for container '{}'" ,
161157 container_name_clone
162158 ) ;
@@ -168,7 +164,7 @@ impl Driver for PodmanDriver {
168164 let mut child = match cmd. spawn ( ) {
169165 Ok ( child) => child,
170166 Err ( e) => {
171- debug ! ( "Failed to spawn podman logs: {}" , e) ;
167+ logging :: log :: debug!( "Failed to spawn podman logs: {}" , e) ;
172168 return ;
173169 }
174170 } ;
@@ -183,23 +179,23 @@ impl Driver for PodmanDriver {
183179 tokio:: select! {
184180 // Check for exit signal
185181 _ = & mut exit_rx => {
186- debug!( "Received exit signal for log streaming. Killing process." ) ;
182+ logging :: log :: debug!( "Received exit signal for log streaming. Killing process." ) ;
187183 let _ = child. kill( ) . await ;
188184 break ;
189185 } ,
190186 // Read from stdout
191187 Ok ( Some ( line) ) = stdout_reader. next_line( ) => {
192- println !( "[{}] {}" , container_name_clone, line) ;
188+ logging :: log :: debug !( "[{}] {}" , container_name_clone, line) ;
193189 } ,
194190 // Read from stderr
195191 Ok ( Some ( line) ) = stderr_reader. next_line( ) => {
196- eprintln !( "[{}] {}" , container_name_clone, line) ;
192+ logging :: log :: debug !( "[{}] {}" , container_name_clone, line) ;
197193 } ,
198194 // Break if log stream ends
199195 else => break ,
200196 }
201197 }
202- debug ! (
198+ logging :: log :: debug!(
203199 "Log streaming task for '{}' finished." ,
204200 container_name_clone
205201 ) ;
@@ -214,8 +210,7 @@ impl Driver for PodmanDriver {
214210 }
215211
216212 fn exit ( & self , handle : Self :: Handle ) -> anyhow:: Result < ( ) > {
217- debug ! ( "Stopping container {}" , handle. name) ;
218- eprintln ! ( "Stopping container {}" , handle. name) ;
213+ logging:: log:: debug!( "Stopping container {}" , handle. name) ;
219214
220215 // Signal the log streaming task to terminate.
221216 let _ = handle. exit_tx . send ( ( ) ) ;
@@ -227,12 +222,12 @@ impl Driver for PodmanDriver {
227222 let _ = Self :: run_command ( stop_cmd) ;
228223
229224 // Remove the container.
230- debug ! ( "Removing container {}" , handle. name) ;
225+ logging :: log :: debug!( "Removing container {}" , handle. name) ;
231226 let mut rm_cmd = std:: process:: Command :: new ( "podman" ) ;
232227 rm_cmd. args ( [ "rm" , "-f" , & handle. name ] ) ;
233228 Self :: run_command ( rm_cmd) ?;
234229
235- debug ! ( "Container {} removed" , handle. name) ;
230+ logging :: log :: debug!( "Container {} removed" , handle. name) ;
236231 Ok ( ( ) )
237232 }
238233}
0 commit comments