For real-time log monitoring with colors, consider these powerful alternatives to plain tail:
# 1. Using multitail (best for multiple logs) sudo pkg install multitail multitail -c /var/log/httpd-error.log
# 2. Using ccze (colorizes any log stream) tail -f /var/log/php_errors.log | ccze -A
For systems where you can't install additional packages:
# Colorize with grep highlighting tail -f /var/log/httpd-access.log | grep --color -E 'GET|POST|404|500'
# Using sed for basic coloring tail -f error.log | sed -e 's/error/\x1b[31m&\x1b[0m/g' -e 's/warning/\x1b[33m&\x1b[0m/g'
For serious production environments:
# Watch multiple logs with different color schemes multitail -cS apache /var/log/httpd-access.log -cS php /var/log/php_errors.log
# Persistent logging with lnav lnav /var/log/httpd/*.log
For ccze users, create ~/.cczerc:
[httpd] color info = blue color warning = yellow,bold color error = red,underline
For multitail, add to ~/.multitailrc:
# Apache scheme colorscheme:apache cs_re:green:\d+\.\d+\.\d+\.\d+ cs_re:yellow:\s4\d\d\s cs_re:red:\s5\d\d\s
When monitoring Apache and PHP error logs in FreeBSD environments, colorized output significantly improves readability and quick pattern recognition. The standard
tail -f
command lacks this capability, but we can enhance it with these approaches:Install the powerful log colorizer:
pkg install grc
Create a custom configuration file at
~/.grc/apache_logs
:regexp=====.*===== colour=blue ====== regexp=\\d{1,3}\\.\\d{1,3}\\.\\d{1,3}\\.\\d{1,3} colour=magenta ====== regexp=\$$.*\$$ colour=cyan ====== regexp=PHP (Warning|Error|Notice|Fatal error) colour=red ======
Then monitor logs with:
grc tail -f /var/log/httpd-error.log
Another excellent alternative using the log colorizer ccze:
pkg install ccze tail -f /var/log/php_errors.log | ccze -A
For professional environments, consider these powerful tools:
Option 1: MultiTail
Monitor multiple logs simultaneously with colors:
pkg install multitail multitail -cS apache /var/log/httpd-access.log -cS php_errors /var/log/php_errors.log
Option 2: lnav
The log file navigator provides syntax highlighting and SQL query capabilities:
pkg install lnav lnav /var/log/httpd-*.log
Add this to your
~/.bashrc
or~/.zshrc
:colorlog() { case $1 in apache) grc tail -f /var/log/httpd/${2:-error}.log ;; php) tail -f /var/log/php_errors.log | ccze -A ;; *) echo "Usage: colorlog [apache|php] [logtype]" ;; esac }
Now simply run:
colorlog apache access colorlog php
When monitoring high-traffic servers:
- Use
grc --buffered
to reduce flickering - Consider
ccze -m ansi
for minimal overhead - For critical servers, implement log rotation monitoring