Skip to content

Instantly share code, notes, and snippets.

@uluumbch
Last active December 13, 2024 02:34
Show Gist options
  • Save uluumbch/c4241fd0bd5eb54012c14d0680d20c2a to your computer and use it in GitHub Desktop.
Save uluumbch/c4241fd0bd5eb54012c14d0680d20c2a to your computer and use it in GitHub Desktop.
print laravel.log with color highlighting on Ubuntu.

Method 1: Using ccze (Recommended)

Install ccze:

sudo apt update
sudo apt install ccze

View the log:

tail -f storage/logs/laravel.log | ccze -A

Method 2: Using grep with Color

You can use grep with the --color option to highlight specific terms:

tail -f storage/logs/laravel.log | grep --color=always -E "ERROR|INFO|DEBUG|NOTICE|$"

Method 3: Using awk for Custom Highlighting

Create a custom highlighting script:

tail -f storage/logs/laravel.log | awk '
/ERROR/ {print "\033[31m" $0 "\033[0m"}
/INFO/  {print "\033[32m" $0 "\033[0m"}
/DEBUG/ {print "\033[34m" $0 "\033[0m"}
/NOTICE/ {print "\033[33m" $0 "\033[0m"}
!/ERROR|INFO|DEBUG|NOTICE/ {print $0}
'

Tips:

  • Replace the log file path if it differs.
  • Customize colors using ANSI codes (31 for red, 32 for green, etc.).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment