sequencer - add more options to info,warning,... output
This commit is contained in:
69
sequencer.sh
69
sequencer.sh
@@ -319,7 +319,9 @@ USAGE_API
|
|||||||
Output [STRING] (can be multiline) to stdout according to log level.
|
Output [STRING] (can be multiline) to stdout according to log level.
|
||||||
[OPTIONS]
|
[OPTIONS]
|
||||||
-a : Append [STRING] skipping leading " [ ] " prefix
|
-a : Append [STRING] skipping leading " [ ] " prefix
|
||||||
|
-d : No leading " [ ] " prefix
|
||||||
-e : Output to stderr
|
-e : Output to stderr
|
||||||
|
-n : No newline
|
||||||
|
|
||||||
USAGE_API
|
USAGE_API
|
||||||
echo -e "${col_green} echoinfo [...]${col_off}"
|
echo -e "${col_green} echoinfo [...]${col_off}"
|
||||||
@@ -382,14 +384,18 @@ USAGE_API
|
|||||||
# Construct log messages
|
# Construct log messages
|
||||||
#
|
#
|
||||||
# [OPTIONS]
|
# [OPTIONS]
|
||||||
# -a : append text (no info and timestamp)
|
# -a : append text (placeholder for info and timestamp)
|
||||||
# Uses color from last sqr::log call without -a
|
# Uses color from last sqr::log call without -a
|
||||||
|
# -d : no info and timestamp
|
||||||
# -e : Output to stderr
|
# -e : Output to stderr
|
||||||
|
# -n : no newline
|
||||||
# -- : End of options
|
# -- : End of options
|
||||||
#
|
#
|
||||||
sqr::log () {
|
sqr::log () {
|
||||||
sqr::debugPause
|
sqr::debugPause
|
||||||
local appendText=
|
local appendText=
|
||||||
|
local direct=0 # no prefix and timestamp
|
||||||
|
local newline='\n'
|
||||||
local col_end="${col_off}"
|
local col_end="${col_off}"
|
||||||
local outp='/dev/stdout'
|
local outp='/dev/stdout'
|
||||||
|
|
||||||
@@ -397,18 +403,28 @@ USAGE_API
|
|||||||
shift
|
shift
|
||||||
local log_color="${1:-}"
|
local log_color="${1:-}"
|
||||||
shift
|
shift
|
||||||
for _ in "${@}" ; do
|
|
||||||
case "${1:-}" in
|
# Only output newline on empty args
|
||||||
--)
|
if ! (( $# )) ; then
|
||||||
shift && break ;;
|
direct=1
|
||||||
-a)
|
newline='\n'
|
||||||
appendText=1
|
fi
|
||||||
shift ;;
|
|
||||||
-e)
|
while getopts "aden" arg; do
|
||||||
outp='/dev/stderr'
|
case "${arg}" in
|
||||||
shift ;;
|
a)
|
||||||
|
appendText=1 ;;
|
||||||
|
d)
|
||||||
|
direct=1 ;;
|
||||||
|
e)
|
||||||
|
outp='/dev/stderr' ;;
|
||||||
|
n)
|
||||||
|
newline='' ;;
|
||||||
|
*)
|
||||||
|
;;
|
||||||
esac
|
esac
|
||||||
done
|
done
|
||||||
|
shift "$((OPTIND-1))"; OPTIND=1
|
||||||
|
|
||||||
[[ -z "${log_color}" ]] && col_end=""
|
[[ -z "${log_color}" ]] && col_end=""
|
||||||
|
|
||||||
@@ -417,23 +433,28 @@ USAGE_API
|
|||||||
|
|
||||||
while IFS=$'\n' read -r log_line ; do
|
while IFS=$'\n' read -r log_line ; do
|
||||||
printf '%b' "${log_color}" >${outp}
|
printf '%b' "${log_color}" >${outp}
|
||||||
if [[ -n "${LOG_TIME}" ]] ; then
|
if ! (( direct )) ; then
|
||||||
if (( appendText )) ; then
|
if [[ -n "${LOG_TIME}" ]] ; then
|
||||||
printf '%24s' "" >${outp}
|
if (( appendText )) ; then
|
||||||
else
|
printf '%24s' "" >${outp}
|
||||||
printf '%s ' "$(date -u +"%Y-%m-%d %H:%M:%S UTC")" >${outp}
|
else
|
||||||
|
printf '%s ' "$(date -u +"%Y-%m-%d %H:%M:%S UTC")" >${outp}
|
||||||
|
fi
|
||||||
fi
|
fi
|
||||||
fi
|
|
||||||
|
|
||||||
if (( ! appendText )) ; then
|
if (( ! appendText )) ; then
|
||||||
printf " %3s " "[${log_level}]" >${outp}
|
printf " %3s " "[${log_level}]" >${outp}
|
||||||
printf "%s" "${log_line}" >${outp}
|
printf "%s" "${log_line}" >${outp}
|
||||||
|
else
|
||||||
|
# +3 : "[] "
|
||||||
|
printf "%$((${#log_level} + 4))s%s" "" "${log_line}" >${outp}
|
||||||
|
fi
|
||||||
else
|
else
|
||||||
# +3 : "[] "
|
# direct output
|
||||||
printf "%$((${#log_level} + 4))s%s" "" "${log_line}" >${outp}
|
printf '%s' "${log_line}"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
printf '%b\n' "${col_end}" >${outp}
|
printf '%b'"${newline}" "${col_end}" >${outp}
|
||||||
done <<< "${@:-}"
|
done <<< "${@:-}"
|
||||||
sqr::debugContinue
|
sqr::debugContinue
|
||||||
}
|
}
|
||||||
@@ -504,7 +525,7 @@ USAGE_API
|
|||||||
esac
|
esac
|
||||||
}
|
}
|
||||||
|
|
||||||
# Echo additional line to info correctly indented
|
# Echo correctly indented additional line to info
|
||||||
readonly _sqr_indentHelp=' : '
|
readonly _sqr_indentHelp=' : '
|
||||||
readonly _sqr_indentExe=' '
|
readonly _sqr_indentExe=' '
|
||||||
readonly _sqr_indentAppendHelp=' '
|
readonly _sqr_indentAppendHelp=' '
|
||||||
|
|||||||
Reference in New Issue
Block a user