1- use std:: env;
21use std:: fs:: File ;
32use std:: io:: { BufRead , BufReader } ;
43use std:: path:: Path ;
54use std:: process;
65use std:: sync:: Mutex ;
6+ use std:: { env, path} ;
77
88use crate :: utils:: execute_and_print_errors;
99
@@ -24,7 +24,7 @@ pub struct ServerInfo {
2424}
2525
2626impl ServerProcess {
27- pub ( crate ) fn start ( ) -> ServerProcess {
27+ pub ( crate ) fn start ( config : crate :: ServerBuilder ) -> ServerProcess {
2828 let bin_name = if let Ok ( ver) = env:: var ( "GEL_MAJOR_VERSION" ) {
2929 format ! ( "gel-server-{ver}" )
3030 } else {
@@ -93,7 +93,7 @@ impl ServerProcess {
9393
9494 // write log file
9595 let stdout = process. stderr . take ( ) . unwrap ( ) ;
96- std:: thread:: spawn ( move || write_log_into_file ( stdout) ) ;
96+ std:: thread:: spawn ( move || write_log_into_file ( stdout, config . log_file_path ) ) ;
9797
9898 // wait for server to start
9999 let info = wait_for_server_status ( get_status_file) . unwrap ( ) ;
@@ -251,19 +251,21 @@ fn wait_for_server_status(get_status_file: impl FnOnce() -> File) -> Result<Serv
251251}
252252
253253/// Writes a stream to a log file in a temporary directory.
254- fn write_log_into_file ( stream : impl std:: io:: Read ) {
255- let log_dir = env:: temp_dir ( ) ;
254+ fn write_log_into_file ( stream : impl std:: io:: Read , log_path : Option < path:: PathBuf > ) {
255+ let log_path = if let Some ( f) = log_path {
256+ f
257+ } else {
258+ let log_dir = env:: temp_dir ( ) ;
259+ std:: fs:: create_dir_all ( & log_dir) . unwrap ( ) ;
256260
257- let id = unique_test_run_identifier ( ) ;
261+ let mut log_path = log_dir;
262+ log_path. push ( format ! ( "gel-server-{}.log" , unique_test_run_identifier( ) ) ) ;
263+ log_path
264+ } ;
258265
259- let mut log_file = log_dir. clone ( ) ;
260- let file_name = format ! ( "gel-server-{id}.log" ) . to_string ( ) ;
261- log_file. push ( file_name) ;
266+ eprintln ! ( "Writing server logs into {:?}" , & log_path) ;
262267
263- eprintln ! ( "Writing server logs into {:?}" , & log_file) ;
264-
265- std:: fs:: create_dir_all ( & log_dir) . unwrap ( ) ;
266- let mut log_file = File :: create ( log_file) . unwrap ( ) ;
268+ let mut log_file = File :: create ( log_path) . unwrap ( ) ;
267269
268270 let mut reader = BufReader :: new ( stream) ;
269271 std:: io:: copy ( & mut reader, & mut log_file) . unwrap ( ) ;
0 commit comments