77# to be included in add-on scripts to reduce code duplication across add-ons.
88# ==============================================================================
99
10+ # Duplicate the original STDOUT on fd 3 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 3>&1
14+
1015# ------------------------------------------------------------------------------
1116# Log a message to output.
1217#
1520# ------------------------------------------------------------------------------
1621bashio::log () {
1722 local message=$*
18- echo -e " ${message} "
23+ echo -e " ${message} " >&3
1924 return " ${__BASHIO_EXIT_OK} "
2025}
2126
@@ -27,7 +32,7 @@ bashio::log() {
2732# ------------------------------------------------------------------------------
2833bashio::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} " >&3
3136 return " ${__BASHIO_EXIT_OK} "
3237}
3338
@@ -39,7 +44,7 @@ bashio::log.red() {
3944# ------------------------------------------------------------------------------
4045bashio::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} " >&3
4348 return " ${__BASHIO_EXIT_OK} "
4449}
4550
@@ -51,7 +56,7 @@ bashio::log.green() {
5156# ------------------------------------------------------------------------------
5257bashio::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} " >&3
5560 return " ${__BASHIO_EXIT_OK} "
5661}
5762
@@ -63,7 +68,7 @@ bashio::log.yellow() {
6368# ------------------------------------------------------------------------------
6469bashio::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} " >&3
6772 return " ${__BASHIO_EXIT_OK} "
6873}
6974
@@ -75,7 +80,7 @@ bashio::log.blue() {
7580# ------------------------------------------------------------------------------
7681bashio::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} " >&3
7984 return " ${__BASHIO_EXIT_OK} "
8085}
8186
@@ -87,7 +92,7 @@ bashio::log.magenta() {
8792# ------------------------------------------------------------------------------
8893bashio::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} " >&3
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} " >&3
119124
120125 return " ${__BASHIO_EXIT_OK} "
121126}
0 commit comments