Skip to content

Commit 0c3b370

Browse files
committed
Use parent STDOUT for logging output
Fixes issues introduced by #169
1 parent b1ae1ce commit 0c3b370

File tree

1 file changed

+13
-8
lines changed

1 file changed

+13
-8
lines changed

lib/log.sh

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,11 @@
77
# to be included in add-on scripts to reduce code duplication across add-ons.
88
# ==============================================================================
99

10+
# Preserve the original STDOUT on a free fd so that we can log to it without
11+
# interfering with the STDOUT of subshells and child processes whose output we
12+
# want to capture for other purposes.
13+
exec {LOG_FD}>&1
14+
1015
# ------------------------------------------------------------------------------
1116
# Log a message to output.
1217
#
@@ -15,7 +20,7 @@
1520
# ------------------------------------------------------------------------------
1621
bashio::log() {
1722
local message=$*
18-
echo -e "${message}"
23+
echo -e "${message}" >&"$LOG_FD"
1924
return "${__BASHIO_EXIT_OK}"
2025
}
2126

@@ -27,7 +32,7 @@ bashio::log() {
2732
# ------------------------------------------------------------------------------
2833
bashio::log.red() {
2934
local message=$*
30-
echo -e "${__BASHIO_COLORS_RED}${message}${__BASHIO_COLORS_RESET}"
35+
echo -e "${__BASHIO_COLORS_RED}${message}${__BASHIO_COLORS_RESET}" >&"$LOG_FD"
3136
return "${__BASHIO_EXIT_OK}"
3237
}
3338

@@ -39,7 +44,7 @@ bashio::log.red() {
3944
# ------------------------------------------------------------------------------
4045
bashio::log.green() {
4146
local message=$*
42-
echo -e "${__BASHIO_COLORS_GREEN}${message}${__BASHIO_COLORS_RESET}"
47+
echo -e "${__BASHIO_COLORS_GREEN}${message}${__BASHIO_COLORS_RESET}" >&"$LOG_FD"
4348
return "${__BASHIO_EXIT_OK}"
4449
}
4550

@@ -51,7 +56,7 @@ bashio::log.green() {
5156
# ------------------------------------------------------------------------------
5257
bashio::log.yellow() {
5358
local message=$*
54-
echo -e "${__BASHIO_COLORS_YELLOW}${message}${__BASHIO_COLORS_RESET}"
59+
echo -e "${__BASHIO_COLORS_YELLOW}${message}${__BASHIO_COLORS_RESET}" >&"$LOG_FD"
5560
return "${__BASHIO_EXIT_OK}"
5661
}
5762

@@ -63,7 +68,7 @@ bashio::log.yellow() {
6368
# ------------------------------------------------------------------------------
6469
bashio::log.blue() {
6570
local message=$*
66-
echo -e "${__BASHIO_COLORS_BLUE}${message}${__BASHIO_COLORS_RESET}"
71+
echo -e "${__BASHIO_COLORS_BLUE}${message}${__BASHIO_COLORS_RESET}" >&"$LOG_FD"
6772
return "${__BASHIO_EXIT_OK}"
6873
}
6974

@@ -75,7 +80,7 @@ bashio::log.blue() {
7580
# ------------------------------------------------------------------------------
7681
bashio::log.magenta() {
7782
local message=$*
78-
echo -e "${__BASHIO_COLORS_MAGENTA}${message}${__BASHIO_COLORS_RESET}"
83+
echo -e "${__BASHIO_COLORS_MAGENTA}${message}${__BASHIO_COLORS_RESET}" >&"$LOG_FD"
7984
return "${__BASHIO_EXIT_OK}"
8085
}
8186

@@ -87,7 +92,7 @@ bashio::log.magenta() {
8792
# ------------------------------------------------------------------------------
8893
bashio::log.cyan() {
8994
local message=$*
90-
echo -e "${__BASHIO_COLORS_CYAN}${message}${__BASHIO_COLORS_RESET}"
95+
echo -e "${__BASHIO_COLORS_CYAN}${message}${__BASHIO_COLORS_RESET}" >&"$LOG_FD"
9196
return "${__BASHIO_EXIT_OK}"
9297
}
9398

@@ -115,7 +120,7 @@ function bashio::log.log() {
115120
output="${output//\{MESSAGE\}/"${message}"}"
116121
output="${output//\{LEVEL\}/"${__BASHIO_LOG_LEVELS[$level]}"}"
117122

118-
echo -e "${output}"
123+
echo -e "${output}" >&"$LOG_FD"
119124

120125
return "${__BASHIO_EXIT_OK}"
121126
}

0 commit comments

Comments
 (0)