Skip to content

Instantly share code, notes, and snippets.

@masonwan
Last active June 12, 2023 18:55
Show Gist options
  • Save masonwan/7956055 to your computer and use it in GitHub Desktop.
Save masonwan/7956055 to your computer and use it in GitHub Desktop.
Print out Tomcat log file "catalina.out" with color
tail -200 catalina.out | ack-grep --flush --passthru --color --color-match=red "^.*ERROR.*" | ack-grep --flush --passthru --color --color-match=green "^.*DEBUG.*"
@ElMesa
Copy link

ElMesa commented Nov 22, 2014

Hi, thanks a lot. maybe spliting lines maskes easier to read and modify

For example i tried adding a INFO match

    tail -200 catalina.out | \
    ack-grep --flush --passthru --color --color-match=red "^.*ERROR.*" | \
    ack-grep --flush --passthru --color --color-match=green "^.*DEBUG.*" | \
    ack-grep --flush --passthru --color --color-match=blue "^.*INFO.*"

Also worth mentioning the available colors. I found about them at this stackoverflow answer made by Andy Lester and edited by 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

@ElMesa
Copy link

ElMesa commented Nov 22, 2014

If u are interested i forked the gist and included the colors info with attribution included:
https://gist.github.com/ElMesa/374c556283972e96deef

@tfga
Copy link

tfga commented Sep 3, 2021

Here are my contributions, based on @ElMesa's fork:
https://gist.github.com/tfga/26c22026d9aeb9c0df3db2b39ccfbf88

  • Refactored the code to use functions, so now the main code looks like this:

    colorize red    "ERROR"                 | \
    colorize red    "SEVERE"                | \
    colorize green  "DEBUG"                 | \
    colorize yellow "Deploying|finished"    | \
    colorize blue   "INFO"
  • You can colorize the whole line or just "the word" / regex match (e.g. ERROR, SEVERE).

  • Made it a pipe:

    catalina.sh run 2>&1 | colorizeTomcat
    tail -200 catalina.out | colorizeTomcat

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment