linux less command and color logs
When you have a script to colour your logs from an application and its name is “colorize” you should place it in the PATH environment variable and the do the following:
Create:
$HOME/bin/lessopen.sh
#!/bin/sh
case "$1" in
*.log)
tail -n+1 -f $1 | colorize > /tmp/less.$$ &
echo $[$! - 1] > /tmp/tail_pid.$$
echo /tmp/less.$$
;;
esac
Create:
$HOME/bin/lessclose.sh
#! /bin/sh rm $2 old_pid=`echo $2 | sed 's/\/tmp\/less\.//'` kill -9 `cat /tmp/tail_pid.$old_pid` rm /tmp/tail_pid.$old_pid
Add to .bash_profile
export LESSOPEN="$HOME/bin/lessopen.sh %s" export LESSCLOSE="$HOME/bin/lessclose.sh %s %s"
And the run less, with the working “+F” option:
less -R +F /some/file/server.log