Skip to content

Commit

Permalink
Introduce run_and_log() function
Browse files Browse the repository at this point in the history
  • Loading branch information
pabera committed Dec 11, 2023
1 parent 9f6144d commit e84d8d5
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 6 deletions.
9 changes: 5 additions & 4 deletions installation/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion installation/includes/02_helpers.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down
5 changes: 5 additions & 0 deletions installation/install-jukebox.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
2 changes: 1 addition & 1 deletion installation/routines/setup_rfid_reader.sh
Original file line number Diff line number Diff line change
@@ -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() {
Expand Down

0 comments on commit e84d8d5

Please sign in to comment.