From a93dc7c1fa4b600aa69e3a76021e0960443511ed Mon Sep 17 00:00:00 2001 From: Valentin Lab Date: Fri, 7 Jan 2022 11:39:36 +0100 Subject: [PATCH] new: redirect standard logs towards stderr if running an action This allows direct actions to produce output that won't be messed around by the logs. Signed-off-by: Valentin Lab --- bin/compose-core | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/bin/compose-core b/bin/compose-core index 74bf402..d28e19e 100755 --- a/bin/compose-core +++ b/bin/compose-core @@ -3850,6 +3850,10 @@ fi _setup_state_dir mkdir -p "$CACHEDIR" || exit 1 + +log () { cat; } +export -f log + ## ## Argument parsing ## @@ -3887,6 +3891,8 @@ while read-0 arg; do --quiet|-q) export QUIET=true export wrap_opts+=("-q") + log () { cat >&2; } + export -f log ;; --version|-V) print_version @@ -4081,6 +4087,10 @@ if [ -z "$is_docker_compose_action" -a "$action" ]; then esac } < <(has_service_action "$action_service" "$action") services_args=("$action_service") + + ## Divert logging to stdout to stderr + log () { cat >&2; } + export -f log else die "Unknown action '${DARKCYAN}$action$NORMAL': It doesn't match any docker-compose commands nor inner charm actions." fi @@ -4185,7 +4195,7 @@ if [ -n "$full_init" ]; then run_service_hook pre_deploy "${services_args[@]}" || exit 1 -fi +fi | log if [ "$action" == "run" -a "${#services_args}" != 0 ]; then charm=$(get_service_charm "${services_args[0]}") || exit 1