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