title: Syslog - How to Show Colorized Messages?
body: <p>I need to clarify that <strong>I am not looking to colorize the log output</strong>, and I am only interested in the program outputs that are written to <code>syslog</code>.</p>
  
  <p>So here is the scenario, I have a <code>systemd</code> unit service that runs a script, which indicates the 256 colors in Bash.</p>
  
  <p>Here is the Service Unit File:</p>
  
  <pre><code>[Unit]
  Description=Bash Color Service
  
  [Service]
  Type=simple
  EnvironmentFile=/etc/environment
  ExecStart=/home/username/colors.sh
  
  StandardOutput=syslog
  StandardError=syslog
  SyslogIdentifier=bashcolors
  
  Restart=on-failure
  RestartSec=10
  
  User=username
  Group=username
  
  [Install]
  WantedBy=multi-user.target
  </code></pre>
  
  <p>And this is the Bash script under <code>/home/username/colors.sh</code> (grabbed it from <a href="https://misc.flogisoft.com/bash/tip_colors_and_formatting" rel="noreferrer">here</a>):</p>
  
  <pre><code>#!/bin/bash
  
  # This program is free software. It comes without any warranty, to
  # the extent permitted by applicable law. You can redistribute it
  # and/or modify it under the terms of the Do What The Fuck You Want
  # To Public License, Version 2, as published by Sam Hocevar. See
  # http://sam.zoy.org/wtfpl/COPYING for more details.
  
  for fgbg in 38 48 ; do # Foreground / Background
      for color in {0..255} ; do # Colors
          # Display the color
          printf "\e[${fgbg};5;%sm  %3s  \e[0m" $color $color
          # Display 6 colors per lines
          if [ $((($color + 1) % 6)) == 4 ] ; then
              echo # New line
          fi
      done
      echo # New line
  done
  
  exit 0
  </code></pre>
  
  <p>Running this script gives out some colored output to my terminal, like this:</p>
  
  <p><a href="https://i.stack.imgur.com/Hzf9e.png" rel="noreferrer"><img src="https://i.stack.imgur.com/Hzf9e.png" alt="enter image description here"></a></p>
  
  <p>Alright, now to the actual problem. When I run the service, the syslog output <em>does include the escape color characters</em>, but are not displayed in color. Here is a snippet output of <code>tail -f /var/log/syslog</code> with relevant information:</p>
  
  <pre><code>bashcolor[19892]: #033[48;5;202m  202  #033[0m#033[48;5;203m  203  #033[0m#033[48;5;204m  204  #033[0m#033[48;5;205m  205  #033[0m#033[48;5;206m  206  #033[0m#033[48;5;207m  207  #033[0m
  bashcolor[19892]: #033[48;5;208m  208  #033[0m#033[48;5;209m  209  #033[0m#033[48;5;210m  210  #033[0m#033[48;5;211m  211  #033[0m#033[48;5;212m  212  #033[0m#033[48;5;213m  213  #033[0m
  bashcolor[19892]: #033[48;5;214m  214  #033[0m#033[48;5;215m  215  #033[0m#033[48;5;216m  216  #033[0m#033[48;5;217m  217  #033[0m#033[48;5;218m  218  #033[0m#033[48;5;219m  219  #033[0m
  bashcolor[19892]: #033[48;5;220m  220  #033[0m#033[48;5;221m  221  #033[0m#033[48;5;222m  222  #033[0m#033[48;5;223m  223  #033[0m#033[48;5;224m  224  #033[0m#033[48;5;225m  225  #033[0m
  bashcolor[19892]: #033[48;5;226m  226  #033[0m#033[48;5;227m  227  #033[0m#033[48;5;228m  228  #033[0m#033[48;5;229m  229  #033[0m#033[48;5;230m  230  #033[0m#033[48;5;231m  231  #033[0m
  bashcolor[19892]: #033[48;5;232m  232  #033[0m#033[48;5;233m  233  #033[0m#033[48;5;234m  234  #033[0m#033[48;5;235m  235  #033[0m#033[48;5;236m  236  #033[0m#033[48;5;237m  237  #033[0m
  bashcolor[19892]: #033[48;5;238m  238  #033[0m#033[48;5;239m  239  #033[0m#033[48;5;240m  240  #033[0m#033[48;5;241m  241  #033[0m#033[48;5;242m  242  #033[0m#033[48;5;243m  243  #033[0m
  bashcolor[19892]: #033[48;5;244m  244  #033[0m#033[48;5;245m  245  #033[0m#033[48;5;246m  246  #033[0m#033[48;5;247m  247  #033[0m#033[48;5;248m  248  #033[0m#033[48;5;249m  249  #033[0m
  bashcolor[19892]: #033[48;5;250m  250  #033[0m#033[48;5;251m  251  #033[0m#033[48;5;252m  252  #033[0m#033[48;5;253m  253  #033[0m#033[48;5;254m  254  #033[0m#033[48;5;255m  255  #033[0m
  </code></pre>
  
  <p><strong>Things I Have Tried So Far</strong>:</p>
  
  <ul>
  <li>using the <a href="https://linux.die.net/man/1/ccze" rel="noreferrer">ccze</a> utility: <code>tail -f /var/log/syslog | ccze -A</code></li>
  <li><code>echo -ne $(tail -f /var/log/syslog)</code></li>
  <li>using <a href="https://vanheusden.com/multitail/" rel="noreferrer"><code>multitail</code></a>, <a href="https://github.com/garabik/grc" rel="noreferrer"><code>grc</code></a> and <code>rainbow</code> utilities instead of <code>tail</code></li>
  </ul>