-
Notifications
You must be signed in to change notification settings - Fork 343
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
gum log
is always outputted to stderr
#677
Comments
You can redirect to gum log "This is a test" -o /dev/stdout > out |
Another solution I am using in my script is using |
Amusing choice in diction haha (emphasis mine). Agreed that it'd be nice if it automatically chose the right stdout/stderr path. Both EDIT FWIW this is how I'm using #!/usr/bin/env bash
# Function to log using gum
logger() {
local level msg OPTIND log_file log_dir log_path
level=""
msg=""
log_dir="/tmp"
log_file="gum.log"
log_path="${log_dir}/${log_file}"
while getopts ":l:" opt; do
case ${opt} in
l )
level=$OPTARG
;;
\? )
echo "Invalid option: $OPTARG" 1>&2
return 1
;;
: )
echo "Invalid option: $OPTARG requires an argument" 1>&2
return 1
;;
esac
done
shift $((OPTIND -1))
msg="$1"
gum_log() {
local cmd
cmd=(gum log --time rfc1123 --structured)
case "$level" in
"")
cmd+=("$msg")
;;
"debug" | "info" | "warn" | "error" | "fatal")
cmd+=("--level" "$level" "$msg")
;;
*)
cmd+=("--level" "error" "Invalid log level: $level")
;;
esac
# "${cmd[@]}" 2>&1
"${cmd[@]}" -o /dev/stdout
}
case "${LOG:-}" in
stdout)
gum_log
;;
log)
gum_log >> "$log_path"
;;
both)
gum_log | tee -a "$log_path"
;;
"")
gum_log
;;
*)
echo "Invalid LOG option: ${LOG}. Using 'none'." >&2
;;
esac
}
LOG=both
n=42
logger -l info "The secret to life is: $n"
https://gist.github.com/pythoninthegrass/e763dfc659e2501d5b3c1a2cd1278ded |
Describe the bug
The output of
gum log
is always outputted to stderr, this can be frustrating to work with inside bash scripts as error handling is polluted with logs.Also, other bash feature don't work as expected:
gum log
cannot be manipulated with|
,>
,>>
,1>
, ...To redirect to a file, the
-o
flag is here (or we can use2>
/2>>
) but this is not flexible enough for some scripting usages.To Reproduce
Steps to reproduce the behavior:
gum log "This is a test" > out
(Log level don't change anything)out
file and the log was outputted in the TTYExpected behavior
The output of
gum log
should be manipulable with|
,>
,>>
,1>
, ...Desktop (please complete the following information):
The text was updated successfully, but these errors were encountered: