martes, 7 de enero de 2020

How to color the output of tail / cat / stdout with awk

This works in CentOS 6, CentOS 7 and Ubuntu 16.04, 16.04, 18.04

tail -f /opt/gerrit/logs/error_log | awk '
  /INFO/ {print "\033[32m" $0 "\033[39m"}
  /WARN/ {print "\033[33m" $0 "\033[39m"}
  /ERROR/ {print "\033[91m" $0 "\033[39m"}
'

Sample output:

[2020-01-07 14:32:43,807] [ReceiveCommits-2] INFO  com.google.gerrit.server.git.receive.ReceiveCommits : deprecated topic push seen for project big-boloni [CONTEXT RECEIVE_ID="big-boloni-1578403963806-c573c2f6" ]
[2020-01-07 14:33:20,082] [sshd-SshServer[5c4516ec]-nio2-thread-5] WARN  org.apache.sshd.server.session.ServerSessionImpl : exceptionCaught(ServerSessionImpl[jira@/jira-server.localdomain:40520])[state=Opened] IOException: Connection reset by peer
[2020-01-07 14:37:29,492] [ReceiveCommits-4] INFO  com.google.gerrit.server.git.receive.ReceiveCommits : deprecated topic push seen for project big-boloni [CONTEXT RECEIVE_ID="big-boloni-1578404249491-64256376" ]
[2020-01-07 14:38:43,935] [ReceiveCommits-1] INFO  com.google.gerrit.server.git.receive.ReceiveCommits : deprecated topic push seen for project big-boloni [CONTEXT RECEIVE_ID="big-boloni-1578404323935-1992a843" ]
[2020-01-07 14:40:36,559] [HTTP-2385] ERROR com.googlesource.gerrit.plugins.its.base.workflow.ActionController : Could not process project event. No its-project associated with project big-boloni. Did you forget to configure the ITS project association in project.config?




No hay comentarios:

Publicar un comentario