diff --git a/src/risedevtool/run_command.sh b/src/risedevtool/run_command.sh index e3da246d9d8c9..029249d7638a2 100755 --- a/src/risedevtool/run_command.sh +++ b/src/risedevtool/run_command.sh @@ -5,14 +5,30 @@ echo "${@:3}" echo "logging to $1, and status to $2" -"${@:3}" 2>&1 | tee "$1" +# Strip ANSI color codes to make the log file readable. +# trap '' INT: ignore interrupts in sed +strip_ansi() { + (trap '' INT; sed -e 's/\x1b\[[0-9;]*m//g') +} +# Run the command and log the output to both the terminal and the log file. +# tee -i: ignore interrupts in tee +RW_LOG_FORCE_COLORFUL=1 "${@:3}" 2>&1 | tee -i >(strip_ansi > "$1") + +# Retrieve the return status. RET_STATUS="${PIPESTATUS[0]}" -echo "status ${RET_STATUS}" > "$2" +# If the status file exists, write the return status to it. +# +# The status file is used to detect early exits. Once `risedev-dev` finishes launching successfully, +# it will clean up the status file, so it's safe to ignore it then. +if [ -f "$2" ]; then + echo "status ${RET_STATUS}" > "$2" +fi +# Show the return status in both outputs. echo "$(date -u) [risedev]: Program exited with ${RET_STATUS}" >> "$1" -echo "Program exited with ${RET_STATUS}, press Ctrl+C to continue." +echo "Program exited with ${RET_STATUS}, press Ctrl+C again to close the window." while true; do read -r diff --git a/src/risedevtool/src/task.rs b/src/risedevtool/src/task.rs index 21b6f20eec5ee..94985269cb353 100644 --- a/src/risedevtool/src/task.rs +++ b/src/risedevtool/src/task.rs @@ -138,11 +138,7 @@ where if !id.is_empty() { self.pb.set_prefix(id.clone()); self.id = Some(id.clone()); - - // Remove the old status file if exists to avoid confusion. - let status_file = self.status_dir.path().join(format!("{}.status", id)); - fs_err::remove_file(&status_file).ok(); - self.status_file = Some(status_file); + self.status_file = Some(self.status_dir.path().join(format!("{}.status", id))); // Remove the old log file if exists to avoid confusion. let log_file = Path::new(&env::var("PREFIX_LOG").unwrap()) diff --git a/src/utils/runtime/src/logger.rs b/src/utils/runtime/src/logger.rs index ee4bbd88d6f87..bb191cf991030 100644 --- a/src/utils/runtime/src/logger.rs +++ b/src/utils/runtime/src/logger.rs @@ -87,7 +87,8 @@ impl LoggerSettings { Self { name: name.into(), enable_tokio_console: false, - colorful: console::colors_enabled_stderr() && console::colors_enabled(), + colorful: env_var_is_true("RW_LOG_FORCE_COLORFUL") + || (console::colors_enabled_stderr() && console::colors_enabled()), stderr: false, with_thread_name: false, targets: vec![],