title: Is there a way to redirect all stdout and stderr to systemd journal from within script?
body: <p>I like the idea of using systemd's journal to view and manage the logs of my own scripts.  I have become aware you can log to journal from my user scripts on a per message basis..</p>
  
  <pre><code>echo 'hello' | systemd-cat -t myscript -p emerg
  </code></pre>
  
  <p>Is there a way to redirect all messages to journald, even those generated by other commands?  Like..</p>
  
  <pre><code>exec &amp;&gt; systemd-cat
  </code></pre>
  
  <p><strong>Update:</strong></p>
  
  <p>Some partial success.
  Tried <a href="https://stackoverflow.com/users/5291015/inian">Inian</a>'s suggestion from terminal.</p>
  
  <pre><code>~/scripts/myscript.sh 2&gt;&amp;1 | systemd-cat -t myscript.sh
  </code></pre>
  
  <p>and it worked, stdout and stderr were directed to systemd's journal. 
   Curiously, </p>
  
  <pre><code>~/scripts/myscript.sh &amp;&gt; | systemd-cat -t myscript.sh
  </code></pre>
  
  <p>didn't work in my Bash terminal.</p>
  
  <p>I still need to find a way to do this inside my script for when other programs call my script.</p>
  
  <p>I tried..</p>
  
  <pre><code>exec 2&gt;&amp;1 | systemd-cat -t myscript.sh
  </code></pre>
  
  <p>but it doesn't work.  </p>
  
  <p><strong>Update 2</strong>:</p>
  
  <p>From terminal </p>
  
  <pre><code>systemd-cat ~/scripts/myscript.sh
  </code></pre>
  
  <p>works.  But I'm still looking for a way to do this from within the script.</p>