Skip to content

Instantly share code, notes, and snippets.

@Thilak-KN
Forked from tfga/colorizeTomcat
Created June 12, 2023 18:56
Show Gist options
  • Save Thilak-KN/d4e0b1fe38115aa80f81ac233b6b659f to your computer and use it in GitHub Desktop.
Save Thilak-KN/d4e0b1fe38115aa80f81ac233b6b659f to your computer and use it in GitHub Desktop.
Colorize logs
#!/usr/bin/env bash
#
# Usage:
#
# catalina.sh run 2>&1 | colorizeTomcat
# tail -200 catalina.out | colorizeTomcat
#
# Previous versions:
#
# https://gist.github.com/masonwan/7956055
# https://gist.github.com/ElMesa/374c556283972e96deef
#
colorizeLine() {
local color="$1"
local level="$2"
colorize "$color" "^.*$level.*"
}
colorize() {
local color="$1"
local level="$2"
ack-grep --flush --nopager --passthru --color --color-match="$color" "$level"
}
colorize red "ERROR" | \
colorize red "SEVERE" | \
colorize green "DEBUG" | \
colorize yellow "Deploying|finished" | \
colorize blue "INFO"
####################################################################
# Colors available
#
# From Stackoverflow: http://stackoverflow.com/a/9626444
# Thanks to Andy Lester: http://stackoverflow.com/users/8454/andy-lester
# Thanks to Mytho: http://stackoverflow.com/users/225037/mytho
####################################################################
#The recognized normal foreground color attributes (colors 0 to 7) are:
#
# black red green yellow blue magenta cyan white
#
# The corresponding bright foreground color attributes (colors 8 to 15)
# are:
#
# bright_black bright_red bright_green bright_yellow
# bright_blue bright_magenta bright_cyan bright_white
#
# The recognized normal background color attributes (colors 0 to 7) are:
#
# on_black on_red on_green on_yellow
# on_blue on_magenta on_cyan on_white
#
# The recognized bright background color attributes (colors 8 to 15) are:
#
# on_bright_black on_bright_red on_bright_green on_bright_yellow
# on_bright_blue on_bright_magenta on_bright_cyan on_bright_white
#
# For any of the above listed attributes, case is not significant
####################################################################
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment