I have this extremely simple function in my script:
# Used for debug tracing.
log()
{
:
echo "log: $1"
}
The idea is to be able to customize/turn off logging at a single place. Very crude.
Now I want my script to produce absolutely no output when in release configuration. The only solution I have thought of, but extremely unDRY:
TMPFILE='/tmp/tempfilewithpossiblyuniquename'
cmd 1>"$TMPFILE" 2>"$TMPFILE"
cat "$TMPFILE" | xargs log
rm "$TMPFILE"
for every single command. How to improve on this?
EDIT: I want to collect all output to stdout
and stderr
and channel it through log()
. Then log()
can choose to disregard everything, to log to a file, to print etc.
log()
. – Vorac May 29 '18 at 16:33