I have 2 log functions:
log_msg()
{
if [ ! -e $LOG_FILE ]; then
touch $LOG_FILE
chmod 0640 $LOG_FILE
fi
echo "$(date +'[%Y-%m-%d %T]') $1" >> $LOG_FILE
}
log_stream()
{
while read data; do
printf "$(date +'[%Y-%m-%d %T]') $data" >> $LOG_FILE
done
}
In order to log msg:
log_msg "Hello World!";
In order to log stdout of another function I tried to do:
bgcommand --a --b 2>&1 > log_stream &
But it's not working.
I've found the function to log pipe at this question: Pipe output to bash function But something is missing.