Skip to content

Instantly share code, notes, and snippets.

@cbrunnkvist
Created June 9, 2024 12:05
Show Gist options
  • Save cbrunnkvist/054f820023c017fe74f1ac8bc8abee09 to your computer and use it in GitHub Desktop.
Save cbrunnkvist/054f820023c017fe74f1ac8bc8abee09 to your computer and use it in GitHub Desktop.
Colorize any log (ANSI, sed)
#!/bin/bash
echo "Starting screens with logs tailing ..."
colors="sed --unbuffered \
-e 's/\\(.*\\[ERROR.*\\)/\\o033[1;31m\\\1\\o033[0;39m/' \
-e 's/\\(.*\\[WARN.*\\)/\\o033[1;33m\\\1\\o033[0;39m/' \
-e 's/\\(.*\\[INFO.*\\)/\\o033[1;32m\\\1\\o033[0;39m/' \
-e 's/\\(.*\\[DEBUG.*\\)/\\o033[1;34m\\\1\\o033[0;39m/' \
-e 's/\\(.*\\[TRACE.*\\)/\\o033[1;35m\\\1\\o033[0;39m/'"
screen -d -m -S some-service-console-log
screen -S some-service-console-log -p 0 -X stuff "tail -F -n5000 /opt/logs/data.log | ${colors}$(printf \\r)"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment