diff --git a/installation/README.md b/installation/README.md index def6db23d..ab789ac07 100644 --- a/installation/README.md +++ b/installation/README.md @@ -3,10 +3,11 @@ ## Logging - Bash Script output rules ```bash -print_lc "This message will be logged to both console and logfile" -print_c "This message will only be logged to the console" -log "This message will only be logged to the logfile" -clear_c "Clears the console screen" +print_lc "This message will be logged to both console and logfile" +print_c "This message will only be logged to the console" +log "This message will only be logged to the logfile" +run_and_log "Run a command and log its output to logfile" +clear_c "Clears the console screen" ``` [Learn more about bash script outputs](https://stackoverflow.com/questions/18460186/writing-outputs-to-log-file-and-console) diff --git a/installation/includes/02_helpers.sh b/installation/includes/02_helpers.sh index 3945265f7..3d91c799c 100644 --- a/installation/includes/02_helpers.sh +++ b/installation/includes/02_helpers.sh @@ -17,7 +17,7 @@ run_with_timer() { $1; # Executes the function passed as an argument - calc_runtime_and_print time_start $(date +%s) | log + run_and_log calc_runtime_and_print time_start $(date +%s) } run_with_log_frame() { diff --git a/installation/install-jukebox.sh b/installation/install-jukebox.sh index aae698984..8090989a2 100755 --- a/installation/install-jukebox.sh +++ b/installation/install-jukebox.sh @@ -50,6 +50,11 @@ log() { echo -e "$message" } +# Function to run a command where the output will be logged to both console and logfile +run_and_log() { + "$@" | tee /dev/fd/3 +} + # Function to log to console only print_c() { local message="$1" diff --git a/installation/routines/setup_rfid_reader.sh b/installation/routines/setup_rfid_reader.sh index 61361574a..f633bcdaf 100644 --- a/installation/routines/setup_rfid_reader.sh +++ b/installation/routines/setup_rfid_reader.sh @@ -1,7 +1,7 @@ #!/usr/bin/env bash _run_setup_rfid_reader() { - python "${INSTALLATION_PATH}/src/jukebox/run_register_rfid_reader.py" | log + run_and_log python "${INSTALLATION_PATH}/src/jukebox/run_register_rfid_reader.py" } setup_rfid_reader() {